Category Trend  Published on 07/02/2015

Fractals

Description

NinjaTrader Fractals indicator analog.

No other description ...

No other comments ...

It is free of charge :)

This is a sample image:

End of description.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Fractals : Indicator
    {
        [Parameter("Show prices", DefaultValue = true)]
        public bool ShowPrices { get; set; }

        [Parameter("Days backward", DefaultValue = 10)]
        public int DaysBackward { get; set; }
        
        private MarketSeries m;
        
        private double lastHi;
        private double lastLo;

        protected override void Initialize()
        {
            m = MarketData.GetSeries(TimeFrame.Daily);
            lastHi = double.MinValue;
            lastLo = double.MaxValue;
            OnTimer();
            Timer.Start(10);
        }

        private int GetIndexByPrice(DataSeries series, double price)
        {
            for (int i = 1; MarketSeries.OpenTime[series.Count - i] >= m.OpenTime[DaysBackward]; ++i)
            {
                if (series[series.Count - i] == price)
                {
                    return series.Count - i;
                }
            }
            return -1;
        }

        public override void Calculate(int index)
        {
        }

        private void DrawLine(DataSeries series, double price, int d, VerticalAlignment a)
        {
            int indexLast = GetIndexByPrice(series, price);
            if (indexLast != -1)
            {
                string l_name = string.Format("p_{0}", price);
                string t_name = string.Format("t_{0}", price);
                ChartObjects.DrawLine(l_name, MarketSeries.OpenTime[indexLast], price, MarketSeries.OpenTime.LastValue.AddYears(2), price, Colors.DarkGray, 1, LineStyle.LinesDots);
                if (ShowPrices)
                {
                    ChartObjects.DrawText(t_name, string.Format("{0}", price), indexLast, price + d * Symbol.PipSize, a, HorizontalAlignment.Right, Colors.DarkGray);
                }
            }
        }

        protected override void OnTimer()
        {
            if (lastHi > m.High.Maximum(1) && lastLo <  m.Low.Minimum(1))
            {
                return;
            }
            
            ChartObjects.RemoveAllObjects();
            
            double prevHi = double.MinValue, prevLo = double.MaxValue;
            
            for (int i = 1; i <= DaysBackward; ++i)
            {
                double hi = m.High.Maximum(i);
                double lo = m.Low.Minimum(i);

                if (prevHi < hi)
                {
                    DrawLine(MarketSeries.High, hi, 2, VerticalAlignment.Top);
                    prevHi = hi;
                }

                if (prevLo > lo)
                {
                    DrawLine(MarketSeries.Low, lo, -2, VerticalAlignment.Bottom);
                    prevLo = lo;
                }
            }
            
            lastHi = m.High.Maximum(1);
            lastLo = m.Low.Minimum(1);
        }
    }
}


ZI
ZigzagAK

Joined on 06.02.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Fractals.algo
  • Rating: 0
  • Installs: 5305
Comments
Log in to add a comment.
QU
QuanTrade · 11 months ago

what period are the fractals set to, it shows me different fractals from the default indicator on ctrader !

QU
QuanTrade · 11 months ago

excellent indicators, is it possible in your opinion to insert a multi timeframe, for example observe the H1 fractals on a 5 minute TimeFrame ?

CA
carvalhoalbuquerque25 · 3 years ago

this indicator would look great combined with the zigzag.
For example, in the entire zig zag leg it would form a line, like this image below.

http://icmarkets.ctrader.com/c/VHHvn

http://icmarkets.ctrader.com/c/DHHvn

CU
CuteLittleMay · 3 years ago

buggy, it deletes trendlines you draw by hand