Partial KijunSen

Created at 22 Oct 2020, 23:59
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!
M.

m.mohammadreza.m.s

Joined 22.10.2020 Blocked

Partial KijunSen
22 Oct 2020, 23:59


hey

Im trying to write an indicator to predict kijun sen for some candles ahead

but i only need the data for ahead of live candle

ive written this code but it doesn't show any results

this is incomplete yet,but i expect it to show 1 point ahead of current kijun Sen

thank you in advance

/*
==================================================================================
==================================================================================
                          ichimoku shift
  Copyright © 2020, MRM
  Developer: MRM
  
==================================================================================
==================================================================================
with this indicator you can shift ichimoku forward or backward


*/

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

namespace cAlgo.Indicators
{
    [Cloud("SenkouSpanA", "SenkouSpanB")]

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class ICHIP : Indicator
    {
        [Parameter(DefaultValue = 9, Group = "Periods")]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26, Group = "Periods")]
        public int periodMedium { get; set; }

        [Parameter(DefaultValue = 52, Group = "Periods")]
        public int periodSlow { get; set; }



        [Parameter(DefaultValue = -26, Group = "Displacements")]
        public int DisplacementChikou { get; set; }

        [Parameter(DefaultValue = 26, Group = "Displacements")]
        public int DisplacementCurrentCloud { get; set; }



        [Parameter(DefaultValue = 0, Group = "Displacements")]
        public int Shift { get; set; }



        [Parameter(DefaultValue = -16, Group = "Displacements")]
        public int KPredictionShift { get; set; }

        [Parameter(DefaultValue = 1, Group = "PeriodShown")]
        public int PredictionPeriodShown { get; set; }


        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }
        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }
        [Output("ChikouSpan", Color = Colors.DarkViolet)]
        public IndicatorDataSeries ChikouSpan { get; set; }
        [Output("SenkouSpanB", Color = Colors.Red)]
        public IndicatorDataSeries SenkouSpanB { get; set; }
        [Output("SenkouSpanA", Color = Colors.Green)]
        public IndicatorDataSeries SenkouSpanA { get; set; }


        [Output("KPrediction1", Color = Colors.DarkViolet, PlotType = PlotType.Points)]
        public IndicatorDataSeries KPrediction1 { get; set; }


        double maxfast, minfast, maxmedium, minmedium, maxslow, minslow, pmaxmedium1, pminmedium1;

        public override void Calculate(int index)
        {
            if ((index < periodFast) || (index < PeriodSlow))
            {
                return;
            }

            maxfast = MarketSeries.High[index];
            minfast = MarketSeries.Low[index];
            maxmedium = MarketSeries.High[index];
            minmedium = MarketSeries.Low[index];
            maxslow = MarketSeries.High[index];
            minslow = MarketSeries.Low[index];

            pmaxmedium1 = MarketSeries.High[index];
            pminmedium1 = MarketSeries.Low[index];

            for (int i = 0; i < periodFast; i++)
            {
                if (maxfast < MarketSeries.High[index - i])
                {
                    maxfast = MarketSeries.High[index - i];
                }
                if (minfast > MarketSeries.Low[index - i])
                {
                    minfast = MarketSeries.Low[index - i];
                }
            }
            for (int i = 0; i < periodMedium; i++)
            {
                if (maxmedium < MarketSeries.High[index - i])
                {
                    maxmedium = MarketSeries.High[index - i];
                }
                if (minmedium > MarketSeries.Low[index - i])
                {
                    minmedium = MarketSeries.Low[index - i];
                }
            }
            for (int i = 0; i < periodSlow; i++)
            {
                if (maxslow < MarketSeries.High[index - i])
                {
                    maxslow = MarketSeries.High[index - i];
                }
                if (minslow > MarketSeries.Low[index - i])
                {
                    minslow = MarketSeries.Low[index - i];
                }
            }




            for (int i = 0; i < (periodMedium - 1); i++)
            {
                if (pmaxmedium1 < MarketSeries.High[index - i])
                {
                    pmaxmedium1 = MarketSeries.High[index - i];
                }
                if (pminmedium1 > MarketSeries.Low[index - i])
                {
                    pminmedium1 = MarketSeries.Low[index - i];
                }
            }


            TenkanSen[index + Shift] = ((maxfast + minfast) / 2);
            KijunSen[index + Shift] = ((maxmedium + minmedium) / 2);
            ChikouSpan[index + DisplacementChikou + Shift] = MarketSeries.Close[index];
            SenkouSpanA[index + DisplacementCurrentCloud + Shift] = (((maxfast + minfast) / 2 + (maxmedium + minmedium) / 2) / 2);
            SenkouSpanB[index + DisplacementCurrentCloud + Shift] = ((maxslow + minslow) / 2);


            if (index == 0)
            {
                KPrediction1[index + KPredictionShift] = (pmaxmedium1 + pminmedium1) / 2;
            }
            else
            {
                KPrediction1[index + KPredictionShift] = double.NaN;
            }
        }
    }
}