Trailing stop & order modify error 1

 

Hi i`m trying to build a trailing stop, and it's working fine but sometimes i get a nasty order modify error 1.I don't know if it's harmful i've read the documentation it is when the value is unchanged i guess,but the question is how to resolve it :D .Hew is my code:

double TRAILSTOP;
extern int STOPLOSSPIPS=124;
    TotalNumberOfOrders = OrdersTotal();
for(PositionIndex = TotalNumberOfOrders - 1; PositionIndex >= 0 ; PositionIndex --)  
{
 /////  
   
if( ! OrderSelect(PositionIndex, SELECT_BY_POS, MODE_TRADES) ) continue;   

if( OrderMagicNumber() == magic     && OrderSymbol() == Symbol()    && ( OrderType() == OP_BUY ) && (OrderProfit()>0))         
{
TRAILSTOP=(Ask-OrderOpenPrice())/Point;
if((TRAILSTOP > STOPLOSSPIPS) && ((Ask-(STOPLOSSPIPS*Point))>OrderStopLoss())){OrderModify(OrderTicket(),OrderOpenPrice(),Ask-(STOPLOSSPIPS*Point),OrderTakeProfit(),0,White); }

}


if( OrderMagicNumber() == magic     && OrderSymbol() == Symbol()    && ( OrderType() == OP_SELL ) && (OrderProfit()>0))   
{
TRAILSTOP=(OrderOpenPrice()-Bid)/Point;
if((TRAILSTOP > STOPLOSSPIPS) && ((Bid+(STOPLOSSPIPS*Point))<OrderStopLoss())){OrderModify(OrderTicket(),OrderOpenPrice(),Bid+(STOPLOSSPIPS*Point),OrderTakeProfit(),0,White); }

}
 
 ///
}
 
Proximus: i get a nasty order modify error 1. I don't know if it's harmful i've read the documentation it is when the value is unchanged i guess but the question is how to resolve it :
  1. You
    Server
    Change the SL to X
    It is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane

    Print your values and find out.
  2. (Ask-(STOPLOSSPIPS*Point))>OrderStopLoss() newSL=Ask-(STOPLOSSPIPS*Point);
    What if Ask - STOPLOSSPIPS*Point > OrderStopLoss() by less than one Point. Your modify fails because newSL-StopLoss() < Point, i.e. the same value. The == operand. - MQL4 forum
  3. On a 5 digit broker Point is NOT a pip.
  4. You open a buy at the ask, your TP/SL is relative to the bid.
 
WHRoeder:
  1. You
    Server
    Change the SL to X
    It is at X!
    Change the SL to XIt is at X!
    Change the SL to XYou are insane

    Print your values and find out.
  2. What if Ask - STOPLOSSPIPS*Point > OrderStopLoss() by less than one Point. Your modify fails because newSL-StopLoss() < Point, i.e. the same value. The == operand. - MQL4 forum
  3. On a 5 digit broker Point is NOT a pip.
  4. You open a buy at the ask, your TP/SL is relative to the bid.

3. I have a 5 digit broker,but this is surely not the problem i have all my formulas counted in fractional pips

4. Buy is opened in ask sell is opened in bid, thaks fine too

1 & 2 I suspected that it was the problem with the same value,since the code basically what it does, that it tests if a price moves in my favor and moves the stoploss in paralel with the price.If the price doesnt move then it should not move the stop loss since i have this on

if((Ask-(STOPLOSSPIPS*Point))>OrderStopLoss()) ...

Why it still modifies the order even if the price didnt changed if i stated out with an > that it should only change it if the current stop loss is bigger (in the buy case) than the previous?

And how to correct it?

Thank you!

 
Proximus:

3. I have a 5 digit broker,but this is surely not the problem i have all my formulas counted in fractional pips

4. Buy is opened in ask sell is opened in bid, thaks fine too

1 & 2 I suspected that it was the problem with the same value,since the code basically what it does, that it tests if a price moves in my favor and moves the stoploss in paralel with the price.If the price doesnt move then it should not move the stop loss since i have this on

Why it still modifies the order even if the price didnt changed if i stated out with an > that it should only change it if the current stop loss is bigger (in the buy case) than the previous?

And how to correct it?

Thank you!

Do you know Ask at start() is also Ask moment you modify ??
Simply don't modify every Point wait until the diffence is more then a Point

why not modify if it is atleast a pip difference

that way you avoid also a lot of tradecontext to busy errors...

 
Proximus:


Why it still modifies the order even if the price didnt changed if i stated out with an > that it should only change it if the current stop loss is bigger (in the buy case) than the previous?

Read the thread at the link given to you and spend some time understanding . . . then fix your code. This is a link --> --> --> The == operand. - MQL4 forum


1.54321000000001 is > 1.543210000000001 but in terms of a GBPUSD price they are equal . . .

 
RaptorUK:

Read the thread at the link given to you and spend some time understanding . . . then fix your code. This is a link --> --> --> The == operand. - MQL4 forum


1.54321000000001 is > 1.543210000000001 but in terms of a GBPUSD price they are equal . . .

I've fixed it using devries idea, now it has a full 1 pip difference between testings and seems to work fine now.

 
Proximus:

I've fixed it using devries idea, now it has a full 1 pip difference between testings and seems to work fine now.

And next time when you have a similar problem and 1 pip difference is too much what then ? read, learn, understand and you can resolve your issues rather than trying to work around them . . . they will usually come back to bite you otherwise.
 
if((TRAILSTOP > STOPLOSSPIPS) && ((Bid+(STOPLOSSPIPS*Point))<OrderStopLoss())){OrderModify(OrderTicket(),OrderOpenPrice(),Bid+(STOPLOSSPIPS*Point),OrderTakeProfit(),0,White); }

}
 
 ///
}

where is it you get errorreturn when your modify fails ???

if you keep on programming this way then it is hard to believe you understand your own code

there are more issues why it can be a modify is failing

If it happens then you like to know the reason....

 
RaptorUK:
And next time when you have a similar problem and 1 pip difference is too much what then ? read, learn, understand and you can resolve your issues rather than trying to work around them . . . they will usually come back to bite you otherwise.

Nah 1 pip is ok anyway its a trailing stop, which are used on min 5 pips step.If i use it on 1 pip its acceptable and more accurate,and also not to overload the EA,a crash is the worst thing you can get when trading.


deVries:

where is it you get errorreturn when your modify fails ???

if you keep on programming this way then it is hard to believe you understand your own code

there are more issues why it can be a modify is failing

If it happens then you like to know the reason....

If you are talking about syntax errors, there were none.It was an error 1 because the bot modified the order too quickly but now it's resolved ant thanks for help.
 
Proximus:
Nah 1 pip is ok anyway its a trailing stop, which are used on min 5 pips step.If i use it on 1 pip its acceptable and more accurate,and also not to overload the EA,a crash is the worst thing you can get when trading.

I'm not talking about the trailing stop, I'm talking about any situation where you may need to compare double values . . . do you understand what the issue is with double values ?
 
Proximus:
Nah 1 pip is ok anyway its a trailing stop, which are used on min 5 pips step.If i use it on 1 pip its acceptable and more accurate,and also not to overload the EA,a crash is the worst thing you can get when trading.


If you are talking about syntax errors, there were none.It was an error 1 because the bot modified the order too quickly but now it's resolved ant thanks for help.


i wrote there are more issues why it can be a modify is failing

might be you don't see them while you backtesting but some you will get the moment you gonna trade your EA