TD_moving_average_I

Download script
Author: mladen
TD_moving_average_I

This tool is designed to help traders identify specific price trends by analyzing the frequency of high and low points within a certain timeframe. Instead of showing every single price movement, it filters out market "noise" to highlight significant structural shifts in the market.

How the Logic Works

The script operates through three main stages:

1. Identifying Peak Frequency The tool looks at a specific window of time (the HighsLowsPeriod) to track how often new highs and lows are being formed. It essentially keeps a running count of these peaks. If the market is moving steadily, this count remains low; however, if the price starts hitting many new highs or lows in rapid succession, the counter increases.

2. Filtering for Market Stability (The "Gap" Logic) This is the core of the indicator's intelligence. The script uses an "Allowed Gap" setting to determine if the market is currently experiencing a period of stability or a significant trend shift.

  • If the count of highs or lows stays below your chosen limit, the tool considers this a valid area for analysis.
  • If the count exceeds that limit, the indicator remains silent, effectively "ignoring" erratic price action that doesn't meet the criteria for a meaningful move.

3. Generating Trend Visuals When the conditions in the previous steps are met, the script calculates a moving average based on the highest and lowest prices within that timeframe:

  • Upper Trend: It calculates an average of the high prices to show the ceiling of the current movement.
  • Lower Trend: It calculates an average of the low prices to show the floor of the current movement.

Visual Outputs

The tool provides clear visual cues on your chart:

  • Trend Lines: You will see moving average lines representing the price ceilings and floors when the market behaves within the specified parameters.
  • Entry Signals: The script is programmed to place specific markers (arrows) at the exact moment a new trend line appears. These arrows notify you when the conditions have just shifted from "inactive" to "active," highlighting potential turning points or new trend starts.

In summary, this script acts as a filter that hides the minor fluctuations of the market and only draws attention to price movements that are structurally significant enough to meet your defined criteria.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
TD_moving_average_I
//+------------------------------------------------------------------+
//|                                          TD moving average I.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_color3 Red
#property indicator_color4 LimeGreen
#property indicator_width1 2
#property indicator_width2 2

//
//
//
//
//

extern int HighsLowsPeriod  = 13;
extern int AllowedGapPeriod = 3;
extern int AveragesPeriod   = 5;

//
//
//
//
//

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
double buffer5[];
double buffer6[];

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

int init()
{
   IndicatorBuffers(6);
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3); SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,159);
   SetIndexBuffer(3,buffer4); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,159);
   SetIndexBuffer(4,buffer5);
   SetIndexBuffer(5,buffer6);
   return(0);
}
int deinit() { return(0); }


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

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
 
   //
   //
   //
   //
   //
   
   for(i=limit; i >= 0; i--)
   {
      if (iLowest(NULL,0,MODE_HIGH,HighsLowsPeriod,i)==i) buffer5[i] = 0; else buffer5[i] = buffer5[i+1]+1;
      if (iHighest(NULL,0,MODE_LOW,HighsLowsPeriod,i)==i) buffer6[i] = 0; else buffer6[i] = buffer6[i+1]+1;

      //
      //
      //
      //
      //
      
         buffer1[i] = EMPTY_VALUE;
         buffer2[i] = EMPTY_VALUE;
         buffer3[i] = EMPTY_VALUE;
         buffer4[i] = EMPTY_VALUE;
         
         if (buffer5[i] <= AllowedGapPeriod)  buffer1[i] = iMA(NULL,0,AveragesPeriod,0,MODE_SMA,PRICE_HIGH,i);
         if (buffer6[i] <= AllowedGapPeriod)  buffer2[i] = iMA(NULL,0,AveragesPeriod,0,MODE_SMA,PRICE_LOW ,i);
         if (buffer1[i] != EMPTY_VALUE && buffer1[i+1] == EMPTY_VALUE) buffer3[i] = buffer1[i];
         if (buffer2[i] != EMPTY_VALUE && buffer2[i+1] == EMPTY_VALUE) buffer4[i] = buffer2[i];
   }

   //
   //
   //
   //
   //
  
   return(0);
}

Comments