ma_hl_sw
Download scriptThis custom indicator is designed to help traders identify potential momentum shifts and trend reversals by analyzing the relationship between two different moving averages. Instead of simply looking at price, it focuses on the interaction between specific price points—highs and lows—over two distinct timeframes.
How the Logic Works
The core functionality of this script relies on comparing a "fast" moving average (short-term trend) against a "slow" moving average (long-term trend). Specifically, it tracks the highest highs and the lowest lows associated with these averages.
1. Trend Detection The tool looks for specific conditions where the short-term movement moves in harmony with the long-term structure:
- Bullish Alignment: If the short-term high is greater than the long-term high, and simultaneously, the short-term low is greater than the long-term low, the script identifies a positive alignment.
- Bearish Alignment: Conversely, if both the short-term high and low are lower than their corresponding long-term counterparts, it identifies a negative alignment.
2. Visual Signaling Rather than creating a cluttered line on your main chart, this indicator operates in a separate window and uses a visual "level" system:
- Blue Markers: These appear when the short-term trend aligns with a bullish bias relative to the long-term average.
- Red Markers: These appear when the short-term trend aligns with a bearish bias relative to the long-term average.
3. Smart Filtering The script includes a logic gate to prevent "signal noise." It checks the previous bar's data before placing a marker; if a signal was already active on the preceding bar, it will not repeat the marker unless the condition has reset. This ensures that the visual output remains clean and highlights the initiation of a trend shift rather than every single bar within a sustained move.
Summary for the Trader
In practical terms, this indicator acts as a filter to show you when short-term price action is "breaking out" above or falling below the established long-term boundaries. By viewing these signals in a separate window, you can monitor the transition between bullish and bearish states more clearly, helping to identify when momentum is shifting from one direction to another.
//+------------------------------------------------------------------+
//| |
//| |
//+------------------------------------------------------------------+
//2009fxtsd
#property copyright ""
#property link ""
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_minimum 1
#property indicator_maximum 9
//
extern int maperiod1 = 5;
extern int maperiod2 = 34;
extern int mamethod = 1;
extern int maprice = 0;
extern double barlevel = 2.5;
double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,buffer1);
SetIndexBuffer(1,buffer2);
SetIndexBuffer(2,buffer3);
SetIndexBuffer(3,buffer4);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,108);
SetIndexEmptyValue(2,EMPTY_VALUE);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,108);
SetIndexEmptyValue(3,EMPTY_VALUE);
IndicatorShortName("ma hl " +maperiod1+","+maperiod2);
// SetIndexLabel(0,"Sto");
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=limit; i>=0; i--)
{
double ma1h = iMA(NULL, 0, maperiod1, 0,mamethod, 2, i);
double ma1l = iMA(NULL, 0, maperiod1, 0,mamethod, 3, i);
double ma2h = iMA(NULL, 0, maperiod2, 0,mamethod, 2, i);
double ma2l = iMA(NULL, 0, maperiod2, 0,mamethod, 3, i);
buffer1[i] =EMPTY_VALUE; buffer2[i] =EMPTY_VALUE;
buffer3[i] =EMPTY_VALUE; buffer4[i] =EMPTY_VALUE;
if (ma1h>ma2h && ma1l>ma2l)
{ buffer1[i] =barlevel; if (buffer1[i+1]==EMPTY_VALUE) buffer3[i] =barlevel;
}
if (ma1l<ma2l && ma1h<ma2h)
{ buffer2[i] =barlevel; if (buffer2[i+1]==EMPTY_VALUE) buffer4[i] =barlevel;
}
}
return(0);
}
Comments