Category Oscilators  Published on 19/02/2020

Kijunsen X3 Normalised

Description

I have used Kijun-Sen (Overlay version) for example as a baseline for different trading strategies. I wanted to take a different look at this very basic and simple indicator and see what else it could do...

I have combined 3 Kijunsen lines that are normalized as oscillators (normally Kijun-Sen line is drawn to the chart as an overlay indicator). I have also added moving average smoothing (MA period value 0 voids smoothing).

Original KijunSen uses 26 periods, I have chosen Fibonacci sequence numbers for the default periods.

My initial idea was to use this for mean reversion strategies looking for the faster lines to diverge from the slower lines. The oscillator can also be used during a trend trade to get in on a pullback (fast pulling away from slow, slow showing trend strength).

Let me know if you find new ideas about how to use this indicator. 

What is the Kijun-Sen (Japanese for Reference / Baseline)?

The Kijun-sen is an indicator and important component of the Ichimoku Kinko Hyo method of technical analysis, which is also known as the Ichimoku cloud.

The original Kijun-sen is the midpoint price of the last 26-periods, and therefore an indicator of short- to medium-term price momentum. The indicator aids in assessing the trend, and can also be useful for identifying trading opportunities when combined with the other components of the Ichimoku cloud.

How to Calculate the original Kijun Line (Base Line)

  1. Find the highest price over the last 26 periods.
  2. Find the lowest price over the last 26 periods.
  3. Combine the high and low, then divide by two.
  4. Update the calculation after each period ends.

                                                               

Version updates:
===========================

 2019/12/11

2020/2/20

  • Added  "Use Mean High/Low" & "Use Average" as a different way of calculating the normalisation.

Follow 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. There's also a Discord Server now @ https://discord.gg/5GAPMtp

 

 

=================================================================================

  Copyright © 2020, Fibonacci2011

  Developer: Fibonacci2011 // https://ctrader.com/users/profile/23066

  Telegram:  @Fibonacci2011

=================================================================================

 


/*
==================================================================================
==================================================================================
                          KijunSen3XNormalised
  Copyright © 2020, Fibonacci2011 
  Developer: Fibonacci2011 // https://ctrader.com/users/profile/23066
  Telegram:  @Fibonacci2011 
==================================================================================
==================================================================================


I have combined 3 Kijunsen lines that are normalized as oscillators (normally Kijun-Sen line is drawn to the chart as an overlay indicator). I have also added moving average smoothing (MA period value 0 voids smoothing).

Original KijunSen uses 26 periods, I have chosen Fibonacci sequence numbers for the default periods.

My initial idea was to use this for mean reversion strategies looking for the faster lines to diverge from the slower lines. The oscillator can also be used during a trend trade to get in on a pullback (fast pulling away from slow, slow showing trend strength).

Let me know if you find new ideas about how to use this indicator. 

What is the Kijun-Sen (Japanese for Reference / Baseline)?

The Kijun-sen is an indicator and important component of the Ichimoku Kinko Hyo method of technical analysis, which is also known as the Ichimoku cloud.

The original Kijun-sen is the midpoint price of the last 26-periods, and therefore an indicator of short- to medium-term price momentum. The indicator aids in assessing the trend, and can also be useful for identifying trading opportunities when combined with the other components of the Ichimoku cloud.

How to Calculate the original Kijun Line (Base Line)

Find the highest price over the last 26 periods.
Find the lowest price over the last 26 periods.
Combine the high and low, then divide by two.
Update the calculation after each period ends.


Version updated: 2019/11/27

Version updated: 2019/12/11

Used API Functions Maximum & Minimum https://ctrader.com/api/reference/functions instead of the FOR-loops to get  Market Series High & Low. Should result in much fewer calculations  by this indicator
I have used Kijun-Sen (Overlay version) as a baseline for different trading strategies. I wanted to take a different look at this very basic and simple indicator and see what else it could do...

Version updated: 2020/2/20

Added  "Use Mean High/Low" & "Use Average" as a different way of calculating the normalisation

*/

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class KijunSen3XNormalised : Indicator
    {


        [Parameter("Fibonacci:: ", Group = "Fibonacci sequence - !! reference only !! - ", DefaultValue = "5,8,13,21,34,55,89,144,233,377,610")]
        public string indicatorinfo { get; set; }

        [Parameter("1) Fast Period", Group = "--- KijunSen Period ---", DefaultValue = 13)]
        public int Period { get; set; }

        [Parameter("2) Medium Period", Group = "--- KijunSen Period ---", DefaultValue = 21)]
        public int Period2 { get; set; }

        [Parameter("3) Slow Period", Group = "--- KijunSen Period ---", DefaultValue = 55)]
        public int Period3 { get; set; }

        [Parameter("MA Period", Group = "--- MA Smoothing Period --- (0 = no smoothing)", DefaultValue = 10, MinValue = 1)]
        public int MAPeriod { get; set; }

        [Parameter("Use Mean High/Low", Group = "---  Normalisation Selector  --- ", DefaultValue = false)]
        public bool UseMedian { get; set; }

        [Parameter("Use Average", Group = "---  Normalisation Selector  --- ", DefaultValue = false)]
        public bool UseAverage { get; set; }

        [Parameter("Normal Levels", Group = "--- Levels ---", DefaultValue = 0.8, Step = 0.01)]
        public double Level1 { get; set; }

        [Parameter("Average Levels ", Group = "--- Levels ---", DefaultValue = 0.001, Step = 0.0001)]
        public double SwitchLevels { get; set; }

        [Parameter(" Read New Bars Only!", Group = "--- Resource Manager --- (calculate only on new bar!)", DefaultValue = true)]
        public bool ReadBars { get; set; }


        [Output(" Fast ", LineColor = "Red", Thickness = 2, LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries KijunSen1 { get; set; }

        [Output(" Medium ", LineColor = "Orange", Thickness = 2, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries KijunSen2 { get; set; }

        [Output(" Slow ", LineColor = "Aquamarine", Thickness = 2, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries KijunSen3 { get; set; }

        [Output("Overbought", LineColor = "Moccasin", LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries overbought { get; set; }

        [Output("Oversold", LineColor = "Moccasin", LineStyle = LineStyle.LinesDots)]
        public IndicatorDataSeries oversold { get; set; }

        [Output("MidLine", LineColor = "Mintcream", LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries midline { get; set; }

        private MovingAverage MA1;
        private MovingAverage MA2;
        private MovingAverage MA3;

        private MovingAverage _MA1;
        private MovingAverage _MA2;
        private MovingAverage _MA3;

        private IndicatorDataSeries Kijun1;
        private IndicatorDataSeries Kijun2;
        private IndicatorDataSeries Kijun3;

        private IndicatorDataSeries _Kijun1;
        private IndicatorDataSeries _Kijun2;
        private IndicatorDataSeries _Kijun3;


        int lastindex = 0;

        protected override void Initialize()
        {
            Kijun1 = CreateDataSeries();
            Kijun2 = CreateDataSeries();
            Kijun3 = CreateDataSeries();

            MA1 = Indicators.MovingAverage(Kijun1, MAPeriod, MovingAverageType.Simple);
            MA2 = Indicators.MovingAverage(Kijun2, MAPeriod, MovingAverageType.Simple);
            MA3 = Indicators.MovingAverage(Kijun3, MAPeriod, MovingAverageType.Simple);

            _Kijun1 = CreateDataSeries();
            _Kijun2 = CreateDataSeries();
            _Kijun3 = CreateDataSeries();

            _MA1 = Indicators.MovingAverage(_Kijun1, MAPeriod, MovingAverageType.Simple);
            _MA2 = Indicators.MovingAverage(_Kijun2, MAPeriod, MovingAverageType.Simple);
            _MA3 = Indicators.MovingAverage(_Kijun3, MAPeriod, MovingAverageType.Simple);
        }


        public override void Calculate(int index)
        {
            if (index < Period || index < Period2 || index < Period3)
            {
                return;
            }

            if (ReadBars)
            {
                if (IsLastBar)
                {
                    if (index != lastindex)
                        lastindex = index;
                    else
                        return;
                }
            }

            double fastsum = 0;
            double mediumsum = 0;
            double slowsum = 0;
            double factor = 1;

            var FastMaxHigh = MarketSeries.High.Maximum(Period);
            var FastMinLow = MarketSeries.Low.Minimum(Period);
            var MediumMaxHigh = MarketSeries.High.Maximum(Period2);
            var MediumMinLow = MarketSeries.Low.Minimum(Period2);
            var SlowMaxHigh = MarketSeries.High.Maximum(Period3);
            var SlowMinLow = MarketSeries.Low.Minimum(Period3);

            var FastMedian = MarketSeries.Low.Sum(Period) / Period;
            var MediumMedian = MarketSeries.Low.Sum(Period2) / Period2;
            var SlowMedian = MarketSeries.Low.Sum(Period3) / Period3;

            var close = MarketSeries.Close[index];
            var close2 = MarketSeries.Close[index];
            var close3 = MarketSeries.Close[index];



            if (UseAverage)
            {

                Kijun1[index] = (FastMaxHigh + FastMinLow) / 2;
                Kijun2[index] = (MediumMaxHigh + MediumMinLow) / 2;
                Kijun3[index] = (SlowMaxHigh + SlowMinLow) / 2;


                for (var i = 1; i <= Period; i++)
                {

                    fastsum += Kijun1[index] - Kijun1[index - i];
                    mediumsum += Kijun2[index] - Kijun2[index - i];
                    slowsum += Kijun3[index] - Kijun3[index - i];
                }

                _Kijun1[index] = (fastsum / Period) * factor;
                _Kijun2[index] = (mediumsum / Period2) * factor;
                _Kijun3[index] = (slowsum / Period3) * factor;

                KijunSen1[index] = _MA1.Result[index];
                KijunSen2[index] = _MA2.Result[index];
                KijunSen3[index] = _MA3.Result[index];

            }

            else
            {

                if (!UseMedian)
                {
                    Kijun1[index] = (close - FastMinLow) / (FastMaxHigh - FastMinLow);
                    Kijun2[index] = (close2 - MediumMinLow) / (MediumMaxHigh - MediumMinLow);
                    Kijun3[index] = (close3 - SlowMinLow) / (SlowMaxHigh - SlowMinLow);
                }
                else
                {
                    Kijun1[index] = (close - FastMedian) / (FastMaxHigh - FastMinLow);
                    Kijun2[index] = (close2 - MediumMedian) / (MediumMaxHigh - MediumMinLow);
                    Kijun3[index] = (close3 - SlowMedian) / (SlowMaxHigh - SlowMinLow);
                }

                KijunSen1[index] = MA1.Result[index];
                KijunSen2[index] = MA2.Result[index];
                KijunSen3[index] = MA3.Result[index];
            }


            if (!UseAverage)
            {
                overbought[index] = Level1;
                oversold[index] = 1 - Level1;
                midline[index] = 0.5;
            }
            else
            {
                overbought[index] = SwitchLevels;
                oversold[index] = -SwitchLevels;
                midline[index] = 0;
            }

        }

    }
}

/*

Old method counting MarketSeries Max & Min values for the Kijunsen period:


            for (int i = 0; i < Period; i++)
            {
                if (maxmedium < MarketSeries.High[index - i])
                {
                    maxmedium = MarketSeries.High[index - i];
                }
                if (minmedium > MarketSeries.Low[index - i])
                {
                    minmedium = MarketSeries.Low[index - i];
                }
            }
...


                Kijun1[index] = (close - minmedium) / (maxmedium - minmedium);
                Kijun2[index] = (close2 - minmedium2) / (maxmedium2 - minmedium2);
                Kijun3[index] = (close3 - minmedium3) / (maxmedium3 - minmedium3);

*/



jani's avatar
jani

Joined on 05.04.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: KijunSen 3X Normalised.algo
  • Rating: 5
  • Installs: 2543
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
DY
dynamites · 5 years ago

Very nice indicator. If I can give you a suggestion, I would add an alert when the values are above/below the extremes...It would be really a time saver...