Category Trend  Published on 20/06/2019

Fibonacci Retracement

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them.

This indicator prints the X% retracement of the last swing measured from the pivot of a zigzag with amplitude equal to the Deviation parameter.

Useful for who wants to have an automatic X% retracement on any movement that is at least Y% of the underlying asset.

To report any bug leave a comment or contact me directly at the link above.


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 0.5)]
        public double Deviation { get; set; }
        [Parameter("% Retracement", DefaultValue = 38.2)]
        public double per { get; set; }

        [Output("_forIndicators", Color = Colors.Gray, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries sign { get; set; }
        [Output("UpTrend", PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries up { get; set; }
        [Output("DownTrend", Color = Colors.Red, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries down { get; set; }

        private ZigZagAndFiboLevels zz;


        protected override void Initialize()
        {
            zz = Indicators.GetIndicator<ZigZagAndFiboLevels>(Deviation, false, false, false);
        }

        public override void Calculate(int index)
        {
            int i = index;
            while (double.IsNaN(zz.Value[i]) && i > 0)
            {
                i--;
            }
            double A = zz.Value[i];
            i--;
            while (double.IsNaN(zz.Value[i]) && i > 0)
            {
                i--;
            }
            double B = zz.Value[i];
            sign[index] = A < B ? B - (1 - per / 100) * (B - A) : A > B ? A - per / 100 * (A - B) : double.NaN;
            down[index] = A < B ? B - (1 - per / 100) * (B - A) : double.NaN;
            up[index] = A > B ? A - per / 100 * (A - B) : double.NaN;

        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: 61.8 Retracement.algo
  • Rating: 0
  • Installs: 6697
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.