NonLagHAMA T3 new Alert

Download script
Author: Copyright � 2008,Forex-TSD.com
NonLagHAMA T3 new Alert

This script is a specialized trading indicator designed to provide traders with a smoothed, high-quality visual representation of market trends. By blending two distinct types of mathematical filtering—Heiken Ashi logic and T3 Moving Averages—it aims to reduce "market noise" (the small, jagged price fluctuations that can often lead to false signals) while maintaining the responsiveness needed to capture a trend as it happens.

Core Logic and Components

The script operates through a three-stage process to interpret market data:

1. Advanced Moving Average Filtering

Instead of using standard moving averages, which can be slow to react or too erratic, this tool employs the T3 Moving Average. The T3 is known for its ability to balance smoothness and speed by applying a multi-layered mathematical formula. It looks at different price points (Open, Close, High, and Low) independently to ensure that the "base" trend it detects is robust and not skewed by single-bar outliers.

2. Heiken Ashi Transformation

Once the smoothed moving average data is captured, the script applies Heiken Ashi logic. This is a popular charting method used to visualize price action more clearly. It calculates synthetic "Open," "High," "Low," and "Close" values based on the filtered moving averages.

  • Trend Visualization: This creates candles (represented as histograms in this script) that stay consistently colored in one direction as long as the trend remains steady.
  • Volatility Smoothing: It ensures that the high and low boundaries of the bars reflect the underlying momentum rather than just extreme, temporary price spikes.

3. Signal Generation and Alerts

The final layer of the script identifies specific "turning points" in the market trend to provide actionable information for the trader:

  • Trend Reversals: The logic monitors the relationship between the synthetic Open and Close values. When the trend shifts from bullish (upward) to bearish (downward), or vice versa, the script identifies this transition point.
  • Visual Cues: The indicator places arrows on the chart to highlight these specific reversals.
  • Real-Time Notifications: If enabled, the script will trigger an automated alert (pop-up/sound) the moment a trend flip is detected. It includes "logic gates" to ensure you only get one alert per trend change, preventing repetitive notifications during a single sustained move.

Summary for the User

This tool essentially acts as a trend-following filter. It takes the raw, messy price of the market, smooths it out using advanced T3 mathematics, converts it into a cleaner Heiken Ashi style visual, and then watches that visual for significant shifts in momentum. It is designed to help you stay on the "right side" of a trend by filtering out minor movements and highlighting major directional changes.

Price Data Components
Series array that contains open time of each bar
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
NonLagHAMA T3 new Alert
//+------------------------------------------------------------------+
//|                                            Heiken Ashi Ma T3.mq4 |
//+------------------------------------------------------------------+
//|                                                      mod by Raff |
//|                                               2009 mod by mladen |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008,Forex-TSD.com"
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 RoyalBlue
#property indicator_color3 Red
#property indicator_color4 RoyalBlue
#property indicator_color5 Aqua
#property indicator_color6 Magenta
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 1
#property indicator_width6 1


extern int    NLMA_Length    = 9;   
extern int    NLMA_Displace  = 0;    
extern double NLMA_PctFilter = 0;
extern int    Step           = 1;
extern bool   BetterFormula  = true;
extern bool   T3Average      = true;
extern double T3Hot          = 0.70;
extern bool   T3Original     = false;
extern bool   Alerts         = true;

//
//
//
//
//

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double UpArrow[];
double DnArrow[];
//
//
//
//
//

double emas[][24];
double alpha;
double c1;
double c2;
double c3;
double c4;




static bool TurnedUp   = false;
static bool TurnedDown = false;
datetime    timeprev   = 0;

//+------------------------------------------------------------------+
//|                                                                  |
//|------------------------------------------------------------------|
//
//
//
//
//

int init()
{
   SetIndexBuffer(0, ExtMapBuffer1); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1, ExtMapBuffer2); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2, ExtMapBuffer3); SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(3, ExtMapBuffer4); SetIndexStyle(3,DRAW_HISTOGRAM);
   
   SetIndexBuffer(4, UpArrow); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,233);
   SetIndexBuffer(5, DnArrow); SetIndexStyle(5,DRAW_ARROW); SetIndexArrow(5,234);


   //
   //
   //
   //
   //
   
      double a  = T3Hot;
             c1 = -a*a*a;
             c2 =  3*(a*a+a*a*a);
             c3 = -3*(2*a*a+a+a*a*a);
             c4 = 1+3*a+a*a*a+3*a*a;

      NLMA_Length = MathMax(1,NLMA_Length);
      if (T3Original)
           alpha = 2.0/(1.0 + NLMA_Length);
      else alpha = 2.0/(2.0 + (NLMA_Length-1.0)/2.0);

   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int start()
{
   double maOpen, maClose, maLow, maHigh;
   double haOpen, haClose, haLow, haHigh;
   int    counted_bars=IndicatorCounted();
   int    pointModifier;
   int    i,limit;

   //
   //
   //
   //
   //
   if(timeprev<iTime(NULL,0,0)) {TurnedDown=false; TurnedUp=false;timeprev=iTime(NULL,0,0);}
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
         if (ArrayRange(emas,0) != Bars) ArrayResize(emas,Bars);
         if (Digits==3 || Digits==5)
               pointModifier = 10;
         else  pointModifier = 1;               
          
   //
   //
   //
   //
   //
   
   for(int pos=limit; pos >= 0; pos--)
   {
      if (T3Average)
         {
            maOpen  = iT3(Open[pos] ,pos, 0);
            maClose = iT3(Close[pos],pos, 6);
            maLow   = iT3(Low[pos]  ,pos,12);
            maHigh  = iT3(High[pos] ,pos,18);
         }
      else
         {
           maOpen  = iCustom(NULL,0,"NonLagMA_v7.1.1",PRICE_OPEN, NLMA_Length,NLMA_Displace,NLMA_PctFilter,1,0,pos);
           maClose = iCustom(NULL,0,"NonLagMA_v7.1.1",PRICE_CLOSE,NLMA_Length,NLMA_Displace,NLMA_PctFilter,1,0,pos);
           maLow   = iCustom(NULL,0,"NonLagMA_v7.1.1",PRICE_LOW,  NLMA_Length,NLMA_Displace,NLMA_PctFilter,1,0,pos);
           maHigh  = iCustom(NULL,0,"NonLagMA_v7.1.1",PRICE_HIGH, NLMA_Length,NLMA_Displace,NLMA_PctFilter,1,0,pos);
         }
   
      //
      //
      //
      //
      //
        
         if (BetterFormula) {
               if (maHigh!=maLow)
                     haClose = (maOpen+maClose)/2+(((maClose-maOpen)/(maHigh-maLow))*MathAbs((maClose-maOpen)/2));
               else  haClose = (maOpen+maClose)/2; }
         else        haClose = (maOpen+maHigh+maLow+maClose)/4;
                     haOpen   = (ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
                     haHigh   = MathMax(maHigh, MathMax(haOpen,haClose));
                     haLow    = MathMin(maLow,  MathMin(haOpen,haClose));

         if (haOpen<haClose) { ExtMapBuffer1[pos]=haLow;  ExtMapBuffer2[pos]=haHigh; } 
         else                { ExtMapBuffer1[pos]=haHigh; ExtMapBuffer2[pos]=haLow;  } 
                               ExtMapBuffer3[pos]=haOpen;
                               ExtMapBuffer4[pos]=haClose;
      
      //
      //
      //
      //
      //

      if (Step>0)
      {
         if( MathAbs(ExtMapBuffer1[pos]-ExtMapBuffer1[pos+1]) < Step*pointModifier*Point ) ExtMapBuffer1[pos]=ExtMapBuffer1[pos+1];
         if( MathAbs(ExtMapBuffer2[pos]-ExtMapBuffer2[pos+1]) < Step*pointModifier*Point ) ExtMapBuffer2[pos]=ExtMapBuffer2[pos+1];
         if( MathAbs(ExtMapBuffer3[pos]-ExtMapBuffer3[pos+1]) < Step*pointModifier*Point ) ExtMapBuffer3[pos]=ExtMapBuffer3[pos+1];
         if( MathAbs(ExtMapBuffer4[pos]-ExtMapBuffer4[pos+1]) < Step*pointModifier*Point ) ExtMapBuffer4[pos]=ExtMapBuffer4[pos+1];
         if (Alerts==true)
        {
         UpArrow[pos]=EMPTY_VALUE; DnArrow[pos]=EMPTY_VALUE;
         if (ExtMapBuffer3[pos]<ExtMapBuffer4[pos] && ExtMapBuffer4[pos+1]<ExtMapBuffer3[pos+1])
           {
            UpArrow[pos]=ExtMapBuffer4[pos+1]-iATR(NULL,0,20,i)/2.0;
            if (UpArrow[0]!=EMPTY_VALUE && TurnedUp==false)
              {
               Alert("HAMa  BUY:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
               TurnedDown=false;
               TurnedUp=true;
              }
           }
         if (ExtMapBuffer3[pos]>ExtMapBuffer4[pos] && ExtMapBuffer4[pos+1]>ExtMapBuffer3[pos+1])
           {
            DnArrow[pos]=ExtMapBuffer4[pos+1]+iATR(NULL,0,20,i)/2.0;
            if (DnArrow[0]!=EMPTY_VALUE && TurnedDown==false)
              {
               Alert("HAMa SELL:  ",Symbol()," - ",Period(),"  at  ", Close[0],"  -  ", TimeToStr(CurTime(),TIME_SECONDS));
               TurnedUp=false;
               TurnedDown=true;
              }
           }
         }
       }
      }
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

double iT3(double price,int shift,int buffer)
{
   int i = Bars-shift-1;
   if (i < 1)
      {
         emas[i][0+buffer] = price;
         emas[i][1+buffer] = price;
         emas[i][2+buffer] = price;
         emas[i][3+buffer] = price;
         emas[i][4+buffer] = price;
         emas[i][5+buffer] = price;
      }
   else
      {
         emas[i][0+buffer] = emas[i-1][0+buffer]+alpha*(price            -emas[i-1][0+buffer]);
         emas[i][1+buffer] = emas[i-1][1+buffer]+alpha*(emas[i][0+buffer]-emas[i-1][1+buffer]);
         emas[i][2+buffer] = emas[i-1][2+buffer]+alpha*(emas[i][1+buffer]-emas[i-1][2+buffer]);
         emas[i][3+buffer] = emas[i-1][3+buffer]+alpha*(emas[i][2+buffer]-emas[i-1][3+buffer]);
         emas[i][4+buffer] = emas[i-1][4+buffer]+alpha*(emas[i][3+buffer]-emas[i-1][4+buffer]);
         emas[i][5+buffer] = emas[i-1][5+buffer]+alpha*(emas[i][4+buffer]-emas[i-1][5+buffer]);
      }
   return(c1*emas[i][5+buffer] + c2*emas[i][4+buffer] + c3*emas[i][3+buffer] + c4*emas[i][2+buffer]);
}

Comments