This tool is designed to automatically map out the price boundaries of the trading day on your chart. It functions by identifying specific high and low points to create a visual "channel" that represents the price range established during a daily session.
How the Logic Works
1. Session Identification and Reset The script continuously scans historical price data to determine when a new trading period begins. It is programmed to look for specific time triggers—specifically late evening hours on weekdays and late night hours on weekends—to reset its tracking mechanism. This ensures that the boundaries calculated for one day do not bleed into or influence the calculations for the next.
2. Dynamic Boundary Tracking Once a new session starts, the tool captures the initial price levels (the high and low) of the first 30 minutes of the day. From that point forward, it performs a continuous "search" across all subsequent candles:
- Upper Bound: If the market reaches a price higher than any previously recorded price in that session, the script updates the upper boundary.
- Lower Bound: If the market drops to a price lower than any previously recorded price in that session, the script updates the lower boundary.
3. Average Price Calculation In addition to tracking the extremes, the tool automatically calculates a "Midline" or Average Channel. This is derived by finding the exact halfway point between the current high and low of the day, providing a clear visual representation of the median price level.
4. Visual Output and Data Display The script renders three distinct lines on your chart:
- An Upper Channel (High)
- A Lower Channel (Low)
- An Average Channel (Midline)
Furthermore, the tool provides real-time information directly on the chart screen. It displays a text summary showing the current high, low, and average price values, as well as the total "width" of the channel (the distance between the high and low) measured in points. This allows you to see at a glance how much volatility or range the market has covered during the current trading day.
//+------------------------------------------------------------------+
//| DayChannel.mq4 |
//| Ãîøà Øìåëü |
//| http://www.system32.ru |
//+------------------------------------------------------------------+
#property copyright "Ãîøà Øìåëü"
#property link "http://www.system32.ru"
//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 Blue
//----
double shifthigh[];
double shiftlow[];
double shiftaver[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE, 0,2);
SetIndexBuffer(0,shifthigh);
SetIndexLabel(0,"Up Channel");
SetIndexDrawBegin(0,0);
SetIndexStyle(1,DRAW_LINE, 0,2);
SetIndexBuffer(1,shiftlow);
SetIndexLabel(1,"Down Channel");
SetIndexDrawBegin(1,0);
SetIndexStyle(2,DRAW_LINE, 0,2);
SetIndexBuffer(2,shiftaver);
SetIndexLabel(2,"Average Channel");
SetIndexDrawBegin(2,0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i;
double LowLine=0;
double HighLine=0;
double AverLine=0;
//----
int ww=0;
for(i=(Bars-1);i>0;i--)
{
if (((TimeHour(Time[i])== 23) && (TimeMinute(Time[i]) < 59))
|| ((TimeDayOfWeek(Time[i])== 5) && (TimeHour(Time[i])== 22) && (TimeMinute(Time[i]) < 59)))
ww=0;
if (TimeHour(Time[i])== 0 && TimeMinute(Time[i])>=0 && TimeMinute(Time[i])<=30 && ww==0)
{
LowLine=iLow(Symbol(),NULL,i);
HighLine=iHigh(Symbol(),NULL,i);
ww=1;
}
else
{
if (iLow(Symbol(),NULL,i) < LowLine) LowLine=iLow(Symbol(),NULL,i);
if (iHigh(Symbol(),NULL,i) > HighLine) HighLine=iHigh(Symbol(),NULL,i);
}
AverLine=LowLine+(HighLine-LowLine)/2;
//----
shiftlow[i]=LowLine;
shifthigh[i]=HighLine;
shiftaver[i]=AverLine;
}
Comment(" Õàé - ", HighLine,"; Ëîó - ",LowLine, "; ÄÑ - ",AverLine,"; Øèðèíà êàíàëà=",(HighLine-LowLine)*(1/Point));
//----
return(0);
}
//+------------------------------------------------------------------+
Comments