/*[[ Name := WMA ADX Cross Author := Matt Heldreth aka Pip_hunter Notes := Use on H4 chart. Lots := 1 Stop Loss := 35 Take Profit := 999 Trailing Stop := 60 ]]*/ defines: Slippage(3); defines: MM(0),Leverage(1); var: cnt(0),IsBuying(False),IsSelling(False),IsClosing(False),RealTP(0),RealSL(0); var: adx1_1(0),adx1sd_0(0),adx1pd_0(0),adx1sd_1(0),adx1_0(0),adx1pd_1(0),ma3_1(0),ma3_0(0),ma4_1(0),ma4_0(0),ma2_1(0),ma2_0(0); var: LotMM(0),LotMax(50); // Check for invalid bars and takeprofit If Bars<200 then Exit; // From which month test on history. Define : MyYear(2005),MyMonth(1); If MyYear>0 And MyYear>Year Then Exit; If MyYear>0 And Year==MyYear And Month LotMax then LotMM = LotMax; }; If MM = 0 then LotMM = lots; if MM > 0 then { LotMM = Round(Balance*Leverage/10000)/10; If LotMM > 1 then LotMM = ceil(LotMM); if LotMM < 1 then LotMM = 1; If LotMM > LotMax then LotMM = LotMax; }; // Check for BUY, SELL, and CLOSE signal IsBuying = (ma2_0 > ma3_0) and (ma3_0 > ma4_0) and (adx1pd_0 > 20) and (ma2_0 > ma4_0); IsSelling = (ma4_0 > ma2_0) and (ma3_0 > ma2_0) and (ma4_0 > ma3_0) and (adx1sd_0 > 20); IsClosing = (adx1sd_0 < 20) or (adx1pd_0 < 20); // Control open trades for cnt=1 to TotalTrades { // Control only market trades not entry order if OrderValue(cnt,VAL_TYPE)<=OP_SELL and OrderValue(cnt,VAL_SYMBOL)=Symbol then { // Check for close signal for bought trade If OrderValue(cnt,VAL_TYPE)=OP_BUY then { If IsSelling or IsClosing then { // Close bought trade CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,3,Violet); Alert("WMA ADX Cross: Closing BUY order."); }; // Check trailing stop If TrailingStop>0 then { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then { // Modify trailing stop ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); }; }; }; } else { // Check sold trade for close signal If IsBuying or IsClosing then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Alert("WMA ADX Cross: Closing SELL order."); }; // Control trailing stop If TrailingStop>0 then { If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(Point*TrailingStop) then { If OrderValue(cnt,VAL_STOPLOSS)=0 or OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); }; }; }; }; }; }; // If there is no open trade If TotalTrades<1 then { // If we have enough money for 1 lot If FreeMargin<1000 then Exit; // Check for BUY entry signal If IsBuying and IsSelling=False and IsClosing=False then { // Buy If StopLoss>0 then { RealSL=Ask-StopLoss*Point; } If TakeProfit>0 then { RealTP=Ask+TakeProfit*Point; } SetOrder(OP_BUY,Lots,Ask, Slippage,RealSL,RealTP,RED); Alert("WMA ADX Cross: Buying"); }; // Check for SELL entry signal If IsSelling and IsBuying=False and IsClosing=False then { // Sell If StopLoss>0 then { RealSL=Bid+StopLoss*Point; } If TakeProfit>0 then { RealTP=Bid-TakeProfit*Point; } SetOrder(OP_SELL,Lots,Bid,Slippage,RealSL,RealTP,RED); Alert("WMA ADX Cross: Selling"); }; };