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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);
}
}