Real Time Fibonacci Indicators

by Scott in category Trend at 04/05/2013
Description

****************************  WILL ONLY WORK WHEN MARKET IS LIVE

This indicator uses fibonacci simple moving averages and fibonacci bands (http://ctdn.com/algos/indicators/show/190) to show support and resistance over 4 time frames. They are shown as price and plotted on the chart as below

You will need to open 4 charts 1m, 5m, 15m, 60m build the Average True Range (ATR) indicator first as you will need to referance this in the fibbandsRT indicator (code at bottom)

Then load  fiblevelsRT and fibbandsRT indicators (code at bottom of post) resize them so they are like below, you will also have to move the time box to the left a bit to bring it all into view.

For the charts load FibGrid7Chart they will show 7 SMA's that show history, you could also add the fiboonacci bands indicator but I find this get crowded (I use it when looking though historical data)

There are 4 SMA's shown on the real time indicator they are 21sma, 34sma, 55sma and 233sma

The fibonacci bands show 23.60%, 38.00%, 61.80%, and 100.00% from the Average True Range (ATR) both above and below

The FibGrid7Chart Indicator Shows 7 simple moving averages 21sma, 34sma, 55sma, 75sma, 100sma, 144sma and 233sma

 

// Average True Range   ---- Build this first as it needs to referenced in fibbandsRT

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false,ScalePrecision = 5)]
    public class averageTrueRange : Indicator
    {   
        [Parameter(DefaultValue = 14, MinValue = 2)]
        public int Period { get; set; }
        
          [Output("AverageTrueRange", Color = Colors.Orange)]
        public IndicatorDataSeries atr { get; set; }
        
        private ExponentialMovingAverage ema;
           public IndicatorDataSeries tr;
           private TrueRange tri;
        protected override void Initialize()
        {
            tr =  CreateDataSeries();
            tri = Indicators.TrueRange();
            ema = Indicators.ExponentialMovingAverage(tr,Period);
        }
        
        public override void Calculate(int index)
        {
            if(index<Period+1)
            {atr[index] = tri.Result[index];}
            if(index>=Period){
            atr[index] = (atr[index-1]*(Period-1)+tri.Result[index]) / Period;}
        }
    }
}

 

//  fibbandsRT  --- You need to referance the Average True Range indicator before this will build

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class fibbandsRT : Indicator
    {
        private averageTrueRange _averageTrueRange;
        private ExponentialMovingAverage _exponentialMovingAverage;


        [Parameter(DefaultValue = 55)]
        public int PeriodEma { get; set; }

        [Parameter(DefaultValue = 21)]
        public int PeriodAtr { get; set; }

        [Output("Upper Band 1", Color = Colors.Aqua)]
        public IndicatorDataSeries UpperBand1 { get; set; }

        [Output("Upper Band 2", Color = Colors.DeepSkyBlue)]
        public IndicatorDataSeries UpperBand2 { get; set; }

        [Output("Upper Band 3", Color = Colors.DodgerBlue)]
        public IndicatorDataSeries UpperBand3 { get; set; }

        [Output("Upper Band 4", Color = Colors.Aquamarine)]
        public IndicatorDataSeries UpperBand4 { get; set; }

        [Output("Lower Band 1", Color = Colors.Aqua)]
        public IndicatorDataSeries LowerBand1 { get; set; }

        [Output("Lower Band 2", Color = Colors.DeepSkyBlue)]
        public IndicatorDataSeries LowerBand2 { get; set; }

        [Output("Lower Band 3", Color = Colors.DodgerBlue)]
        public IndicatorDataSeries LowerBand3 { get; set; }

        [Output("Lower Band 4", Color = Colors.Aquamarine)]
        public IndicatorDataSeries LowerBand4 { get; set; }

        [Output("EMA", Color = Colors.SlateGray)]
        public IndicatorDataSeries Ema { get; set; }

        protected override void Initialize()
        {
            _averageTrueRange = Indicators.GetIndicator<averageTrueRange>(PeriodAtr);
            _exponentialMovingAverage = Indicators.ExponentialMovingAverage(MarketSeries.Close, PeriodEma);
        }


        public override void Calculate(int index)
        {
            if (!IsRealTime) return;
            for  (int i = index - 10; i <= index; i++) 
            {
                double ema = _exponentialMovingAverage.Result[index];
                double atr = _averageTrueRange.atr[index];

                UpperBand1[i] = ema + 1.62*atr;
                UpperBand2[i] = ema + 2.62*atr;
                UpperBand3[i] = ema + 4.23*atr;
                UpperBand4[i] = ema + 1*atr;
                LowerBand1[i] = ema - 1.62*atr;
                LowerBand2[i] = ema - 2.62*atr;
                LowerBand3[i] = ema - 4.23*atr;
                LowerBand4[i] = ema - 1*atr;

                Ema[i] = ema;
            }
            for (int i = 0; i < index - 10; i++)
            {
                UpperBand1[i] = double.NaN;
                UpperBand2[i] = double.NaN;
                UpperBand3[i] = double.NaN;
                UpperBand4[i] = double.NaN;
                LowerBand1[i] = double.NaN;
                LowerBand2[i] = double.NaN;
                LowerBand3[i] = double.NaN;
                LowerBand4[i] = double.NaN;

                Ema[i] = double.NaN;
            }

            int xPos = index + 0;
            double yPos = UpperBand1[index];
            string text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj1", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.Aqua);

            yPos = UpperBand2[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj2", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left,
                                  Colors.DeepSkyBlue);

            yPos = UpperBand3[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj3", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left,
                                  Colors.DodgerBlue);

            yPos = UpperBand4[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj4", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.Aquamarine);

            yPos = LowerBand1[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj5", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.Aqua);
            yPos = LowerBand2[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj6", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left,
                                  Colors.DeepSkyBlue);
            yPos = LowerBand3[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj7", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left,
                                  Colors.DodgerBlue);
            yPos = LowerBand4[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj8", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.Aquamarine);
            
            yPos = Ema[index];
            text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
            ChartObjects.DrawText("obj9", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.SlateGray);
        }
    }
}

 

//  fiblevelsRT indicator

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class fiblevelsRT : Indicator
    {
        private fiblevelsRT fiblevelsRTIndicator;    
        [Parameter]
           
        public DataSeries Source { get; set; }

        [Parameter("L1", DefaultValue = 21)]
        public int Periods { get; set; }
        [Parameter("L2", DefaultValue = 34)]
        public int Periods2 { get; set; }
        [Parameter("L3", DefaultValue = 55)]
        public int Periods3 { get; set; }

        [Parameter("L7", DefaultValue = 233)]
        public int Periods7 { get; set; }

        [Output("Level1", Color = Colors.Lime, Thickness = 5, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries Result { get; set; }
        [Output("Level2", Color = Colors.Yellow, Thickness = 5, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries Result2 { get; set; }
        [Output("Level3", Color = Colors.White, Thickness = 5, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries Result3 { get; set; }

        [Output("Level7", Color = Colors.Red, Thickness = 5, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries Result7 { get; set; }

        private SimpleMovingAverage _simpleMovingAverage1;
        private SimpleMovingAverage _simpleMovingAverage2;
        private SimpleMovingAverage _simpleMovingAverage3;        

        private SimpleMovingAverage _simpleMovingAverage7;


        protected override void Initialize()
        {
            _simpleMovingAverage1 = Indicators.SimpleMovingAverage(Source, Periods);
            _simpleMovingAverage2 = Indicators.SimpleMovingAverage(Source, Periods2);
            _simpleMovingAverage3 = Indicators.SimpleMovingAverage(Source, Periods3);

            _simpleMovingAverage7 = Indicators.SimpleMovingAverage(Source, Periods7);


        }


public override void Calculate(int index)
{
    if (!IsRealTime) return;

    for (int i = index - 10; i <= index; i++)
        {
        Result[i] = _simpleMovingAverage1.Result[index];
        Result2[i] = _simpleMovingAverage2.Result[index];
        Result3[i] = _simpleMovingAverage3.Result[index];

        Result7[i] = _simpleMovingAverage7.Result[index];
    }
    for(int i = 0; i < index - 10; i++)
    {
        Result[i] = double.NaN;
        Result2[i] = double.NaN;
        Result3[i] = double.NaN;

        Result7[i] = double.NaN;
    }
    int xPos = index + 1;
    double yPos = _simpleMovingAverage1.Result[index];
    var text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
    ChartObjects.DrawText("obj1", text, xPos, yPos, VerticalAlignment.Center, HorizontalAlignment.Left,Colors.Lime);

    yPos = _simpleMovingAverage2.Result[index];
    text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
    ChartObjects.DrawText("obj2", text, xPos, yPos, VerticalAlignment.Bottom, HorizontalAlignment.Left,Colors.Yellow);

    yPos = _simpleMovingAverage3.Result[index];
    text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
    ChartObjects.DrawText("obj3", text, xPos, yPos, VerticalAlignment.Center, HorizontalAlignment.Left,Colors.White);



    yPos = _simpleMovingAverage7.Result[index];
    text = String.Format("{0}", Math.Round(yPos, Symbol.Digits));
    ChartObjects.DrawText("obj7", text, xPos, yPos, VerticalAlignment.Top, HorizontalAlignment.Left, Colors.Red);
}
}
}

 

//  FibGrid7Chart Indicator  --- 7 simple moving averages 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class FibGrid7Chart : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }

        [Parameter("L1", DefaultValue = 21)]
        public int Periods { get; set; }
        [Parameter("L2", DefaultValue = 34)]
        public int Periods2 { get; set; }
        [Parameter("L3", DefaultValue = 55)]
        public int Periods3 { get; set; }
        [Parameter("L4", DefaultValue = 75)]
        public int Periods4 { get; set; }
        [Parameter("L5", DefaultValue = 100)]
        public int Periods5 { get; set; }
        [Parameter("L6", DefaultValue = 144)]
        public int Periods6 { get; set; }
        [Parameter("L7", DefaultValue = 233)]
        public int Periods7 { get; set; }

        [Output("Level1", Color = Colors.Lime, Thickness = 3)]
        public IndicatorDataSeries Result { get; set; }
        [Output("Level2", Color = Colors.Yellow, Thickness = 3)]
        public IndicatorDataSeries Result2 { get; set; }
        [Output("Level3", Color = Colors.White, Thickness = 3)]
        public IndicatorDataSeries Result3 { get; set; }
        [Output("Level4", Color = Colors.Aqua, Thickness = 3)]
        public IndicatorDataSeries Result4 { get; set; }
        [Output("Level5", Color = Colors.Blue, Thickness = 3)]
        public IndicatorDataSeries Result5 { get; set; }
        [Output("Level6", Color = Colors.Orange, Thickness = 3)]
        public IndicatorDataSeries Result6 { get; set; }
        [Output("Level7", Color = Colors.Red, Thickness = 3)]
        public IndicatorDataSeries Result7 { get; set; }

        private SimpleMovingAverage _simpleMovingAverage1;
        private SimpleMovingAverage _simpleMovingAverage2;
        private SimpleMovingAverage _simpleMovingAverage3;        
        private SimpleMovingAverage _simpleMovingAverage4;
        private SimpleMovingAverage _simpleMovingAverage5;
        private SimpleMovingAverage _simpleMovingAverage6;
        private SimpleMovingAverage _simpleMovingAverage7;


        protected override void Initialize()
        {
            _simpleMovingAverage1 = Indicators.SimpleMovingAverage(Source, Periods);
            _simpleMovingAverage2 = Indicators.SimpleMovingAverage(Source, Periods2);
            _simpleMovingAverage3 = Indicators.SimpleMovingAverage(Source, Periods3);
            _simpleMovingAverage4 = Indicators.SimpleMovingAverage(Source, Periods4);
            _simpleMovingAverage5 = Indicators.SimpleMovingAverage(Source, Periods5);
            _simpleMovingAverage6 = Indicators.SimpleMovingAverage(Source, Periods6);
            _simpleMovingAverage7 = Indicators.SimpleMovingAverage(Source, Periods7);


        }
        public override void Calculate(int index)
        {
            Result[index] = _simpleMovingAverage1.Result[index];
            Result2[index] = _simpleMovingAverage2.Result[index];
            Result3[index] = _simpleMovingAverage3.Result[index];
            Result4[index] = _simpleMovingAverage4.Result[index];
            Result5[index] = _simpleMovingAverage5.Result[index];
            Result6[index] = _simpleMovingAverage6.Result[index];
            Result7[index] = _simpleMovingAverage7.Result[index];
         

        }

    }
}
  

If anyone wants the modified 1m that shows the price and lays out the fibs let me know

I would also like to thank support for all there hard work in helping me build this indicator (like 99% I've just modified)

Scott

 

Download
3767 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 System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false,ScalePrecision = 5, AccessRights = AccessRights.None)]
    public class averageTrueRange : Indicator
    {   
        [Parameter(DefaultValue = 14, MinValue = 2)]
        public int Period { get; set; }
        
      	[Output("AverageTrueRange", Color = Colors.Orange)]
        public IndicatorDataSeries atr { get; set; }
        
        private ExponentialMovingAverage ema;
       	public IndicatorDataSeries tr;
       	private TrueRange tri;
		protected override void Initialize()
        {
        	tr =  CreateDataSeries();
        	tri = Indicators.TrueRange();
        	ema = Indicators.ExponentialMovingAverage(tr,Period);
        }
        
        public override void Calculate(int index)
        {
        	if(index<Period+1)
        	{atr[index] = tri.Result[index];}
        	if(index>=Period){
        	atr[index] = (atr[index-1]*(Period-1)+tri.Result[index]) / Period;}
        }
    }
}
Comments

lec0456 - May 04, 2013 @ 18:08

This looks interesting. So, how do you trade with it?

Scott - May 04, 2013 @ 22:47

Its the same way as money map/tiger pips software, you can get it for MT4 its called combogrid2, but it wont work with my brokers version of MT4. I wouldn't call myself a expert trader with this but I get it better than I can explain it, but I'll have a go :) I use all the sma's as support levels as well as the fibonacci bands over 4 time frames. I trade mostly of the 5 minute. I use the first 3 levels/sma as support so if they are in order L1 L2 L3 then I looking to go long after its either passed though the levels and 1 to 2 candles have closed above the L1 or If the L1 L2 L3 setup has occurred and the price is above, I would wait for a retrace back to the L1 and go long off the bounce. The L7/sma can either end a trend or continue it. If L7 crosses the L1 and the price has been rising it tends to end the direction and trend, if the price is falling at that time then it can cause the price to continue down or offer a long buy in if the price bounces of the L1 in the near future. The fibonacci band levels I use as exits and also to see spaces in between the different time frames to judge if there is room for price to climb. Take a look at tiger pips youtube channel http://www.youtube.com/feed/UC59PKf9nIj-gfNYzzHPbZ6Q I'm working on boolean code to fix the price center and fix the range of the price, but not a c# programmer so it's taking some time to get right, right now I have diddly squat, take a look at my post for better explanation http://ctdn.com/forum/indicator-support/761 thanks for the interest lec

Scott - May 04, 2013 @ 22:53

The L7/sma can either end a trend or continue it. If L7 crosses the L1 and the price has been falling it tends to end the direction and trend, if the price is falling at that time then it can cause the price to continue up or offer a long buy in if the price bounces of the L1 in the near future. got mixed up on that bit corrected it, I would load the FibGrid7Chart Indicator to have a look and see what I mean, I'm not the best at explaining this as I said.

Scott - May 04, 2013 @ 22:53

The L7/sma can either end a trend or continue it. If L7 crosses the L1 and the price has been falling it tends to end the direction and trend, if the price is falling at that time then it can cause the price to continue up or offer a long buy in if the price bounces of the L1 in the near future. got mixed up on that bit corrected it, I would load the FibGrid7Chart Indicator to have a look and see what I mean, I'm not the best at explaining this as I said.

kricka - May 05, 2013 @ 02:54

Excellent documentation! I wish everybody who post indicators or robots will give a full description. Good work!

Scott - May 05, 2013 @ 21:25

Thanks Kricka

NyanHtet - February 14, 2017 @ 19:07

hi, 
i m very new.

how do i get from indicator to Cbots?

5