Hi-Lo_v4
Download scriptThis tool is designed to identify specific price action trends by analyzing the relationship between current market prices and a moving average of historical highs and lows. It acts as a visual guide, placing directional markers on your chart to help distinguish between "buy" and "sell" zones based on momentum shifts.
How the Logic Works
The script operates by constantly monitoring two different types of moving averages: one based on the highest prices reached over a specific period, and another based on the lowest prices reached over that same timeframe. By focusing on these extremes rather than just the average closing price, the tool provides a clearer picture of the market's boundaries.
The core logic follows a "state-switching" system:
- Trend Identification: The script looks at where the current price sits in relation to these high and low boundaries.
- The Switch: When the price breaks above the moving average of recent highs, the system registers a shift toward an upward trend. Conversely, when the price falls below the moving average of recent lows, it recognizes a downward shift.
- Visual Signaling: To keep the chart clean and easy to read, the script doesn't draw a continuous line. Instead, it places specific arrows on the chart only when a new trend is confirmed.
- An arrow appears when the price confirms it has moved into a positive trend area.
- A separate arrow appears when the price confirms it has shifted into a negative trend area.
Key Features for the User
- Customizable Sensitivity: You can adjust the "Period" setting to change how many past candles the script looks at. A smaller period makes the tool more sensitive to quick price changes, while a larger period smooths out the data to identify long-term trends.
- Visual Clarity: The markers are placed slightly offset from the actual price points (by a few pips) to ensure they remain clearly visible and do not overlap with the candlesticks themselves.
- Automated Monitoring: The script automatically processes a large amount of historical data (up to 300 bars) upon loading, ensuring that your chart is populated with relevant signals immediately.
In summary, this tool serves as an automated trend-following assistant. It filters out minor market noise by focusing on significant price breakouts at historical highs and lows, signaling potential shifts in direction with clear visual markers.
//+------------------------------------------------------------------+
//| 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 = 3;
extern int CountBars = 300;
//---- buffers
double Up[];
double Down[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
SetIndexStyle(0, DRAW_ARROW, 0, 1);
SetIndexArrow(0, 159);
SetIndexStyle(1, DRAW_ARROW, 0, 1);
SetIndexArrow(1, 159);
SetIndexBuffer(0, Up);
SetIndexBuffer(1, Down);
//---- name for DataWindow label
SetIndexLabel(0, "HiLoUp(" + Per + ")");
SetIndexLabel(1, "HiLoDown(" + Per + ")");
//----
SetIndexDrawBegin(0, Per);
SetIndexDrawBegin(1, Per);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Hi-Lo |
//+------------------------------------------------------------------+
int start()
{
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;
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