Download MetaTrader 5

Another issue with StopLoss's

To add comments, please log in or register
The entire MQL5.community history on a single page!
Willbur
198
Willbur 2016.04.14 14:38 

I've got a problem with an sl too. Whenever I think it's about numbers typed "double".

Bevor I use my SL in OrderSend() I try to round it to the posible numbers given by the TickSize.

double sl = 0.00544;
double currSymbolTickSize = 0.00001;
            
sl = MathRound(sl*currSymbolTickSize)/currSymbolTickSize;  // round to posible numbers

It works fine for e.g. Ger30Jun16  

SymbolTickSize is 0.5
SL = 10000,4 becomes 10000,5

Trying with e.g. USDCHF with a TickSize of 0.00001 the calculation gives me a  Zero.

Willbur

Doerk Hilger
1176
Doerk Hilger 2016.04.14 18:22  
CSymbolInfo is a class defined in SymbolInfo.mqh. Why dont you use that instead of reinventing the wheel? The function .NormalizePrice() delivers what you are looking for. And if you are using MT4, drop the unsupported functions and keep the rest of it.
Willbur
198
Willbur 2016.04.14 22:01  
Willbur:

I've got a problem with an sl too. Whenever I think it's about numbers typed "double".

Bevor I use my SL in OrderSend() I try to round it to the posible numbers given by the TickSize.

It works fine for e.g. Ger30Jun16  

SymbolTickSize is 0.5
SL = 10000,4 becomes 10000,5

Trying with e.g. USDCHF with a TickSize of 0.00001 the calculation gives me a  Zero.

Willbur

Thanks Doerk - I will check this out.

In my formular there was a very stupid error.

It should be:

double sl = 0.00544;
double currSymbolTickSize = 0.00001;
            
sl = MathRound(sl/currSymbolTickSize)*currSymbolTickSize;  // round to posible numbers

Willbur

Doerk Hilger
1176
Doerk Hilger 2016.04.14 22:19  
Youre welcome. But you should check if the ticksize is present, not all brokers provide a value. 
Alain Verleyen
Moderator
30752
Alain Verleyen 2016.04.15 08:11  
Doerk Hilger:
Youre welcome. But you should check if the ticksize is present, not all brokers provide a value. 
A broker which doesn't provide a value should be avoided, it's either incompetent or dishonest.
Willbur
198
Willbur 2016.04.15 12:50  

Some people think that this is a bad habit, but I always want to know exacly how something works.

So I disassembled NormalizePrice - and: There is nothing else in but the same formular.

In addition, it reduces the number of decimal places, which can't be relevant after the MathRound.

double CSymbolInfo::NormalizePrice(const double price) const

  {
   if(m_tick_size!=0)
      return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,m_digits));
//---
   return(NormalizeDouble(price,m_digits));
  }
Doerk Hilger
1176
Doerk Hilger 2016.04.15 17:51  

... yep, and checks if there is a value for the tick-size. Thats why I mentioned it. 

Alain, of course you are right, but better checking it than getting a division by zero

Alain Verleyen
Moderator
30752
Alain Verleyen 2016.04.15 20:53  
Doerk Hilger:

... yep, and checks if there is a value for the tick-size. Thats why I mentioned it. 

Alain, of course you are right, but better checking it than getting a division by zero

For sure.
To add comments, please log in or register