Need help with my CandleTrail EA

 

Hi,

I try to use a CandleTrail function on a simple MAcross system and it works but I have many [Invalid stops] errors and I don't know why.

Can someone help me fix this problem? 

Files:
 
YANND:

Hi,

I try to use a CandleTrail function on a simple MAcross system and it works but I have many [Invalid stops] errors and I don't know why.

Can someone help me fix this problem? 

What is the Stoplevel for the symbol you are trading ?
 
angevoyageur:
What is the Stoplevel for the symbol you are trading ?

I don't know.

 If I use 

Comment(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL));

It shows me "0" in the EURUSD chart

 

I already tried to add the StopLevel to the StopLoss but I didn't solve the problem. Or maybe I use the StopLevel wrong?

 
YANND:

I don't know.

 If I use 

It shows me "0" in the EURUSD chart. 

 

I already tried to add the StopLevel to the StopLoss but I didn't solve the problem. Or maybe I use the StopLevel wrong?

The problem is when you are trying to modify your SL/TP (trailing function), modify your code as follow:

void candletrail(double CBack, double PAmount)
      {
      MqlTradeRequest request={0};
      ...

Anyway, you have to check your SL, as it can gives Invalid Stops if it is to close to market price.

 
angevoyageur:

Anyway, you have to check your SL, as it can gives Invalid Stops if it is to close to market price.

Now I changed the code a little.

I call the CandleTrail function only once per bar and use the PositionModify from the standard library.

I have much less errors but there are still [Invalid stops] errors. 

It seems that my SL verify code doesn't work.

I use

double min=SymbolInfoDouble(_Symbol,SYMBOL_BID)-_Point*SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
if(CandleTrailPrice > currentSL && CandleTrailPrice < min)
  {
   Trade.PositionModify(_Symbol,CandleTrailPrice,TP);
  }

and

 

double max=SymbolInfoDouble(_Symbol,SYMBOL_ASK)+_Point*SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
if(CandleTrailPrice < currentSL && CandleTrailPrice > max)
   {
    Trade.PositionModify(_Symbol,CandleTrailPrice,TP);
   }

 What am I doing wrong?

Documentation on MQL5: Standard Library
Documentation on MQL5: Standard Library
  • www.mql5.com
Standard Library - Documentation on MQL5
Files:
 
YANND:

Now I changed the code a little.

I call the CandleTrail function only once per bar and use the PositionModify from the standard library.

I have much less errors but there are still [Invalid stops] errors. 

It seems that my SL verify code doesn't work.

I use

and

 

 What am I doing wrong?

Which error do you get ? You have to use GetLastError() when Trade.PositionModify() return false.
 
angevoyageur:
Which error do you get ? You have to use GetLastError() when Trade.PositionModify() return false.
The Error is 4756  ERR_TRADE_SEND_FAILED and sometimes I have Error 4753  ERR_TRADE_POSITION_NOT_FOUND
Files:
 
YANND:
The Error is 4756  ERR_TRADE_SEND_FAILED and sometimes I have Error 4753  ERR_TRADE_POSITION_NOT_FOUND

I think you have error 4756 because you are trying to modify a position without changing anything (see this discussion about price).

Try this :

     if(CandleTrailPrice-currentSL>_Point/2. && CandleTrailPrice<min)
     ...

instead of that :

     if(CandleTrailPrice > currentSL && CandleTrailPrice < min)
     ...

EDIT: Your error checking isn't good, you have to use Trade.ResultRetcode and not result.retcode. Also your syntax is wrong :

            Trade.PositionModify(_Symbol,CandleTrailPrice,TP);
            if (Trade.ResultRetcode() != TRADE_RETCODE_DONE && Trade.ResultRetcode() != TRADE_RETCODE_PLACED)
               {
               Print("trade error = ", Trade.ResultRetcode(), " last error: ",GetLastError());
               }
 
angevoyageur:

I think you have error 4756 because you are trying to modify a position without changing anything (see this discussion about price).

Try this :

instead of that :

The error 4753 is a little weird, I will see if I can reproduce it.

Oh yes. I understand.  "except with zero never compare doubles for equality"  :)

Thanks a lot. The error 4756 is disappeared.

 
YANND:

Oh yes. I understand.  "except with zero never compare doubles for equality"  :)

Thanks a lot. The error 4756 is disappeared.

See above about error 4753.
 
Alain Verleyen:
See above about error 4753.

Hi, I started to have the same error after upgrading version of MT5. Please what is not compatible in my code anymore? This error is a plague!

Reason: