#property strict input bool IsCloseCounter = false; input double Lots = 1; input string Commentary = "MA Crossovr"; input int Magic = 11111; input double TpPercent = 1.0; input double SlPercent =0.5; input double TslTriggerPercent = 0.5; input double TslPercent =0.2; double MaxAccountBalance = AccountBalance(); double MinAccountBalance = 1000000; double InitialAccountBalance = AccountBalance(); int barsTotal; int OnInit(){ barsTotal = iBars(_Symbol,PERIOD_CURRENT); return(INIT_SUCCEEDED); } void OnDeinit(const int reason){ } void OnTick(){ double maFast1 = iMA(_Symbol,PERIOD_CURRENT,20,0,MODE_SMA,PRICE_CLOSE,1); double maFast2 = iMA(_Symbol,PERIOD_CURRENT,20,0,MODE_SMA,PRICE_CLOSE,2); double maSlow1 = iMA(_Symbol,PERIOD_CURRENT,50,0,MODE_SMA,PRICE_CLOSE,1); double maSlow2 = iMA(_Symbol,PERIOD_CURRENT,50,0,MODE_SMA,PRICE_CLOSE,2); for(int i = OrdersTotal()-1; i>= 0; i--){ if(OrderSelect(i,SELECT_BY_POS && OrderSymbol() == _Symbol && OrderMagicNumber() == Magic)){ if (OrderType()== OP_BUY){ if (IsCloseCounter && maFast1 < maSlow1){ if (OrderClose(OrderTicket(),OrderLots(),Bid, 100000)){ Print ("Buy Order Closed"); continue; } } if (Bid > OrderOpenPrice() + OrderOpenPrice() * TslTriggerPercent / 100){ double sl = Bid - Bid * TslPercent /100; sl = NormalizeDouble(sl,_Digits); if(sl> OrderStopLoss()){ if(OrderModify(OrderTicket(), OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration())){ Print ("Order Modified"); } } } } if (OrderType()== OP_SELL){ if (IsCloseCounter && maFast1 > maSlow1){ if (OrderClose(OrderTicket(),OrderLots(),Ask, 100000)){ Print ("Sell Order Closed"); continue; } } if (Ask < OrderOpenPrice() - OrderOpenPrice() * TslTriggerPercent / 100){ double sl = Ask + Ask * TslPercent /100; sl = NormalizeDouble(sl,_Digits); if(sl< OrderStopLoss() || OrderStopLoss() == 0){ if(OrderModify(OrderTicket(), OrderOpenPrice(),sl,OrderTakeProfit(),OrderExpiration())){ Print ("Order Modified"); } } } } } } int bars = iBars(_Symbol,PERIOD_CURRENT); if(barsTotal != bars){ barsTotal = bars; if(maFast1 > maSlow1 && maFast2 < maSlow2){ Print ("Buy Signal!!!!!"); executeBuy(); } if(maFast1 < maSlow1 && maFast2 > maSlow2){ Print ("Sell Signal!!!!!"); executeSell(); }} double CurrentAccountBalance = AccountBalance(); if (MaxAccountBalance < AccountBalance()) MaxAccountBalance = AccountBalance(); if (MinAccountBalance > AccountBalance()) MinAccountBalance = AccountBalance(); Comment ("Initial Account Balance was ",InitialAccountBalance,", Minimum Balance was ",MinAccountBalance,", Max Balance was ", MaxAccountBalance,", Current Balance is ",CurrentAccountBalance," and Current Equity is ",AccountEquity(), ""); } int executeBuy(){ double entry = Ask; entry = NormalizeDouble(entry, _Digits); double sl = entry - entry * SlPercent / 100; sl = NormalizeDouble(sl, _Digits); double tp = entry + entry * TpPercent / 100; tp = NormalizeDouble(tp, _Digits); return OrderSend(_Symbol,OP_BUY,Lots,entry,100000,sl,tp,Commentary,Magic,0,clrBlue); } int executeSell(){ double entry = Bid; entry = NormalizeDouble(entry, _Digits); double sl = entry + entry * SlPercent / 100; sl = NormalizeDouble(sl, _Digits); double tp = entry - entry * TpPercent / 100; tp = NormalizeDouble(tp, _Digits); return OrderSend(_Symbol,OP_SELL,Lots,entry,100000,sl,tp,Commentary,Magic,0,clrRed); }