Download MetaTrader 5
To add comments, please log in or register
Have you found a good programmer? Make a targeted order!
Yannick Deubel
13118
Yannick Deubel 2013.10.03 18:30 

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:
Alain Verleyen
Moderator
30299
Alain Verleyen 2013.10.03 19:19  
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 ?
Yannick Deubel
13118
Yannick Deubel 2013.10.03 19:30  
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?

Alain Verleyen
Moderator
30299
Alain Verleyen 2013.10.03 19:44  
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.

Yannick Deubel
13118
Yannick Deubel 2013.10.03 20:50  
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:
Alain Verleyen
Moderator
30299
Alain Verleyen 2013.10.03 22:08  
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.
Yannick Deubel
13118
Yannick Deubel 2013.10.03 22:43  
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:
Alain Verleyen
Moderator
30299
Alain Verleyen 2013.10.03 23:23  
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());
               }
Yannick Deubel
13118
Yannick Deubel 2013.10.04 00:00  
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.

Alain Verleyen
Moderator
30299
Alain Verleyen 2013.10.04 00:10  
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.
/
To add comments, please log in or register