This tool is designed as a visual aid for traders to identify price momentum and trend direction by analyzing the relationship between current market prices and a Moving Average (MA) line. Instead of just showing a static average, it acts as a dynamic filter that highlights specific conditions where the price interacts with its historical trend.
Core Functionality
The script calculates a Moving Average based on customizable settings (such as the length of time it looks back and the type of calculation used). It then monitors how the current closing price relates to this average line across different time frames. Depending on your preferences, the tool can display these interactions as continuous lines or as specific visual markers (arrows) on your chart.
Logic Variations
The behavior of the tool changes based on the "BreakBars" setting, which determines how much historical context the script requires before it signals an interaction:
- Instant Interaction (0 BreakBars): The tool highlights the Moving Average whenever the current price is either above or below the line. This provides a constant view of where the price sits relative to the trend.
- Immediate Confirmation (1 BreakBar): The script looks at the current bar and the one immediately preceding it. It will only display a signal if both the current price and the previous price are on the same side of the Moving Average. This helps filter out "false" touches where the price briefly flickers across the line.
- Extended Confirmation (2+ BreakBars): The logic becomes stricter by looking back at two preceding bars. It ensures that the price has maintained its position relative to the trend consistently over a longer period before highlighting the Moving Average.
Visual Presentation
The script utilizes three distinct visual layers:
- A primary line representing the Moving Average itself.
- A secondary signal (colored Red/Orange) that appears when the price is trending below the average, meeting your specific "BreakBars" criteria.
- A third signal (colored Blue) that appears when the price is trending above the average, also following the chosen "BreakBars" logic.
By adjusting these parameters, traders can choose between a very sensitive tool that reacts to every minor price movement or a more conservative tool that only highlights sustained trends.
//+------------------------------------------------------------------+
//| MA_xP |
//+------------------------------------------------------------------+
//2008fxtsd ki
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DarkSlateGray
#property indicator_color2 OrangeRed
#property indicator_color3 DeepSkyBlue
extern int ma_period =9;
extern int ma_method =1;
extern int ma_price =0;
extern int breakBars =1;
extern bool drawLine = false;
double Buffer1[];
double Buffer2[];
double Buffer3[];
//+---
int init()
{
SetIndexBuffer(0,Buffer1); SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(1,Buffer2);
SetIndexBuffer(2,Buffer3);
if (drawLine) {SetIndexStyle(1,DRAW_LINE);SetIndexStyle(2,DRAW_LINE);}
else {
SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,158); SetIndexEmptyValue (1,EMPTY_VALUE);
SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,158); SetIndexEmptyValue (2,EMPTY_VALUE);
}
return(0);
}
//+----
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
for(i=limit; i>=0; i--)
{
double MA =iMA(NULL,0,ma_period,0,ma_method,ma_price,i) ;
double MA1=iMA(NULL,0,ma_period,0,ma_method,ma_price,i+1) ;
double MA2=iMA(NULL,0,ma_period,0,ma_method,ma_price,i+2) ;
Buffer1[i] = MA;
Buffer2[i] = EMPTY_VALUE;
Buffer3[i] = EMPTY_VALUE;
int BreakBars=MathAbs(breakBars);
if (BreakBars==0)
{
if (Close[i]<MA) Buffer2[i]= MA;
if (Close[i]>MA) Buffer3[i]= MA;
}
if (BreakBars==1)
{
if (Close[i]<MA &&Close[i+1]<MA1) Buffer2[i]= MA;
if (Close[i]>MA &&Close[i+1]>MA1) Buffer3[i]= MA;
}
if (BreakBars==2)
{
if (Close[i]<MA &&Close[i+1]<MA1 &&Close[i+2]<MA2) Buffer2[i]= MA;
if (Close[i]<MA &&Close[i+1]<MA1 &&Close[i+2]>MA2) Buffer3[i]= MA;
}
if (BreakBars>=2)BreakBars=2;
}
return(0);
}
//+---------------
Comments