Author: Kalenzo
KI

This script functions as a custom technical analysis tool designed to identify momentum shifts and trend reversals by measuring the relationship between different moving averages. Instead of looking at price action directly, it analyzes the "gap" or difference between trends to provide clearer visual signals.

Core Logic Overview

The indicator operates through three distinct layers of calculation:

1. The Difference Calculation (The Histogram) The tool begins by comparing two different Exponential Moving Averages (EMAs). One is set to a very short duration (3 periods) and the other to a slightly longer duration (10 periods). By subtracting the 10-period average from the 3-period average, the script creates a "Difference" value. This represents the immediate momentum of the market; when this difference is positive, it suggests upward pressure, and when negative, it suggests downward pressure.

2. The Smoothing Layer (The Moving Average of Difference) To prevent the data from being too "noisy" or jumpy—which can often lead to false signals in fast-moving markets—the script then takes that "Difference" value and applies a third moving average over it (set to 16 periods). This creates a smoothed line that reveals the underlying trend of the momentum rather than just the raw fluctuations.

3. The Signal Generation (Buy and Sell Triggers) The final logic of the script is designed to pinpoint the exact moment the momentum flips. It monitors the smoothed line for "zero-crossings":

  • Upward Signal: If the smoothed line was previously below zero and crosses above it, the script identifies this as a bullish shift.
  • Downward Signal: If the smoothed line was previously above zero and crosses below it, the script identifies this as a bearish shift.

Visual Representation

When applied to a chart, the tool provides three main visual elements:

  • A Histogram representing the raw difference between the short and medium trends.
  • A Dotted Line representing the smoothed average of that difference.
  • Directional Arrows that appear on the chart to highlight the specific moments where the momentum shifts from positive to negative (or vice versa), acting as visual alerts for potential trend changes.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
KI

//+------------------------------------------------------------------+
//|                                                           KI.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 SteelBlue
#property indicator_color2 Orange
#property indicator_color3 DodgerBlue
#property indicator_color4 Magenta

#property indicator_level1 0

extern int Length1 = 3;
extern int Length2 = 10;
extern int Length3 = 16;
 

double Histo[];
double MaHisto[];

double up[];
double dn[]; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- additional buffers are used for counting
   IndicatorBuffers(4);

   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT,1);
   SetIndexStyle(2,DRAW_ARROW,EMPTY,0);
   SetIndexStyle(3,DRAW_ARROW,EMPTY,0);
   
   SetIndexArrow(2,108);
   SetIndexArrow(3,108);
   
   IndicatorDigits(6);

   SetIndexBuffer(0,Histo);
   SetIndexBuffer(1,MaHisto);
   SetIndexBuffer(2,up);
   SetIndexBuffer(3,dn);

   IndicatorShortName("KI");
   
   SetIndexLabel(0,"3/10 Diffrence");
   SetIndexLabel(1,"Moving Average of Diffrence");
   SetIndexLabel(2,"UP SIGNAL");
   SetIndexLabel(3,"DN SIGNAL");
   
   
   
   return(0);
  }
//+------------------------------------------------------------------+
//| SignalIndicator                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) counted_bars=0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//----
      
   for(int i = 0 ;i <= limit ;i++)Histo[i] = iMA(Symbol(),0,Length1,0,MODE_EMA,PRICE_CLOSE,i) - iMA(Symbol(),0,Length2,0,MODE_EMA,PRICE_CLOSE,i);      
   
   for(int j = 0 ;j <= limit ;j++)MaHisto[j] = iMAOnArray(Histo,0,Length3,0,MODE_EMA,j);
   
   for(int m = 0 ;m <= limit ;m++)
   {
      if(MaHisto[m+1] <= 0 && MaHisto[m]>0)
      {
         up[m] = 0;
      }
      
      if(MaHisto[m+1] >= 0 && MaHisto[m]<0)
      {
         dn[m] = 0;
      }
   }
//----
 return(0);
  }
//+------------------------------------------------------------------+

Comments