Another issue with StopLoss's

 

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

 
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:

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

 
Youre welcome. But you should check if the ticksize is present, not all brokers provide a value. 
 
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.
 

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));
  }
 

... 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

 
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.
Reason: