Ma_Distance_From_Price_v2

Download script
Ma_Distance_From_Price_v2

This tool is designed to help traders visualize significant price extremes by identifying specific moments when the market moves away from its established average. Instead of showing a continuous line, it places visual markers (arrows) on your chart to highlight periods where the price has "stretched" too far in one direction relative to its moving average.

How the Logic Works

The core functionality relies on three main components: a Moving Average (MA), a customizable buffer zone, and a conditional trigger system.

1. The Baseline (Moving Average) The tool first calculates a Moving Average based on your preferred settings (such as the length of time to look back, the type of average to use, and which price point—like High, Low, or Close—to prioritize). This serves as the "fair value" or "anchor" line for the market.

2. The Buffer Zone Unlike standard indicators that might trigger a signal the moment a price crosses a line, this script uses a "Pip Buffer." You can define a specific distance (a gap) between the moving average and the current price. This acts as a filter to ignore minor fluctuations and focus only on significant movements.

3. The Trigger System The script constantly monitors the distance between the price action and the moving average. It looks for two specific conditions:

  • Overextended Upside: If the Moving Average value rises significantly above the current high of a candle (beyond your specified buffer), the tool places a visual marker. This suggests that the upward momentum has reached a point of extreme deviation.
  • Overextended Downside: Conversely, if the Moving Average falls significantly below the current low of a candle (beyond your specified buffer), another visual marker is placed. This highlights an instance where the downward pressure has moved the price into an extended zone.

Summary for the User

In plain terms, this script acts as a "stretch detector." It filters out the noise of standard market movements and highlights only those moments where the price has pushed away from its average by a predetermined amount. This allows you to quickly identify potential overextended areas on your chart without having to manually calculate distances or monitor every price tick.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Ma_Distance_From_Price_v2
//+------------------------------------------------------------------+
//|                                       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