AA$-Hurst Displaced MA

Download script
Author: Copyright � 2008, MetaQuotes Software Corp.
AA$-Hurst Displaced MA

This tool is designed to help traders visualize market trends by projecting a specific type of moving average into the future. Instead of just showing you what the price has done in the past, it calculates a mathematical trajectory to help you see where the current momentum might be headed.

How the Logic Works

1. Data Smoothing (The Foundation) The script begins by calculating a Simple Moving Average (SMA). This smooths out the "noise" of daily price fluctuations to reveal the underlying trend. By using a specific period (set by the user), the tool identifies the core direction of the market rather than reacting to every minor price tick.

2. Time Shifting and Displacement A unique feature of this script is its ability to "shift" this average data. It takes the calculated moving average and offsets it in time. This creates a visual gap between historical data and the current price point, allowing the tool to isolate specific trends without cluttering the immediate price action.

3. Trendline Projection (The Forecasting Element) This is where the "Hurst" logic comes into play. The script identifies two specific points on the displaced moving average:

  • A starting point in the past.
  • A secondary point based on a user-defined sample size.

By measuring the change between these two points, the script calculates the exact angle and slope of the current trend. It then draws a dotted trendline that extends from that calculated path forward into the "empty" space on your chart.

4. Dynamic Updates The tool is designed to be reactive. Every time the market moves, the script clears out the previous projection and redraws the line based on the most recent data. This ensures that the projected line always reflects the most current momentum of the moving average.

Summary for the User

In simple terms, this indicator looks at the smoothed history of a price movement, identifies its current "slope," and draws a dotted line forward to show you the path the market is currently traveling. It acts as a visual guide to help you anticipate the direction of the trend based on recent momentum.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
AA$-Hurst Displaced MA
//+------------------------------------------------------------------+
//|                                          $AA-Hurst indicator.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window


#property indicator_buffers 1
#property indicator_color1 Yellow

//---- input parameters
extern int       dmaPeriod=199;
extern int       dmaPeriodShift = -99;
extern int   isRay = 0;
extern int samplePoint = 5;
extern color trendLineColor;

//---- buffers
double dmaBuffer[];
int dmaPeriodShifted;


int init()
  {
  dmaPeriodShifted = (-1 )* dmaPeriodShift;
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexBuffer(0,dmaBuffer);
   return(0);
  }

   

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
 
   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(int i=0; i<=limit; i++)
   {
      dmaBuffer[i+dmaPeriodShifted] = iMA(NULL,0,dmaPeriod,0,MODE_SMA,PRICE_CLOSE,i) ;

   }
      deleteAllObjects();
      double m = (dmaBuffer[dmaPeriodShifted] - dmaBuffer[dmaPeriodShifted+samplePoint])/(Time[dmaPeriodShifted] - Time[dmaPeriodShifted+samplePoint]);
      double c = dmaBuffer[dmaPeriodShifted]  - m * Time[dmaPeriodShifted];
      double y =  m*Time[0] + c;
      
      ObjectCreate("HurstDisplaced-" + dmaPeriod + dmaPeriodShift +"1",OBJ_TREND,0,Time[dmaPeriodShifted],dmaBuffer[dmaPeriodShifted] ,Time[0],y );
      ObjectSet("HurstDisplaced-" + dmaPeriod + dmaPeriodShift +"1",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("HurstDisplaced-" + dmaPeriod + dmaPeriodShift +"1",OBJPROP_COLOR, trendLineColor);
      ObjectSet("HurstDisplaced-" + dmaPeriod + dmaPeriodShift +"1",OBJPROP_RAY, isRay );

      
      
   return(0);
  }


int deinit()
{

   return (0);
}


void deleteAllObjects()
{
   int objs = ObjectsTotal();
   string name;
   for(int cnt=ObjectsTotal()-1;cnt>=0;cnt--)
   {
      name=ObjectName(cnt);
      if (StringFind(name,"HurstDisplaced-" + dmaPeriod + dmaPeriodShift,0)>-1) ObjectDelete(name);
      WindowRedraw();
   }
}

Comments