Fractals free

by spka111 in category Trend at 20/08/2012
Description

The basic Fractals are created with 5 or more bars. With 5 bars, if the highest high is in the middle of the two lower highs on each side an up fractal is generated. Conversely, a down fractal is created when the lowest low is in the middle of two higher lows on each side. Since the fractal can only be created two bars later it is considered a lagging indicator, but if it is assumed that the reversal will last for more bars then the trend will remain as is.

16232 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using cAlgo.API;


namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class Fractals:Indicator
    {
        [Parameter(DefaultValue = 5, MinValue = 5)]
        public int Period { get; set; }

        [Output("Up Fractal", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpFractal { get; set; }

        [Output("Down Fractal", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownFractal { get; set; }

        
        
        
        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            DrawUpFractal(index);
            DrawDownFractal(index);

        }

        private void DrawUpFractal(int index)
        {
            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = index - period / 2;
            double middleValue = MarketSeries.High[middleIndex];

            bool up = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue < MarketSeries.High[index - i])
                {
                    up = false;
                    break;
                }
            }
            if (up)
                UpFractal[middleIndex] = middleValue;

        }

        private void DrawDownFractal(int index)
        {
            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = index - period / 2;
            double middleValue = MarketSeries.Low[middleIndex];
            bool down = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue > MarketSeries.Low[index - i])
                {
                    down = false;
                    break;
                }
            }
            if (down)
                DownFractal[middleIndex] = middleValue;

        }


    }
}
Comments

itaiophir - April 19, 2014 @ 16:38

Hi there,

this indicator looks good and i would like to use within a cBot.

i'm trying to understand what is the "index" parameter used in methods in order to re-write the code.

how can you help me with that?

thanks,

Itai

heldercosta83 - October 13, 2014 @ 22:16

Is it possible to give a margin on the fractals so that they are not glued to the candlestick ?

Would be much more readble.

 

Thanks in advande.

dima1302 - July 23, 2015 @ 15:14

I found that it's not always show fractals correct. Look at the screen shot. Last high-fractal shouldn't appear in that place, becourse second high after it is much higher. http://fxpro.ctrader.com/c/LpRyn

scottagaul - February 13, 2016 @ 01:26

The description explains why that High does not show.

"Since the fractal can only be created two bars later it is considered a lagging indicator..."

sifneosfx - October 05, 2019 @ 17:07

This is how to use it in a cBot: https://ctrader.com/algos/cbots/show/2016

matt92 - October 15, 2019 @ 19:38

Does this indicator repaint? because it is printing the dot before the 5th candle has closed if all other criteria is met..

fetileventakcin - November 26, 2019 @ 16:39

Hi Sir. 

I am using cTrader Desktop. And I can not make the Up and Down Fractals icon bigger. Despite I select the thickest linetype, it is not effecting the size of the icons. Could you please help me? 

 

Regards. 

Levent

ctid491219 - April 12, 2020 @ 21:57

Thias indicator is very important (sp tx for making it). But like matt92 points out there is an annoying problem with the code: It prints the dot before the 5th candle has closed AND more important: If it is no longer a fractal when the 5th bar is closed it doesn't repaint so a wrong fractal is shown. You then have to choose another timeframe and go back again to make the wrong fractals disappear. Isn't ther some easy way to code the indicator not to paint the dot until the 5th candle is closed?

4.17