vaknineyal: I am openning 2 orders on the same direction, but when I modify them I can modify only one.
if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true)
You are only selecting the oldest open order. How do you expect it to ever modify any other? What if there is an open order on another chart? Then you don't modify any.
Do a OrderSelect loop so you modify ALL your open orders
So far I tried this and its work I don't know if that the smart way to do that
int TPCalc() { bool ModifyBuy1; bool ModifyBuy2; bool ModifySell1; bool ModifySell2; for (int i=1; i<=OrdersTotal(); i++) { if (OrderSelect(i-1,SELECT_BY_POS)== true) { if(OrderSymbol() != Symbol()) continue; if(OrderSymbol() == Symbol() && OrderType() == OP_BUY) { Risk = OrderOpenPrice() - OrderStopLoss(); TakeProfit1 = OrderOpenPrice() + Risk; TakeProfit2 = OrderOpenPrice() + (Risk*RiskFactor); if(OrderMagicNumber() == 111) { ModifyBuy1 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit1,0,CLR_NONE); } else if (OrderMagicNumber() == 222) { ModifyBuy2 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit2,0,CLR_NONE); } } if (OrderSymbol() == Symbol() && OrderType() == OP_SELL) { Risk = OrderStopLoss() - OrderOpenPrice(); TakeProfit1 = OrderOpenPrice() - Risk; TakeProfit2 = OrderOpenPrice() - (Risk*RiskFactor); if(OrderMagicNumber() == 111) { ModifySell1 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit1,0,CLR_NONE); } else if (OrderMagicNumber() == 222) { ModifySell2 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit2,0,CLR_NONE); } } } // if (OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == true) // { // if (OrderSymbol() == Symbol()) // { // if (OrderType() == OP_BUY) // { // Risk = OrderOpenPrice() - OrderStopLoss(); // TakeProfit1 = OrderOpenPrice() + Risk; // TakeProfit2 = OrderOpenPrice() + (Risk*RiskFactor); // if (OrderComment() == "Buy1") // { // ModifyBuy1 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit1,0,CLR_NONE); // } // if (OrderComment() == "Buy2") // { // ModifyBuy2 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit2,0,CLR_NONE); // } // } // if (OrderType() == OP_SELL) // { // Risk = OrderStopLoss() - OrderOpenPrice(); // TakeProfit1 = OrderOpenPrice() - Risk; // TakeProfit2 = OrderOpenPrice() - (Risk*RiskFactor); // if (OrderMagicNumber() == 111) // { // ModifySell1 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit1,0,CLR_NONE); // } // if (OrderMagicNumber() == 222) // { // ModifySell2 = OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),TakeProfit2,0,CLR_NONE); // } // } // } } return(0); }

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
Hi All
I have problem to modify Take Profit and I need help;
I am openning 2 orders on the same direction, but when I modify them I can modify only one.
I open 2 Orders in the same price calculate the stoploss and then calculate take profit, one order TP should 1:1 RR and the second 1:2 RR.
I can modify one one order to 1:1 and the second dosent work, I tried to change them by OrderMagicNumber() or by OrderComment() both of them doesn't work for me.
any help will be wellcome.
here is the code: