Hi-Lo RELIABLE
Download scriptThis tool is designed to provide visual signals on a trading chart by identifying specific shifts in price momentum based on high and low price averages. It functions as a trend-tracking indicator that marks potential entry or exit points using colored arrows.
How the Logic Works
The script operates by analyzing the relationship between the current closing price and two distinct moving averages: one calculated from the highest prices over a set period, and another from the lowest prices over that same period.
1. Trend Detection Instead of looking at simple price movement, the tool tracks whether the market is currently "breaking out" above or below these high/low boundaries. It constantly monitors two conditions:
- Bullish Signal: If the closing price moves above the high-price average, the logic registers a shift toward an upward trend.
- Bearish Signal: If the closing price drops below the low-price average, the logic registers a shift toward a downward trend.
2. Signal Filtering (State Persistence) To prevent the chart from becoming cluttered with constant signals, the script uses "state memory." It remembers the previous state of the market. A new signal is only triggered when there is a definitive crossover from one state to another—for example, moving from a bearish trend to a bullish one. If the price remains within the same trend boundary, no new marks are placed.
3. Visual Representation Once a transition is detected:
- When the market switches to a bullish state, the script places a visual marker (an arrow) just below the current low average.
- When the market switches to a bearish state, the script places a visual marker just above the current high average.
Key Customizable Features
The logic allows for two primary adjustments to change how the tool behaves:
- Period: This determines how many previous bars are used to calculate the highs and lows. A shorter period makes the indicator more sensitive to quick price changes, while a longer period makes it react more slowly to major trends.
- Count Bars: This defines the historical depth of the chart the script will analyze at one time.
In summary, this script acts as a "trend switcher" that identifies when the market has broken out of its recent high or low boundaries, providing clear visual cues for when momentum has shifted in either direction.
//+------------------------------------------------------------------+
//| Hi-Lo.mq4 |
//| |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Lime
//---- input parameters
extern int Per=2;
extern int CountBars=3000;
//---- buffers
double Up[];
double Down[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,159);
SetIndexBuffer(0,Up);
SetIndexBuffer(1,Down);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Hi-Lo |
//+------------------------------------------------------------------+
int start()
{
SetIndexDrawBegin(0,Bars-CountBars+Per);
SetIndexDrawBegin(1,Bars-CountBars+Per);
int i,counted_bars=IndicatorCounted();
bool Pr=false, PrevPr=false;
double val,val2;
//----
if(CountBars<=Per) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=Per;i++) Up[CountBars-i]=0.0;
for(i=1;i<=Per;i++) Down[CountBars-i]=0.0;
}
//----
i=CountBars-Per-1;
// if(counted_bars>=CCIPeriod1) i=Bars-counted_bars-1;
while(i>=0)
{
val=iMA(NULL,0,Per,1,MODE_SMA,PRICE_HIGH,i);
val2=iMA(NULL,0,Per,1,MODE_SMA,PRICE_LOW,i);
if (Close[i]<val2 && PrevPr==true) Pr=false;
if (Close[i]>val && PrevPr==false) Pr=true;
PrevPr=Pr;
Up[i]=0.0; Down[i]=0.0;
if (Pr==false) Up[i] = val+2*Point;
if (Pr==true) Down[i] = val2-2*Point;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments