Moving Stop to Breakeven works in backtest but not Live

 

Can someone tell me what I am doing wrong? This part of the code works in backtesting but does not work properly in live testing.

TH

total = OrdersTotal();

for(int i = 0 ; i<total ; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

ticket = OrderTicket();

//----BreakEven Code

if (OrderType()==OP_BUY && OrderSymbol()==Symbol())

{

CurrentProfit = Bid - OrderOpenPrice();

if (CurrentProfit>=BreakEven*Point && OrderMagicNumber()!=Profit1)

OrderModify(ticket,Bid,OrderOpenPrice(),OrderTakeProfit(),0,Red);

}

//-----

if (OrderType()==OP_SELL && OrderSymbol()==Symbol())

{

CurrentProfit = OrderOpenPrice() - Ask;

if (CurrentProfit>=BreakEven*Point && OrderMagicNumber()!=Profit1 )

OrderModify(ticket,Ask,OrderOpenPrice(),OrderTakeProfit(),0,Green);

// if (OrderLots()==1 && CurrentProfit>=30*Point)

// OrderModify(ticket,Ask,Ask+StopLoss*Point,Ask-TakeProfit*Point,3,Green);

}

}

 

Hi,

I think the code of BreakEven must be :

void BreakEven()

{

//----

int total = OrdersTotal();

for(int i = 0 ; i<total ; i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

int ticket = OrderTicket();

//----BreakEven Code

if (OrderMagicNumber()==Magic && OrderSymbol()==Symbol())

{

if (OrderType()==OP_BUY)

{

double CurrentProfit = Bid - OrderOpenPrice();

if (CurrentProfit>=BreakEven*Point)

OrderModify(ticket,Bid,OrderOpenPrice(),OrderTakeProfit(),0,Red);

return(0);

}

//-----

if (OrderType()==OP_SELL)

{

CurrentProfit = OrderOpenPrice() - Ask;

if (CurrentProfit>=BreakEven*Point)

OrderModify(ticket,Ask,OrderOpenPrice(),OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

Also you can use my advanced "Stepped" BreakEven.

Igor