Kijun-sen+_v1
Download scriptThis script is designed to provide traders with a visual tool called the Kijun-sen, which is a core component of the popular Ichimoku Kinko Hyo technical analysis system. Its primary purpose is to help identify the medium-term trend of a financial market by smoothing out daily price fluctuations and highlighting significant price levels.
How the Logic Works
The script functions by calculating a "median" price over a specific period of time. Instead of simply looking at the current price, it looks backward at a set window of past candles (defined by the user as 26 periods by default).
1. Identifying Extremes For every point on the chart, the logic scans through the designated number of previous bars to find two specific pieces of data:
- The highest high reached during that timeframe.
- The lowest low reached during that timeframe.
2. Calculating the Midpoint Once the highest and lowest points are identified, the script calculates the halfway point between them. This average represents the "equilibrium" or the central balance of the price action for that period.
3. Visual Representation The script then plots this midpoint as a continuous line on your chart. Because it is based on these extremes rather than just closing prices, the line moves smoothly across the screen. It acts as a dynamic support and resistance level:
- When the price is above the line, it often suggests a bullish (upward) trend.
- When the price is below the line, it often suggests a bearish (downward) trend.
Key Customizations
The script includes two primary settings that allow you to tailor the logic to your specific trading style:
- Kijun Period: This allows you to change how far back the script looks to find highs and lows (the default is 26 bars).
- Shift: This provides a visual offset, moving the line forward or backward on the chart to help align the data with your specific analysis needs.
In essence, this tool filters out "market noise" by focusing on the core range of price movement, providing you with a clearer picture of where the market's momentum is currently sitting.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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[];
//----
int a_begin;
//+------------------------------------------------------------------+
//| 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