Algorithme Code for distance between 2 MA

Created at 14 Jun 2022, 17:56
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!
E.

e.ameganvi

Joined 14.06.2022

Algorithme Code for distance between 2 MA
14 Jun 2022, 17:56


Hello i will need to implement a code to expresse these conditions:

1- « If distance between MA1 et MA2 > to 4pips »

2- the higher highs of an uptrend and lower low of an downtrend 

Can you help me please ? Thanks 


@e.ameganvi
Replies

amusleh
15 Jun 2022, 08:13

Hi,

You can get the distance between two moving averages like this:

            var distanceInPips = Math.Abs(_firstMa.Result[index] - _secondMa.Result[index]) / Symbol.PipSize;
            
            if (distanceInPips > 4)
            {
                // Do something
            }

Regarding your second point, you have to define what's an higher high and what's a lower low, then you will be able to code it.


@amusleh