Author: Copyright � Roman Shiredchenko, 2009
impuls

This technical tool is designed to analyze market momentum by monitoring two specific types of moving averages simultaneously. It processes historical price data to identify whether the current trend is gaining strength, losing steam, or remaining neutral, and visualizes these insights through a color-coded histogram in a separate window on your trading platform.

How the Logic Works

The script functions by calculating the "velocity" of two different indicators: an Exponential Moving Average (EMA) and a Moving Average Convergence Divergence (MACD). Instead of looking at the raw values of these indicators, the logic focuses on their movement between the current price candle and the previous one.

1. Momentum Calculation For every historical bar, the script determines the direction of change:

  • EMA Change: It compares the current EMA value to the previous one. If the current value is higher, it indicates upward momentum; if lower, it indicates downward momentum.
  • MACD Change: It performs the same comparison on the MACD indicator to confirm whether the broader trend is accelerating or decelerating.

2. Visual Signal Logic (Color Coding) The script then compares the results of these two calculations to decide which color to display on the histogram:

  • Green Signal (Bullish Momentum): If both the EMA and the MACD are increasing simultaneously, the histogram highlights in Green. This suggests a synchronized upward push in the market.
  • Red Signal (Bearish Momentum): If both the EMA and the MACD are decreasing simultaneously, the histogram highlights in Red. This suggests a synchronized downward move in the market.
  • Gray Signal (Neutral/Mixed Momentum): If the indicators do not show a synchronized move (for example, if one is going up while the other is going down, or if they are flat), the histogram displays as Gray. This indicates a lack of clear, unified momentum and suggests a period of indecision or conflicting signals.

Summary for Traders

By using this logic, the indicator filters out "noisy" price action where indicators might disagree. It only highlights strong, confirmed trends in Green or Red, while leaving you aware of neutral market conditions in Gray, allowing for a cleaner visual assessment of market impulse.

Indicators Used
Moving average indicatorMACD Histogram
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
impuls
//--------------------------------------------------------------------
// impuls.mq4 
//--------------------------------------------------------------- 1 --
#property copyright "Copyright © Roman Shiredchenko, 2009"
//--------------------------------------------------------------------
#property indicator_separate_window     // èíäèêàòîð ðèñóåòñÿ â îòäåëüíîì îêíå

#property  indicator_buffers 3          // êîë-âî áóôåðîâ äëÿ ðàñ÷åòà èíäèêàòîðà     
#property  indicator_color1  Gray       // çàïðåò íà ïðîäàæó ëèáî ïîêóïêó ñíÿò
#property  indicator_color2  Green      // çàïðåò íà èãðó íà ïîíèæåíèå 
#property  indicator_color3  Red        //  çàïðåò íà èãðó íà ïîâûøåíèå

//---- indicator parameters 
extern int History    =5000;            // êîë-âî áàðîâ ðàñ÷åòíîé èñòîðèè       
extern int Period_Ema=13;               // ïåðèîä ðàñ÷åòíîé åìà

extern int Period_Macd1=12;             // ïàðàìåòðû ðàñ÷åòà ìàñäè 
extern int Period_Macd2=26;
extern int Period_Macd3=9;
 
 
 
 
double     ExtBuffer0[];                // îïðåäåëåíèå ìàññèâîâ äëÿ èíäèêàòîðà - ãèñòîãðàììû
double     ExtBuffer1[];
double     ExtBuffer2[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 

   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);

   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);

   IndicatorShortName("impuls");
//---- initialization done
   return(0);
  } 
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 
//---- TODO: add your code here 
    
//---- 
   return(0); 
  } 
//----------------------------------------------------------------

int start()                         // Ñïåöèàëüíàÿ ôóíêöèÿ start()
  {
//-----------------------------------------------------------------
  
   double
   EMA1,  EMA2, SumEMA;                  // 2 ÌÀ äëÿ ðàñ÷åòà çíà÷åíèé èíäèêàòîðà EMA
   double
   M_0, M_1, SumMacd ;                           // Çíà÷åíèå MAIN MACD íà 0 è 1 áàðàõ
   
//--------------------------------------------------------------- 4 --
                      
                             
   int
   i,                            // Èíäåêñ áàðà
   n,                            // Ôîðìàëüí. ïàðàìåòð(èíäåêñ áàðà)
   Counted_bars;                 // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 

//-------------------------------------------------------------- 10 --
   Counted_bars=IndicatorCounted(); // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 
   i=Bars-Counted_bars-1;           // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
   if (i>History-1)                 // Åñëè ìíîãî áàðîâ òî ..
      i=History-1;                  // ..ðàññ÷èòûâàòü çàäàííîå êîëè÷.
//-------------------------------------------------------------- 11 --
      ExtBuffer1[i] = 0;            // îáíóëåíèå çíà÷åíèé ìàññèâîâ ëèíèé èíäèêàòîðà
      ExtBuffer2[i] = 0;
      ExtBuffer0[i] = 0;
   while(i>=0)                      // Öèêë ïî íåïîñ÷èòàííûì áàðàì
     {
      //-------------------------------------------------------- 12 --
        
      EMA1=iMA(NULL,0,Period_Ema,0,MODE_EMA,PRICE_CLOSE,i); // Çíà÷åíèå  EÌÀ1 current
      EMA2=iMA(NULL,0,Period_Ema,0,MODE_EMA,PRICE_CLOSE,i+1); // Çíà÷åíèå  EÌÀ2  prev 
      SumEMA = 0;
      SumEMA = EMA1 - EMA2;          // âû÷èñëåíèå ðàçíîñòè åìà íà òåê. è ïðåäûäóùåì áàðàõ
           
      M_0=iMACD(NULL,0,Period_Macd1,Period_Macd2,Period_Macd3,PRICE_CLOSE,MODE_MAIN,i); // 
      M_1=iMACD(NULL,0,Period_Macd1,Period_Macd2,Period_Macd3,PRICE_CLOSE,MODE_MAIN,i+1); // 
      SumMacd=M_0-M_1;               // òîæå ñàìîå äëÿ ìàêäà
      
      ExtBuffer1[i] = 0;
      ExtBuffer2[i] = 0;
      ExtBuffer0[i] = 0;
      
       
      if (SumEMA>0 && SumMacd>0) ExtBuffer1[i] = 4; // åñëè è åìà è ìàñäè ðàñòóò, òî ðèñóé çåëåíóþ ëèíèþ ãèñòîãðàììû ðàâíóþ 4
      if (SumEMA<0 && SumMacd<0)      // åñëè åìà è ìàêäè óìåíüøàþòñÿ, òî ðèñóé êðàñíóþ ëèí ãèñòîãðàììû ðàâíóþ 2 
       { ExtBuffer2[i] = 2;
       } else
        ExtBuffer0[i] = 3;            // èíà÷å ðèñóé ñåðóþ ëèíèþ ãèñòîãðàììû èíäèêàòîðà èìïóëüñ
        
             
      //-------------------------------------------------------- 13 --
      i--;                          // Ðàñ÷¸ò èíäåêñà ñëåäóþùåãî áàðà
      //-------------------------------------------------------- 14 --
     }
   return;                          // Âûõîä èç ñïåö. ô-èè start()
  }
//-------------------------------------------------------------- 15 --

Comments