/*[[ 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),MarginCutoff(0),risk(3),LiveTrading(0); defines: MM(0),Leverage(1),AccountIsMini(0); 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); var: Opentrades(0); // Check for invalid bars and takeprofit If Bars<200 then Exit; ////////////////////////////////////////////////// ///////////// Manage multiple trades / ////////////////////////////////////////////////// Opentrades=0; For cnt=1 to TotalTrades Begin If OrderValue(cnt,Val_Symbol)==Symbol then { Opentrades=Opentrades+1; }; End; ///////////////////////////////////////////////// // 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 0 then { lotMM = Ceil(Balance * risk / 10000) / 10; if lotMM < 0.1 then lotMM = Lots; if lotMM > 1.0 then lotMM = Ceil(lotMM); // Enforce lot size boundaries if LiveTrading == 1 then { if AccountIsMini == 1 then lotMM = lotMM * 10; if AccountIsMini == 0 and lotMM < 1.0 then lotMM = 1.0; } if lotMM > 100 then lotMM = 100; } else { lotMM = Lots; // Change mm to 0 if you want the Lots parameter to be in effect }; // Calculate indicators' value adx1_1 = iADXEx(14,PRICE_CLOSE,MODE_MAIN,1); adx1sd_0 = iADXEx(14,PRICE_CLOSE,MODE_MINUSDI,0); adx1pd_0 = iADXEx(14,PRICE_CLOSE,MODE_PLUSDI,0); adx1sd_1 = iADXEx(14,PRICE_CLOSE,MODE_MINUSDI,1); adx1_0 = iADXEx(14,PRICE_CLOSE,MODE_MAIN,0); adx1pd_1 = iADXEx(14,PRICE_CLOSE,MODE_PLUSDI,1); ma3_1 = iMAEx(10,MODE_LWMA,0,PRICE_CLOSE,1); ma3_0 = iMAEx(10,MODE_LWMA,0,PRICE_CLOSE,0); ma4_1 = iMAEx(15,MODE_LWMA,0,PRICE_CLOSE,1); ma4_0 = iMAEx(15,MODE_LWMA,0,PRICE_CLOSE,0); ma2_1 = iMAEx(5,MODE_LWMA,0,PRICE_CLOSE,1); ma2_0 = iMAEx(5,MODE_LWMA,0,PRICE_CLOSE,0); // 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 = False; // 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 Opentrades==0 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"); }; };