less-than/greater-than vs HasCrossedBelow/HasCrossedAbove ?

Created at 25 Jun 2019, 06:44
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!
FI

firemyst

Joined 26.03.2019

less-than/greater-than vs HasCrossedBelow/HasCrossedAbove ?
25 Jun 2019, 06:44


Hi everyone:

What's "special" about the HasCrossedAbove or HasCrossedBelow methods on indicators as opposed to just doing a simple less-than or greater-than?

For example, in a bot assume I have 2 Exponential Moving Averages defined.

What's the difference between the following:

if (_ema1.Result.Last(0) < _ema2.Result.Last(0)) { }
//
//or
//
if (_ema1.Result.HasCrossedBelow(_ema2.Result, 0)) { }

Do the HasCrossedBelow/HasCrossedAbove methods have additional checks to ensure a more definitive crossing? Do they make a difference for a period other than zero?

In a nutshell, why would I ever want to use the latter as opposed to the former?

Thank you.


@firemyst
Replies

PanagiotisCharalampous
25 Jun 2019, 09:28

Hi FireMyst,

if (_ema1.Result.HasCrossedBelow(_ema2.Result, i)) { }

will check if there was a cross in the last i bars, from 0 to i. So essentially it implements a for loop. On the other hand

if (_ema1.Result.Last(i) < _ema2.Result.Last(i)) { }

will only check the bars with index i.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
25 Jun 2019, 09:58

RE:

Panagiotis Charalampous said:

Hi FireMyst,

if (_ema1.Result.HasCrossedBelow(_ema2.Result, i)) { }

will check if there was a cross in the last i bars, from 0 to i. So essentially it implements a for loop. On the other hand

if (_ema1.Result.Last(i) < _ema2.Result.Last(i)) { }

will only check the bars with index i.

Best Regards,

Panagiotis

Thanks @Panagiotis!

Your explanation is a lot better to me than what I read on the API page: https://ctrader.com/api/reference/functions/hascrossedbelow

 


@firemyst

firemyst
25 Jun 2019, 09:58

RE:

Panagiotis Charalampous said:

Hi FireMyst,

if (_ema1.Result.HasCrossedBelow(_ema2.Result, i)) { }

will check if there was a cross in the last i bars, from 0 to i. So essentially it implements a for loop. On the other hand

if (_ema1.Result.Last(i) < _ema2.Result.Last(i)) { }

will only check the bars with index i.

Best Regards,

Panagiotis

Thanks @Panagiotis!

Your explanation is a lot better to me than what I read on the API page: https://ctrader.com/api/reference/functions/hascrossedbelow

 


@firemyst