Modify take profit of all current buy trades is not working in strategy tester
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; }
My question
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.
Hello,
should be to change little bit the code.
old code...
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()); } } } } }
to new one....
void modifyAllBuyOrdTP() { if(CountTradesBuy()>=2) { for(int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) { if(OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) { 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()); } } } } } }
Hello,
should be to change little bit the code.
old code...
to new one....
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; }
My question
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.