extern int StopLoss = 18; extern int TakeProfit = 25; extern int ZeroStopLossProfit = 13; //ýòî óðîâåíü ïåðåâîäà ïîçèöèè â áåçóáûòîê +1 ïèïñ extern bool MakeSound = true; double MaxDeltaPrice; string SymbolString; bool Error; /*=================================================================================================*/ void init () { Error = false; SymbolString = Symbol(); if ( (StopLoss < 13) || (TakeProfit < 13) || (ZeroStopLossProfit < 13) ) { Comment ("Error: inputs cannot be less than 13. Change."); Error = true; return; } else Comment ("The Expert is loaded and waiting data."); } /*=================================================================================================*/ void start () { int i; double OpenPrice; double CurrentPrice; double DeltaPrice; double StopLossPrice; double TakeProfitPrice; int OrderDir; int OrderCounter; if (Error == true) return; Comment (SymbolString,": The Expert is working..."); OrderCounter = OrdersTotal(); if (OrderCounter==0) return; for (i=0; i<OrderCounter; i++) { OrderSelect (i,SELECT_BY_POS); OpenPrice = OrderOpenPrice(); OrderDir = OrderType(); if (OrderSymbol() != Symbol()) continue; if (OrderStopLoss() != 0.0) { if ( (OrderDir == OP_SELL) && (OrderOpenPrice() > OrderStopLoss()) ) continue; if ( (OrderDir == OP_BUY) && (OrderOpenPrice() < OrderStopLoss()) ) continue; if (OrderProfit() <= 0.0) continue; CurrentPrice = OrderClosePrice(); DeltaPrice = MathAbs(CurrentPrice-OpenPrice); if ((DeltaPrice/Point) < ZeroStopLossProfit) { if (DeltaPrice > MaxDeltaPrice) { if (OrderDir == OP_SELL) StopLossPrice = CurrentPrice + (StopLoss*Point); if (OrderDir == OP_BUY) StopLossPrice = CurrentPrice - (StopLoss*Point); OrderModify (OrderTicket(),OrderOpenPrice(),StopLossPrice,OrderTakeProfit(),0,CLR_NONE); if (MakeSound == true) PlaySound ("tick.wav"); } MaxDeltaPrice = MathMax(MaxDeltaPrice,DeltaPrice); continue; } if (OrderDir == OP_SELL) StopLossPrice = OpenPrice - Point; if (OrderDir == OP_BUY) StopLossPrice = OpenPrice + Point; OrderModify (OrderTicket(),OrderOpenPrice(),StopLossPrice,OrderTakeProfit(),0,CLR_NONE); if (MakeSound == true) PlaySound ("tick.wav"); continue; } if (OrderDir == OP_SELL) { StopLossPrice = OpenPrice + (StopLoss * Point); TakeProfitPrice = OpenPrice - TakeProfit*Point; } if (OrderDir == OP_BUY) { StopLossPrice = OpenPrice - (StopLoss * Point); TakeProfitPrice = OpenPrice + TakeProfit*Point; } OrderModify (OrderTicket(),OrderOpenPrice(),StopLossPrice,TakeProfitPrice,0,CLR_NONE); if (MakeSound == true) PlaySound ("tick.wav"); } } /*=================================================================================================*/
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
Other Features: