Rounding Stop Loss and Take Profit levels...

Created at 30 Jan 2018, 16:52
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
DR

Drummond360

Joined 22.12.2017

Rounding Stop Loss and Take Profit levels...
30 Jan 2018, 16:52


Hi all, 

I'm very confused by the resutls returned below, can anyone see what's happening?!?

This code:

            var abcSL = (UpPatternfib382 - minLow) * Symbol.PipSize;
            var abcTP = (ABCDentryPrice - minLow) * Symbol.PipSize;

returns this result: 

abcSL = 4.57319999999983E-08 

abcTP = 9.41279999999934E-08

and this code:

var abcSL = Math.Round((UpPatternfib382 - minLow) * Symbol.PipSize, 2);
var abcTP = Math.Round((ABCDentryPrice - minLow) * Symbol.PipSize, 2);

returns this result:

abcSL = 0 

abcTP = 0

It seems that the fractional digits don't have any effect on the value returned, always showing 0... Why would this be?!?

Many thanks in advance,

Drummond


@Drummond360
Replies

PanagiotisCharalampous
30 Jan 2018, 17:01

Hi Drummond,

This is because you round to the 2nd decimal place. Your values begin at the 8th decimal place. Try the following

var abcSL = Math.Round((UpPatternfib382 - minLow) * Symbol.PipSize, 8);
var abcTP = Math.Round((ABCDentryPrice - minLow) * Symbol.PipSize, 8);

Best Regards,

Panagiotis


@PanagiotisCharalampous

Drummond360
30 Jan 2018, 17:08

Thank you fo rthe quick reponse Panagiotis...

Changing the value to 8 returns this result:

abcSL = 5E-08 

abcTP = 9E-08

Still no good as a calculation of pips to use for StopLoss / TakeProfit levels...

 


@Drummond360

PanagiotisCharalampous
30 Jan 2018, 17:14

Hi Drummond,

Well that is the value. Would you like to explain to us what you are trying to do? If you are trying to get the pip size of a difference between two prices then you should divide instead of multiplying. See below

var abcSL = (UpPatternfib382 - minLow) / Symbol.PipSize;
var abcTP = (ABCDentryPrice - minLow) / Symbol.PipSize;

Best Regards,

Panagiotis


@PanagiotisCharalampous

Drummond360
30 Jan 2018, 17:17

That's fixed it! Thank you once again....

Drummond


@Drummond360