How do i modify TakeProfit of all current open position using OrderModify()?
How do i modify TakeProfit of all current open position using OrderModify()?
Loading saved threads...
Raphael Tunji · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Raphael Tunji
Original post: https://stackoverflow.com/questions/66390834
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have opened up to five buy trades with their individual take profit. I want to change the take profit of the first four buy trades to the take profit of number five buy trade.
modifyAllBuyOrdTP()
is the function created to modify the take profit while
findTpL_BuyOrd()
function will get the take profit of the last trade that just finished opened. It is not working in strategy tester. I will be grateful to anyone that can help me on this problem. Thank you in advance.
void modifyAllBuyOrdTP(){
if(CountTradesBuy()>=2){
for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--)
{
OrderSelect(l_pos_4, SELECT_BY_TICKET);
if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
continue;
if(OrderTakeProfit() == findTpL_BuyOrd())
continue;
if(OrderStopLoss() == 0 && OrderTakeProfit() != findTpL_BuyOrd() && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){
if(OrderType() == OP_BUY){
ModifyStopsByPrice(OrderTicket(),0,findTpL_BuyOrd());//Print(" b tp ",findTpL_BuyOrd());
}
}
}
}
}
double findTpL_BuyOrd(){
double l_ord_TP = 0;
for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--)
{
OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber)
continue;
if(OrderTakeProfit() == 0)
continue;
if(OrderTakeProfit()!=0 && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){
if(OrderType() == OP_BUY){
l_ord_TP = OrderTakeProfit();
break;
}
}
}
return l_ord_TP;
}
Quote
Report
tomgny · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: tomgny
Original post: https://stackoverflow.com/a/66399148
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
In
modifyAllBuyOrdTP()
function you should select orders by
SELECT_BY_POS
if you iterating over them.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: Raphael Tunji Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/66390834 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I have opened up to five buy trades with their individual take profit. I want to change the take profit of the first four buy trades to the take profit of number five buy trade. modifyAllBuyOrdTP() is the function created to modify the take profit while findTpL_BuyOrd() function will get the take profit of the last trade that just finished opened. It is not working in strategy tester. I will be grateful to anyone that can help me on this problem. Thank you in advance. void modifyAllBuyOrdTP(){ if(CountTradesBuy()>=2){ for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_TICKET); if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if(OrderTakeProfit() == findTpL_BuyOrd()) continue; if(OrderStopLoss() == 0 && OrderTakeProfit() != findTpL_BuyOrd() && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){ if(OrderType() == OP_BUY){ ModifyStopsByPrice(OrderTicket(),0,findTpL_BuyOrd());//Print(" b tp ",findTpL_BuyOrd()); } } } } } double findTpL_BuyOrd(){ double l_ord_TP = 0; for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if(OrderTakeProfit() == 0) continue; if(OrderTakeProfit()!=0 && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber){ if(OrderType() == OP_BUY){ l_ord_TP = OrderTakeProfit(); break; } } } return l_ord_TP; }
Checking account access…