Order Modify Error 1

 

Hi, I’m writing this code, but I obtain the message “OrderModify Error 1” because the system continue to see as valid the condition “Bid > TakeProfit_Long_1”.

I need to modify the orders only one time, when Bid price cross TakeProfit_Long_1.

How can I proceed? Thank you!

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);

{

if(OrderSymbol()==Symbol() )

{

if(OrderType()==OP_BUY && Bid > TakeProfit_Long_1 )

{

OrderModify(OrderTicket(),OrderOpenPrice(),New_Stop_Long,OrderTakeProfit(),0,Blue);

return(0);

}

if(OrderType()==OP_SELL && Ask < TakeProfit_Short_1 )

{

OrderModify(OrderTicket(),OrderOpenPrice(),New_Stop_Short,OrderTakeProfit(),0,Blue);

return(0);

}

}

}

}

 

try change

if(OrderType()==OP_BUY && Bid > TakeProfit_Long_1 )

to

if(OrderType()==OP_BUY && Bid > TakeProfit_Long_1 && OrderTakeProfit() != TakeProfit_Long_1)

 
Solved! Thank you.
 
phy:

try change

if(OrderType()==OP_BUY && Bid > TakeProfit_Long_1 )

to

if(OrderType()==OP_BUY && Bid > TakeProfit_Long_1 && OrderTakeProfit() != TakeProfit_Long_1)

Hello, i wrote an EA based on QQE indicator and Parabolic SAR, I have the problem i got Order modify error 1, really I cannot understand why. I printed all the value needed on the journal, but this doesn't help. The EA seems to trail the stop loss correctly with SAR when the conditions are met (here I look to the results).

N.B. I use in the EA The Signal ENTRY (QQE), it is not synchronized with Parabolic's trend direction. My wish is to place a first StopLoss attached to the entry order, then if if the parabolic is trendind at the same direction of the last order and if the parabolic sar is shorter than the stoploss THEN modify order stoploss with parabolic.

If Parabolic reverse before my exit signal, I would like to the stoploss remains constant.


Could you have look on this ? Thanks for helping

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

double RsiMaCurrent,TrLevelSlowCurrent,RsiMaPrevious, TrLevelSlowPrevious,StopParabolic;

RsiMaCurrent=iCustom(NULL,0,"QQE",SF,0,1);
TrLevelSlowCurrent=iCustom(NULL,0,"QQE",SF,1,1);
RsiMaPrevious=iCustom(NULL,0,"QQE",SF,0,2);
TrLevelSlowPrevious=iCustom(NULL,0,"QQE",SF,1,2);
StopParabolic = iCustom(NULL,0,"Parabolic Sub",StepPararabolic,MaxParabolic,0,0);


////////////////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////////////

for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if ((RsiMaCurrent < TrLevelSlowCurrent)&&(RsiMaPrevious > TrLevelSlowPrevious))
{
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
return(0); // exit
}
// Set Parabolic Stop, If Price > StopParabolic, The signal could be erlier than an parabolic signal,
// Already set StopLoss < StopParabolic then modify order, the StopLoss can never go in wrong direction
if ((Bid > StopParabolic) && (OrderStopLoss() < StopParabolic))
{

OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
Print("(LONG) MODIFY STOP to Valeur Parabolic ", StopParabolic," Bid ",Bid);
return(0);

}

}
}
else // go to short position
{
// should it be closed?
if ((RsiMaCurrent > TrLevelSlowCurrent)&&(RsiMaPrevious < TrLevelSlowPrevious))
{
Print("CLOSE Current Signal 1 : ",RsiMaCurrent," Signal 2 : ",TrLevelSlowCurrent," Previous Signal 1 : ",RsiMaPrevious," Signal 2 : ",TrLevelSlowPrevious);
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
return(0); // exit
}
//Parabolic same as long side
if ((Ask < StopParabolic) && (OrderStopLoss() > StopParabolic))
{
OrderModify(OrderTicket(),OrderOpenPrice(),StopParabolic,OrderTakeProfit(),0,Green);
Print("(SHORT) MODIFY STOP to Valeur Parabolic ", StopParabolic," Ask ",Ask );
return(0);
}
}

}

return(0);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////





Files:
Reason: