Ma_Distance_From_Price_v1
Download scriptThis tool is designed to help traders identify significant price discrepancies between the current market action and a specific Moving Average (MA) trend line. Instead of just following the trend, this indicator focuses on measuring "distance"—essentially highlighting moments where the price has moved significantly away from or toward its average value.
How it Works
The logic operates by continuously calculating a Moving Average based on your preferred settings (such as the timeframe period, the type of moving average, and the specific price data used for calculation). It then monitors the distance between this Moving Average and the actual highs and lows of the market candles.
Key Features and Logic:
- Distance Filtering: The script uses a customizable "Pip Buffer." This is a crucial setting that prevents the tool from creating "noise." It ensures that an alert or visual signal only appears if the gap between the Moving Average and the price is larger than a specific amount.
- Visual Signals: Rather than drawing lines, the indicator places distinct arrows on your chart:
- Upper Signals: When the Moving Average sits significantly above the current high of a candle (exceeding the Pip Buffer), a visual signal appears. This often suggests that the price is trailing well below its average.
- Lower Signals: When the Moving Average sits significantly below the current low of a candle (exceeding the Pip Buffer), a different visual signal appears. This typically indicates that the price is pushing far above its average.
- Customizable Sensitivity: Because every trading strategy is different, the tool allows you to adjust the period of the moving average and the type of calculation method (such as Simple, Exponential, or Linear Weighted) to match your specific trading style.
Practical Application
For a trader, this script serves as a "stretch" indicator. It highlights potential overextended moves where the price has moved too far, too fast, away from its mean. By observing these arrows, traders can identify opportunities to look for potential trend exhaustion or extreme market movements that might require a corrective move back toward the average.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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