Ma_Distance_From_Price

Download script
Ma_Distance_From_Price

This script is designed as a visual trading tool for MetaTrader 4, specifically created to identify significant price "stretch" or exhaustion by measuring the distance between the current market price and a Moving Average.

Core Functionality

The tool acts as an alert system that monitors how far the current market price has deviated from its established trend line (the Moving Average). Instead of simply showing you where the trend is, it highlights specific moments where the price has pushed exceptionally far away from that average, which traders often use to identify potential reversals or overextended moves.

How the Logic Works

The script performs a continuous calculation based on four main components:

  • Trend Calculation: It calculates a Moving Average based on parameters you can customize (such as the length of the period, the type of average, and the specific price point used for the calculation).
  • The Distance Buffer: This is the "sensitivity" setting. You can define a specific amount of space (measured in Pips) that the price must move away from the Moving Average before the tool takes action.
  • Dynamic Monitoring: The script scans the historical data to look for two specific conditions:
    1. Upper Extension: If the Moving Average is significantly higher than the current high price (beyond your set buffer), it signals that the price may be lagging or dropping too quickly.
    2. Lower Extension: If the Moving Average is significantly lower than the current low price (beyond your set buffer), it signals a potential upward move or a bottoming out.

Visual Output

When these specific distance conditions are met, the script automatically places visual markers (arrows) on your chart:

  • One type of arrow appears when the price is extended significantly below the Moving Average.
  • A different type of arrow appears when the price is extended significantly above the Moving Average.

Summary for the User

Essentially, this tool filters out "normal" market noise. It ignores minor fluctuations and only highlights instances where the price has moved into a zone that might be considered overextended relative to its moving average. This allows you to see at a glance where the market might be reaching a point of fatigue, providing a visual aid for identifying potential entry or exit points based on price distance.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
Ma_Distance_From_Price
//+------------------------------------------------------------------+
//|                                       Ma_Distance_From_Price.mq4 |
//|                              transport_david , David W Honeywell |
//|                                        transport.david@gmail.com |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Coral
#property indicator_color2 White
//---- input parameters
extern int MaPeriod          =   9;  // default = 9,0,3,0,15 on H1 charts
extern int MaShift           =   0;
extern int MaMethod_0to3     =   3; // 0 = SMA, 1 = EMA, 2 = SMMA, 3 = LWMA
extern int AppliedPrice_0to6 =   0; // 0 = Close, 1 = Open, 2 = High, 3 = Low, 4 = Median, 5 = Typical, 6 = Weighted Close
extern int PipBuffer         =  15; // If Ma > Price+PipBuffer then arrow , If Ma < Price-PipBuffer then arrow
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,234);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,233);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int    i;
//---- 
   for (i=Bars-50; i>=0; i--)
      {
      
      double MaCurrent = iMA(Symbol(),0,MaPeriod,MaShift,MaMethod_0to3,AppliedPrice_0to6,i);
      
      if ( MaCurrent > ( High[i] + PipBuffer*Point ) )
         ExtMapBuffer1[i] = High[i]+2*Point;
      
      if ( MaCurrent < ( Low[i] - PipBuffer*Point ) )
         ExtMapBuffer2[i] = Low[i]-2*Point;
      
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments