MA-Heikin

This indicator is designed to provide a visual guide for identifying trend direction and potential price shifts on your trading charts. It works by smoothing out market noise to highlight the underlying momentum of the asset.

How the Logic Works

1. Price Data Smoothing The script begins by calculating a specific average price point for each candle. Instead of relying solely on the current price, it blends the opening, closing, high, and low values of the current candle with those of the two preceding candles. This creates a "normalized" price point that is less sensitive to sudden, erratic spikes and more representative of the actual price action over a short period.

2. Trend Identification (Moving Average) Once these smoothed price points are established, the script applies a Moving Average calculation to them based on a user-defined period. This step creates a continuous line that represents the "path" of the market's momentum. By analyzing this path, the tool can distinguish between upward trends, downward trends, and periods where the price is moving sideways (flat).

3. Visual Signals The indicator then translates these mathematical movements into three distinct visual lines on your chart:

  • Upward Momentum: When the current smoothed average is higher than the previous one, the script highlights the upward movement.
  • Downward Momentum: When the current smoothed average is lower than the previous one, it highlights the downward movement.
  • Neutral/Stable Zones: If the average price remains unchanged between calculations, the indicator recognizes a lack of clear momentum and suppresses the signals accordingly.

Summary for Traders

In simple terms, this tool acts as a trend filter. It ignores minor "hiccups" in price action by averaging out the data from multiple candles at once. By showing you clearly where the momentum is tilting up or down, it helps you visualize whether the current market cycle is leaning toward a bullish or bearish direction, making it easier to spot shifts in the trend as they happen.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
18 Views
0 Downloads
0 Favorites
MA-Heikin

//----
#property  indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_style1 STYLE_SOLID
#property indicator_color2 Yellow
#property indicator_style2 STYLE_SOLID
#property indicator_color3 Aqua
#property indicator_style3 STYLE_SOLID
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  2



//---- input parameters
extern int MA_Period = 8;
extern int MA_method = 1;

//---- buffers


double mahup[];
double mahdown[];
double maheven[];
double Hp[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   IndicatorBuffers(4);
   SetIndexBuffer(3, Hp);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, mahdown);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, mahup);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, maheven);



   return(0);
  }
//+------------------------------------------------------------------+
//|                                          |
//+------------------------------------------------------------------+
int start()
  {
   int i;
   double mahp , mahpre;
   int limit;
   int counted_bars=IndicatorCounted();
   
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(i=0; i < limit; i++)
   {
    Hp[i] = ((Open[i+2] + Close[i+2] + Open[i+1] + Close[i+1])/4 +
              (Open[i] + Close[i] + High[i] + Low[i])/4)/2;
    
   }
   for(i=0; i < limit; i++)
   {
    mahp = iMAOnArray(Hp,0,MA_Period,0,MA_method,i);
    mahpre = iMAOnArray(Hp,0,MA_Period,0,MA_method,i+1);
    
       mahup[i] = mahp; 
       mahdown[i] = mahp; 
       maheven[i] = mahp;
       
        if (mahpre > mahp)
        {
        mahup[i] = EMPTY_VALUE;
        
        }
       else if (mahpre < mahp) 
        {
        mahdown[i] = EMPTY_VALUE; 
        
        }
         else 
         {
         
         mahup[i]=EMPTY_VALUE;
         mahdown[i]=EMPTY_VALUE;
         }
   }



   return(0);
  }
//+------------------------------------------------------------------+

Comments