I changed a "Set SL to break even " with BE plus 2x Spread.
Is this code correct?
- #property copyright ""
#include <WinUser32.mqh>
#include <stdlib.mqh>
//+------------------------------------------------------------------+
int start()
//+------------------------------------------------------------------+
{
//----
bool result;
int err;
string symbol = Symbol();
double spread = Ask - Bid;
Alert("--- START "+WindowExpertName()+" "+Symbol());
int ot = OrdersTotal();
for (int i=0; i<ot; i++)
{
int o = OrderSelect(i, SELECT_BY_POS);
if (OrderSymbol() == symbol)
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
double sl = 0;
if ((OrderType() == OP_BUY) && (OrderStopLoss() < OrderOpenPrice()))
sl = OrderOpenPrice() + (2*spread) + MarketInfo(Symbol() , MODE_SPREAD)*Point;
if ((OrderType() == OP_SELL) && (OrderStopLoss() > OrderOpenPrice()))
sl = OrderOpenPrice() - (2*spread) - MarketInfo(Symbol() , MODE_SPREAD)*Point;
if (sl != 0)
Alert(WindowExpertName()+":moving SL to "+sl);
result=OrderModify(OrderTicket(), OrderOpenPrice(), sl, OrderTakeProfit(), 0);
if(result!=TRUE) {
err = GetLastError();
Alert(WindowExpertName()+":error when OrderModify()",err," : ",ErrorDescription(err));
break;
}
}
}
//----
Alert("--- END "+WindowExpertName()+" "+Symbol());
return(0);
}
//+------------------------------------------------------------------+