Correcting Fibo Pivot Point Indicator

Created at 08 Jul 2020, 13:26
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

MarkDawson

Joined 17.10.2019

Correcting Fibo Pivot Point Indicator
08 Jul 2020, 13:26


I'm adapting the indicator from this thread

So far, everything is ok except that I cannot get the indicator value on Monday. Not sure where I went wrong. I followed the suggestion in the previous thread and converted the code to newer object and changed yesterday parameter to include  yesterday = DateTime.Now.AddDays(-3);

Have a feeling I went wrong trying to calculate the high and low of previous day when it's a Monday. Should be the later end of the code below is wrong.

// Calculate High & Low of previous day

if((currentOpenTime.Day == yesterday.Day && today.DayOfWeek != DayOfWeek.Monday) || (today.DayOfWeek == DayOfWeek.Monday && currentOpenTime.DayOfYear == today.AddDays(-3).Day))

using System;
using cAlgo.API;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.SingaporeStandardTime, AutoRescale = false, AccessRights = AccessRights.None)]
    public class FiboPivotPointsIntraDay : Indicator
    {
        private double _close;
        private double _higher;
        private double _lower;

        #region Output

        [Output("Pivot", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries Pivot { get; set; }

        [Output("R1", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries R1 { get; set; }

        [Output("R2", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries R2 { get; set; }

        [Output("R3", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries R3 { get; set; }

        [Output("R4", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries R4 { get; set; }

        [Output("R5", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries R5 { get; set; }


        [Output("S1", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries S1 { get; set; }

        [Output("S2", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries S2 { get; set; }

        [Output("S3", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries S3 { get; set; }

        [Output("S4", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries S4 { get; set; }

        [Output("S5", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries S5 { get; set; }





        #endregion

        #region Input Parameters

        [Parameter("Number of Pivots", DefaultValue = 3, MinValue = 1, MaxValue = 5)]
        public int NoPiv { get; set; }

        [Parameter("DrawingWidth", DefaultValue = 50, MaxValue = 100)]
        public int DrawingWidth { get; set; }

        #endregion

        public override void Calculate(int index)
        {
            DateTime currentOpenTime = Bars.OpenTimes[index];
            DateTime previousOpenTime = Bars.OpenTimes[index - 1];
            DateTime today = DateTime.Now;
            DateTime yesterday;
            if (today.DayOfWeek == DayOfWeek.Monday)
                yesterday = DateTime.Now.AddDays(-3);
            else
                yesterday = DateTime.Now.AddDays(-1);

            // Initialize High & Low
            if (currentOpenTime.Day == yesterday.Day && previousOpenTime.Day != yesterday.Day)
            {
                _higher = Bars.HighPrices[index];
                _lower = Bars.LowPrices[index];
            }

            // Calculate High & Low of previous day
            if ((currentOpenTime.Day == yesterday.Day && today.DayOfWeek != DayOfWeek.Monday) || (today.DayOfWeek == DayOfWeek.Monday && currentOpenTime.DayOfYear == today.AddDays(-3).Day))
            {
                if (Bars.HighPrices[index] > _higher)
                {
                    _higher = Bars.HighPrices[index];
                }
                if (Bars.LowPrices[index] < _lower)
                {
                    _lower = Bars.LowPrices[index];
                }
            }

            // Set Close of previous day - Close of Last Bar of prevous Day
            if (previousOpenTime.Day == yesterday.Day && currentOpenTime.Day == today.Day)
            {
                _close = Bars.ClosePrices[index - 1];
            }

            // Only show output in todays timeframe
            if (currentOpenTime.Date != today.Date)
                return;

            // Calculate output
            Pivot[index] = (_higher + _lower + _close) / 3;

            R1[index] = Pivot[index] + (0.382 * (_higher - _lower));
            S1[index] = Pivot[index] - (0.382 * (_higher - _lower));

 


@MarkDawson
Replies

PanagiotisCharalampous
09 Jul 2020, 08:20

Hi Mark,

The code does not seem complete. Can you please provide the complete cBot code?

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous