Download MetaTrader 5

Stoploss : numbers, double, digits ...

To add comments, please log in or register
Icham Aidibe
10306
Icham Aidibe  

I'm trying to set a SL, here's the formula used : 

            request.sl=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID) - (SLFactor * SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL) * _Point),SymbolInfoInteger(Symbol(),SYMBOL_DIGITS));
            printf("SL requested : %G", request.sl); <---- debug line
[...]
               //--- printing the server response to the log  
               Print(CheckResult.retcode,"  -error ");
               Print(request.sl);
               Print(__FUNCTION__,":",CheckResult.comment);

Where SL Factor is a double (1.5). But here's what I get in the journal log :

2014.04.23 05:35:27.254 2014.04.17 16:15:00   SL requested : 9399.8 <- request.sl
2014.04.23 05:35:27.254 2014.04.17 16:15:00   10016  -error 
2014.04.23 05:35:27.254 2014.04.17 16:15:00   9399.799999999999 <- the "same" request.sl
2014.04.23 05:35:27.254 2014.04.17 16:15:00   Invalid stops

Did i miss something ?

Alain Verleyen
Moderator
32808
Alain Verleyen  
blouf:

I'm trying to set a SL, here's the formula used : 

Where SL Factor is a double (1.5). But here's what I get in the journal log :

Did i miss something ?

Most double values don't have an exact representation, so your output are ok.

Is it the SL for a buy order ? Please show all the relevant code (all code with "request").

What is the value of ticksize for this symbol ?

Icham Aidibe
10306
Icham Aidibe  
angevoyageur:

Most double values don't have an exact representation, so your output are ok.

Is it the SL for a buy order ? Please show all the relevant code (all code with "request").

What is the value of ticksize for this symbol ?

Yep that's a long position SL with symbol's value of tick : 12.5 & size of the tick : 0.5.

Waiting for your answer I'm trying to convert all of it in string. (it may work??)

EDIT : nope it didn't work :/ à l'aide l'ange !

Alain Verleyen
Moderator
32808
Alain Verleyen  
blouf:

Yep that's a long position SL with symbol's value of tick : 12.5 & size of the tick : 0.5.

Waiting for your answer I'm trying to convert all of it in string. (it may work??)

EDIT : nope it didn't work :/ à l'aide l'ange !

Convert what in string ? It's not needed.

Your problem comes from your price, which are doubles. Do you understand the meaning of a tick size of 0.5 ? That means all you price (entry, sl, tp) must be a multiple of 0.5. You can't have a sl of 9399.8, it can be 9399.5 or 9400.

Icham Aidibe
10306
Icham Aidibe  
angevoyageur:

Convert what in string ? It's not needed.

Your problem comes from your price, which are doubles. Do you understand the meaning of a tick size of 0.5 ? That means all you price (entry, sl, tp) must be a multiple of 0.5. You can't have a sl of 9399.8, it can be 9399.5 or 9400.

Hum hum ... well, i may have ignored the deep interest of the tick size. Anyway, thanks for explaining l'ange !
To add comments, please log in or register