Author: Kalenzo
KI-Alert

This tool is designed as a momentum and trend-following indicator for the MetaTrader platform. It simplifies complex market movements into visual signals by analyzing the relationship between different price averages.

How the Logic Works

The script operates through three distinct layers of calculation to filter out "market noise" and identify clear turning points:

1. The Difference Calculation (Momentum) The core of the indicator starts by comparing two different Exponential Moving Averages (EMA). It looks at a very short-term price trend (3 periods) and subtracts a slightly longer-term trend (10 periods) from it. The result is plotted as a histogram.

  • When this difference is positive, it suggests short-term momentum is accelerating upward.
  • When the difference is negative, it suggests momentum is leaning downward.

2. The Smoothing Layer (Trend Confirmation) To prevent the indicator from reacting too quickly to minor price fluctuations, the script takes that "Difference" histogram and applies a third moving average over it (16 periods). This creates a smoother line that represents the underlying trend of the momentum itself. By doing this, the tool ignores small, insignificant "zigs and zags" and focuses on whether the overall momentum is genuinely shifting.

3. The Signal Generation (Buy & Sell Alerts) The final logic identifies specific "crossover" points where the smoothed momentum line crosses the zero level. These crossings act as your primary signals:

  • Up Signal: Triggered when the trend shifts from below zero to above zero.
  • Down Signal: Triggered when the trend shifts from above zero to below zero.

User Experience Features

  • Visual Aids: The tool provides a histogram for raw momentum, a dotted line for the smoothed average, and specific arrow markers on the chart to highlight exactly where the buy and sell signals occur.
  • Audio Notifications: To ensure you don't miss an entry point, the script includes an automated alert system that plays a sound file whenever a new signal is detected.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alerts
15 Views
0 Downloads
0 Favorites
KI-Alert

//+------------------------------------------------------------------+
//|                                                           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;
      }
   if(up[m]==0 || dn[m]==0)PlaySound("alert.wav");
   }
//----
   
 return(0);
  }
//+------------------------------------------------------------------+

Comments