#property copyright "Copyright © 2008, AKA TradeForexFX" #property link "http://www./" extern string Expert_Name = "---- Function Tester EA by TF ----"; extern int MagicNumber = 0; //extern double Lots = 1.00; extern bool StopLossMode = true; extern int StopLoss = 300; extern int TakeProfit = 150; int init() { return(0); } int deinit() { return(0); } int start() { if (StopLossMode && StopLoss > 0) DoStopLoss(); return(0); } void DoStopLoss() { int Total; double QtyOrders = 0.00; double QtyOrderSells = 0.00; Total = OrdersTotal(); bool IsTrade = False; // Better to do this from highest to lowest // for (int i = 0; i < Total; i ++) { for (int i = Total - 1; i >= 0; i --) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //******************************************* // Important to have code check MagicNumber and Symbol if (OrderSymbol() != Symbol()) continue; if (OrderMagicNumber() != MagicNumber) continue; //******************************************* if(OrderType() > OP_SELL) continue; IsTrade = True; if(OrderType() == OP_BUY) { QtyOrders = OrderLots(); //MoveOnce if(StopLoss > 0) // any valid condition { if(QtyOrders > 0) // any valid condition { if(OrderStopLoss() == 0 ) // any valid condition { OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() - Point * StopLoss, OrderOpenPrice() + Point * TakeProfit, 0, Red); // if(!EachTickMode) BarCount = Bars; continue; } } } } else { QtyOrderSells = OrderLots(); //MoveOnce if(StopLoss > 0) //any valid condition { if(QtyOrders > 0 ) //any valid condition { if(OrderStopLoss() == 0 ) //any valid condition { OrderModify(OrderTicket(),OrderOpenPrice(), OrderOpenPrice() + Point * StopLoss, OrderOpenPrice() - Point * TakeProfit, 0, Red); // if(!EachTickMode) BarCount = Bars; continue; } } } } } } // OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()- StopLoss*Point,OrderOpenPrice()+TakeProfit*Point,0,Green);