Author: Copyright � 2009, LeMan
KRI

This technical indicator, known as the KRI (Kocho Relative Index), is designed to help traders visualize the relationship between the current market price and its average historical movement over a specific period. By analyzing this "gap," the tool provides a clearer picture of whether an asset is trading significantly above or below its typical trend.

How the Logic Works

The core functionality of the script revolves around three main steps:

1. Establishing a Baseline (Moving Average) The indicator first calculates a Simple Moving Average (SMA). Think of this as the "fair value" or the baseline of the market over a user-defined timeframe (the Period). By looking at a set number of previous closing prices, it determines what the average price has been recently.

2. Calculating the Variance Once the baseline is established, the script compares the current market price to that moving average. It measures the distance between where the price actually sits right now and where the "average" says it should be.

3. Converting to a Percentage Scale Instead of simply showing you a raw price difference (which can vary wildly between different assets like gold, forex, or stocks), the script converts this variance into a percentage. It takes the difference, divides it by the moving average, and multiplies it by 100. This creates a standardized percentage value that tells you exactly how far the price has deviated from its norm.

What This Means for the User

The result is displayed as a red line in a separate window at the bottom of your trading chart.

  • When the line is above zero: It indicates that the current market price is trading higher than its historical average, suggesting upward momentum or an "overbought" state.
  • When the line is below zero: It indicates that the current market price is trading lower than its historical average, suggesting downward pressure or an "oversold" state.

By adjusting the KRIPeriod setting, users can choose to make the indicator more sensitive (looking at a shorter window of time) or smoother (looking at a longer window of time) depending on their specific trading style.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
KRI
//+------------------------------------------------------------------+
//|                                                          KRI.mq4 |
//|                                         Copyright © 2009, LeMan. |
//|                                                 b-market@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, LeMan"
#property link      "b-market@mail.ru"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- Âõîäíûå ïàðàìåòðû
extern int KRIPeriod = 13;
//---- Áóôåðû
double KRIBuffer[];
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè                                            |
//+------------------------------------------------------------------+
int init() {
   string short_name;
//---- Ëèíèè èíäèêàòîðà
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, KRIBuffer);
//---- Íàäïèñè â îêíå
   short_name = "KRI ("+KRIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   SetIndexDrawBegin(0, KRIPeriod);
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Ìåòîä Êàèðè                                                      |
//+------------------------------------------------------------------+
int start() {
   int i, counted_bars=IndicatorCounted();
//----
   if (Bars <= KRIPeriod) return(0);
//---- initial zero
   if (counted_bars < 1)
      for (i = 1; i <= KRIPeriod; i++) KRIBuffer[Bars-i] = 0.0;
//----
   i = Bars-KRIPeriod-1;
   if (counted_bars >= KRIPeriod) i = Bars-counted_bars-1;
   while(i >= 0) {
      double ma = iMA(NULL,0,KRIPeriod,0,MODE_SMA,PRICE_CLOSE,i);
      KRIBuffer[i] = ((Close[i]-ma)/ma)*100;
      i--;
   }
   return(0);
}
//+------------------------------------------------------------------+

Comments