access the values of Indicators.Fractals

Created at 01 Mar 2021, 12:37
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!
xabbu's avatar

xabbu

Joined 20.07.2020

access the values of Indicators.Fractals
01 Mar 2021, 12:37


Dear Panagiotis,

how can I access the values of the buildin indicator Indicators.Fractals and how can I make decisions based on was the last fractal an up or down fractal - like:

if the last printed fractal on chart was an downfractal -> only short trades are allowed?

Is there any documentation or hints you would like to give me?

Kindest regards,


@xabbu
Replies

PanagiotisCharalampous
01 Mar 2021, 12:44

Hi xabbu,

The values are stored in UpFractal and DownFractal data series

            var fractals = Indicators.Fractals(10);
            Print(fractals.DownFractal.LastValue);
            Print(fractals.UpFractal.LastValue);

The values are saved at the relevant index of the data series. If there is no value, then the value will be NaN. Therefore the last fractal is the one with a value at the highest index.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

xabbu
01 Mar 2021, 14:40

Thank you, Panagiotis!

I have never before worked with NaN and it seems I cant get it to work:

if (double.IsNaN(_fractals.UpFractal.LastValue))
                {
                    Print("Down: " + _fractals.DownFractal.LastValue);
                }

                if (double.IsNaN(_fractals.DownFractal.LastValue))
                {
                    Print("Down: " + _fractals.DownFractal.LastValue);
                }

Can you point me in the right direction, please...?

Kindest regards,


@xabbu

PanagiotisCharalampous
01 Mar 2021, 15:16

Hi xabbu,

What is the code you posted supposed to do?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

xabbu
01 Mar 2021, 17:48 ( Updated at: 21 Dec 2023, 09:22 )

Panagiotis, thank you for taking care!

The code does nothing and was only meent to give me access and an understanding for the function.

What I want to do:

if the last fractal was above (signaling a down trend) I want to take only short trades.

if it was below only long trades.

I would like to use fractals as a kind of filter to prevent unwanted trade direction like here in this picture:

the fractal at the left should prevent me from taking the circeled long trade...


@xabbu

PanagiotisCharalampous
02 Mar 2021, 10:47

Hi xabbu,

Here is an example

            var fractals = Indicators.Fractals(10);
            int lastUpFractalIndex = 1;
            int lastDownFractalIndex = 1;
            
            while (double.IsNaN(fractals.UpFractal.Last(lastUpFractalIndex)))
                lastUpFractalIndex++;
            while (double.IsNaN(fractals.DownFractal.Last(lastDownFractalIndex)))
                lastDownFractalIndex++;

            if (lastUpFractalIndex < lastDownFractalIndex)
                Print("Last Fractal  was Up");
            if (lastUpFractalIndex > lastDownFractalIndex)
                Print("Last Fractal was Down");

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous