Kijun-sen+_v2

Download script
Author: Copyright � 2004, AlexSilver
Kijun-sen+_v2

This script is designed for the MetaTrader platform to display a specific technical analysis tool known as the Kijun-sen, which is a core component of the Ichimoku Kinko Hyo trading system. Its primary purpose is to help traders identify long-term momentum and equilibrium levels in a financial market.

How the Logic Works

The indicator calculates a baseline by looking at a specific window of historical price data—defined by the "Kijun" parameter (set to 26 periods by default). Instead of using a simple average of every closing price, it identifies the extreme boundaries of the market within that timeframe.

Here is the step-by-step breakdown of how it processes this information:

  • Identifying Extremes: For every period on your chart, the script scans back through the past 26 candles to find two specific values: the highest price reached and the lowest price reached during that interval.
  • Calculating the Equilibrium: Once it finds the absolute high and the absolute low for that timeframe, it calculates the midpoint (the average) of those two points. This midpoint represents the "base" or equilibrium level of the market for that period.
  • Visual Positioning (The Shift): The script includes a "Shift" feature. This allows the resulting line to be moved forward on the chart by a set number of candles (set to 3 by default). This is done to align the indicator with specific visual strategies used in Japanese technical analysis, helping traders see where the price was relative to the trend's baseline.
  • Dynamic Updates: The logic continuously recalculates as new price data enters the chart, ensuring that the line moves fluidly as new highs and lows are established.

Summary for Traders

In practical terms, this script draws a "median" line on your chart. When the market price is above this line, it generally suggests an upward trend; when it is below, it suggests a downward trend. Because it relies on the highest highs and lowest lows of a 26-period window rather than just closing prices, it is often more responsive to significant price swings than a standard moving average.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
Kijun-sen+_v2
//+------------------------------------------------------------------+
//|                                                    Kijun-sen.mq4 |
//|                                     Copyright © 2004, AlexSilver |
//|                                                  http://viac.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, AlexSilver"
#property link      "http://viac.ru/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
//---- input parameters
extern int Kijun=26;
extern int ShiftKijun=3;
//---- buffers
double Kijun_Buffer[];
//----
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Kijun_Buffer);
   SetIndexDrawBegin(0,Kijun+ShiftKijun-1);
   SetIndexShift(0,ShiftKijun);
   SetIndexLabel(0,"Kijun Sen+");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo Kijun-sen Only                                |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k;
   int    counted_bars=IndicatorCounted();
   double high,low,price;
//----
   if(Bars<=Kijun) return(0);
//---- initial zero
   if(counted_bars<1)
     {
      for(i=1;i<=Kijun;i++)     Kijun_Buffer[Bars-i]=0;
     }
//---- Kijun Sen
   i=Bars-Kijun;
   if(counted_bars>Kijun) i=Bars-counted_bars-1;
   while(i>=0)
     {
      high=High[i]; low=Low[i]; k=i-1+Kijun;
      while(k>=i)
        {
         price=High[k];
         if(high<price) high=price;
         price=Low[k];
         if(low>price) low=price;
         k--;
        }
      Kijun_Buffer[i+ShiftKijun]=(high+low)/2;
      i--;
     } i=ShiftKijun-1;
   while(i>=0)
     {
      high=High[0]; low=Low[0]; k=Kijun-ShiftKijun+i;
      while(k>=0)
        {
         price=High[k];
         if(high<price) high=price;
         price=Low[k];
         if(low>price) low=price;
         k--;
        }
      Kijun_Buffer[i]=(high+low)/2;
      i--;
     }
   }
//+------------------------------------------------------------------+

Comments