Author: ������� Shimodax. �� ���� ��� ������ ������ ����.
XALIF2

This tool is designed to identify and visually map specific price "zones" on a trading chart based on defined time windows during the trading day. Instead of looking at the entire day's price action, it isolates specific hours to determine key historical highs and lows that may act as significant levels for future price movement.

Core Logic Overview

The script operates by scanning the market history and categorizing price data into two distinct chronological blocks. It identifies the highest and lowest prices reached during these periods and projects them across the chart.

1. Time Window Definition

The tool is configured to monitor two specific sessions:

  • Session 1: A morning period (e.g., 05:00 to 09:00).
  • Session 2: An afternoon period (e.g., 12:00 to 15:00).

2. Dynamic Range Identification

As the script moves through the historical data, it "listens" for the start and end of these specific time windows. During these periods, it continuously tracks:

  • The Highest Price reached.
  • The Lowest Price reached.

Once a session ends, the highest and lowest points captured during that timeframe are locked in as the boundaries for that specific zone.

3. Visual Mapping

The script then paints these boundaries onto your chart as horizontal lines (Zones).

  • Zone 1: Represents the price range established during the first morning session.
  • Zone 2: Represents the price range established during the second afternoon session.

4. Daily Reset Mechanism

The logic is designed to be "day-aware." It automatically detects when a new day begins on the calendar. When the script moves into a new trading day, it clears all previous calculations and resets the trackers. This ensures that the zones shown on your screen are always relevant to the current day's price action rather than carry over old data from previous days.

Summary for the User

Essentially, this tool helps you see the "high-water marks" and "low-water marks" of the morning and afternoon sessions. By identifying these boundaries, it allows you to visualize where the market spent its most significant time during peak hours, helping you identify potential areas of interest for your own trading analysis.

Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
XALIF2
//+------------------------------------------------------------------+
//|                                               maloma 4 XALIF.mq4 |
//+------------------------------------------------------------------+
#property copyright "Ñïàñèáî Shimodax. Íà áàçå åãî èíäþêà ñäåëàë ýòîò."

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Gold
#property indicator_color2 Gold
#property indicator_color3 Coral
#property indicator_color4 Coral

//---- input parameters
extern string StartHour1st   = "05:00";
extern string EndHour1st     = "09:00";
extern string StartHour2nd   = "12:00";
extern string EndHour2nd     = "15:00";

double Zone1Upper[];
double Zone2Upper[];
double Zone1Lower[];
double Zone2Lower[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Zone1Upper);
   SetIndexEmptyValue(0, 0.0);
	SetIndexLabel(0, "Upper Zone 1");

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Zone1Lower);
   SetIndexEmptyValue(1, 0.0);
   SetIndexLabel(1, "Lower Zone 1");

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Zone2Upper);
   SetIndexEmptyValue(2, 0.0);
   SetIndexLabel(2, "Upper Zone 2");

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Zone2Lower);
   SetIndexEmptyValue(3, 0.0);
   SetIndexLabel(3, "Lower Zone 2");

   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }

int start()
  {
   int counted_bars= IndicatorCounted(),
       lastbar, result;

   if (Bars<=100) 
      return(0);
      
   if (counted_bars>0)
      counted_bars--;
      
   lastbar= Bars - counted_bars;
   
   Ranges(0, lastbar);
  }
//+------------------------------------------------------------------+

int Ranges(int offset, int lastbar)
{     
   int i, j, k,
       tidxstart[2]= { 0, 0}, 
       tidxend[2]= { 0, 0 };
   double thigh[2]= { 0.0, 0.0 }, 
           tlow[2]= { 99999.9, 99999.9 };
   string tfrom[3];
          tfrom[0]= StartHour1st;
          tfrom[1]= StartHour2nd;
          tfrom[2]= "12:00";
   string tto[3];
          tto[0]= EndHour1st;
          tto[1]= EndHour2nd;
          tto[2]= "24:00";
   string tday;
   bool inperiod= -1;
   datetime timet;
   

   //
   // search back for the beginning of the day
   //
   tday= TimeToStr(Time[lastbar], TIME_DATE);   
   for (  ; lastbar<Bars; lastbar++) {
      if (TimeToStr(Time[lastbar], TIME_DATE)!=tday) {
         lastbar--;
         break;      
      }
   }   

   //
   // find the high/low for the two periods and carry them forward through the day
   //
   tday= "XXX";
   for (i= lastbar; i>=offset; i--)
     {
         timet= Time[i];   // time of this bar
      
      string timestr= TimeToStr(timet, TIME_MINUTES),    // current time HH:MM
             thisday= TimeToStr(timet, TIME_DATE);       // current date
          
          
      //
      // for all three periods (first period, second period, rest of day)
      //
      for (j=0; j<3; j++)
        {      
         if (tfrom[j]<=timestr && timestr<tto[j])    // Bar[i] in this period
           {
            
            // for the current period find idxstart, idxend and compute high/low
            if (tidxstart[j]==0)
              {
               tidxstart[j]= i;
               tday= thisday;
              }
            
            tidxend[j]= i;
            
            thigh[j]= MathMax(thigh[j], High[i]);
            tlow[j]= MathMin(tlow[j], Low[i]);
            
            for (k= tidxstart[j]; k>=tidxend[j]; k--)
              {
               if (j==0)
                 {
                  Zone1Upper[k]= thigh[j];
                  Zone1Lower[k]= tlow[j];
                 }
               if (j==1)
                 {
                  Zone2Upper[k]= thigh[j];
                  Zone2Lower[k]= tlow[j];
                 }
              }
            
            inperiod= j;   // remember current period
            
            if (inperiod==2)   // inperiod==2 (end of day) is just to check completion of zone 2
              break;
         }
     }
      
      
      //
      // at the beginning of a new day reset everything
      //
      if (tday!="XXX" && tday!=thisday || TimeToStr(timet, TIME_MINUTES)>=tto[2]) {
         // Print("#", i, "new day ", thisday, "/", tday);
      
         tday= "XXX";
         
         inperiod= -1;
         
         for (j= 0; j<2; j++) {
            tidxstart[j]= 0;
            tidxend[j]= 0;
         
            thigh[j]= 0;
            tlow[j]= 99999;
         }
      }
   }

   return (0);       
}



Comments