Auto Draw Fibonacci

by Rony Sitepu in category Volatility at 24/10/2018
Description

Auto Draw Fibonacci on period of X Bar

Download
406 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.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Autofibo : Indicator
    {
        [Parameter("Look Back Period ", DefaultValue = 100)]
        public int lookback { get; set; }

        [Parameter("Series Timeframe")]
        public TimeFrame tf { get; set; }




        private MarketSeries series1;


        protected override void Initialize()
        {
            // Initialize and create nested indicators
            series1 = MarketData.GetSeries(tf);

            OnTimer();
            Timer.Start(60);
        }

        protected override void OnTimer()
        {
            // Initialize and create nested indicators

            //find index
            var hidate = Time.Date;
            var lodate = Time.Date;
            var superhi = MarketSeries.Close.LastValue;
            var superlo = MarketSeries.Close.LastValue;
            var highval = series1.High;
            var loval = series1.Low;

            for (var i = 0; i < lookback; i++)
            {
                //find hi
                if (highval.Last(i) > superhi)
                {
                    superhi = highval.Last(i);
                    hidate = series1.OpenTime.Last(i);
                }

                //findlo
                if (loval.Last(i) < superlo)
                {
                    superlo = loval.Last(i);
                    lodate = series1.OpenTime.Last(i);
                }


                var bull = (hidate > lodate) ? true : false;
                var datechosen = (bull) ? lodate : hidate;

                //set value of line

                List<double> level = new List<double> 
                {
                    0.0,
                    23.6,
                    38.0,
                    50.0,
                    61.8,
                    100
                };


                var now = MarketSeries.OpenTime.LastValue;
                var distance = superhi - superlo;
//drawline 

                foreach (var lev in level)
                {
                    var dev = lev / 100 * distance;
                    var val = (bull) ? superhi - dev : superlo + dev;

                    ChartObjects.DrawLine(lev + "%", datechosen, val, now, val, (bull) ? Colors.Red : Colors.Blue, 1, LineStyle.Solid);
                    ChartObjects.DrawText(lev + "% text", lev + "%", MarketSeries.OpenTime.Count + 1, val + 0.5 * Symbol.PipSize, VerticalAlignment.Center, HorizontalAlignment.Right, (bull) ? Colors.Red : Colors.Blue);



                }






            }


        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
        }
    }
}
Comments
0