You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.
if(OrderClosePrice()-OrderOpenPrice()>=(OrderTakeProfit()-OrderOpenPrice())/2)
is much simpler. Above is for a Buy order obviously
You should also check if the SL has already been modified
You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.
is much simpler. Above is for a Buy order obviously
You should also check if the SL has already been modified
ok ive modified my original code
//+-------------------------------------------------------------------+
void OnBreakEven()
{
for(int iTickets=OrdersTotal()-1; iTickets>=0; iTickets--)
{
if(!OrderSelect(iTickets,SELECT_BY_POS,MODE_TRADES)){continue;}
if(OrderType()>OP_SELL||OrderSymbol()!=sSymbol||OrderMagicNumber()!=iMagic()){continue;}
// sells
if(OrderType()==OP_SELL && OrderOpenPrice()-OrderClosePrice() >=
(OrderOpenPrice()-OrderTakeProfit())*dBreakEvenPercent &&
OrderStopLoss()!=OrderOpenPrice())
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
{return;}
}
//buys
if(OrderType()==OP_BUY && OrderClosePrice()-OrderOpenPrice() >=
(OrderTakeProfit()-OrderOpenPrice())*dBreakEvenPercent &&
OrderStopLoss()!=OrderOpenPrice())
{
if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE))
{return;}
}
}
}
seems im still getting the OrderModify Error 1 and it seems to begin even before any orders are present
again it does work.. it seems like it does it and other times not
You seem to be assuming that 1 pip is worth 10 $, not sure because I can't work out what you are trying to do.
is much simpler. Above is for a Buy order obviously
You should also check if the SL has already been modified
okay now perhaps ive done it -- thx!
void OnBreakEven() { for(int iTickets=OrdersTotal()-1; iTickets>=0; iTickets--) { if(!OrderSelect(iTickets,SELECT_BY_POS,MODE_TRADES)){continue;} if(OrderType()>OP_SELL||OrderSymbol()!=sSymbol||OrderMagicNumber()!=iMagic()){continue;} // sells if(OrderType()==OP_SELL && OrderStopLoss()!=OrderOpenPrice()) if(OrderOpenPrice()-OrderClosePrice() >= (OrderOpenPrice()-OrderTakeProfit())*dBreakEvenPercent) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE)) {return;} } //buys if(OrderType()==OP_BUY && OrderStopLoss()!=OrderOpenPrice()) if(OrderClosePrice()-OrderOpenPrice() >= (OrderTakeProfit()-OrderOpenPrice())*dBreakEvenPercent) { if(OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,CLR_NONE)) {return;} } } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Okay, i'am just using profit amounts to place a stop if order profit is greater than or equal to half of the expected profit
in tester the resulting journal entry says OrderModify error 1. what is wrong just using orderopenprice for stoploss?
though it seems to be working it does get errors (picture updated)