access the values of Indicators.Fractals

xabbu's avatar

xabbu since: 20 Jul 2020;

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

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,

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  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

Head of Community Management at cTrader
xabbu's avatar

xabbu since: 20 Jul 2020;

  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,

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  01 Mar 2021, 15:16

Hi xabbu,

What is the code you posted supposed to do?

Best Regards,

Panagiotis 

Join us on Telegram

Head of Community Management at cTrader
xabbu's avatar

xabbu since: 20 Jul 2020;

  01 Mar 2021, 17:50

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

PanagiotisCharalampous's avatar

PanagiotisCharalampous since: 13 Jan 2017;

  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

Head of Community Management at cTrader