Author: ������� Shimodax. �� ���� ��� ������ ������ ����.
XALIF

This tool is designed to identify and visualize specific price "zones" on a trading chart based on predetermined timeframes during the trading day. Instead of looking at the entire day's movement at once, it isolates high and low price activity into two distinct windows of time.

Core Logic Overview

The script operates by scanning historical data to identify the highest and lowest prices reached during two specific sessions. It then projects these boundaries onto your chart as visual lines (zones).

1. Time-Based Segmentation

The tool is configured to look at two specific "active" periods:

  • First Period: Defined by a start and end hour (e.g., early morning).
  • Second Period: Defined by a different start and end hour (e.g., midday).

The logic automatically detects the beginning of each trading day to ensure that the calculations for one day do not interfere with the data from the previous day.

2. High and Low Detection

As the script scans through each time period, it performs a continuous "search" for:

  • The Highest Price reached during that window.
  • The Lowest Price reached during that window.

Once these extreme points are identified for the respective periods, they are captured as the boundaries for "Zone 1" and "Zone 2."

3. Visual Representation (Zones)

The script draws four distinct lines on your chart:

  • Upper and Lower Boundaries for Zone 1: These show the price range established during the first time window.
  • Upper and Lower Boundaries for Zone 2: These show the price range established during the second time window.

Because the logic "carries forward" these values, the zones provide a clear visual reference of where the price lived during those specific sessions, allowing traders to see how the current market price relates to the historical ranges of those two important periods.

4. Dynamic Feedback

The tool also includes a calculation that determines the total size (the "spread") of these identified zones. This value is displayed as an on-screen comment, providing you with the exact distance in points between the high and low of the analyzed period.

Summary for the User

Think of this script as an automated "high-low" marker. Instead of you having to manually look back at the morning or afternoon charts to see where the price moved, the script does that work for you. It identifies the boundaries of those specific times and draws them clearly on your screen so you can instantly see how the current price is reacting to previous sessions.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
XALIF
//+------------------------------------------------------------------+
//|                                               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   = "03:00";
extern string EndHour1st     = "08:00";
extern string StartHour2nd   = "12:00";
extern string EndHour2nd     = "14:30";

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];
                  Comment("Øèðèíà ïîñëåäíåãî êàíàëà=",MathAbs((thigh[j]-tlow[j])/Point));
                 }
               if (j==1)
                 {
                  Zone2Upper[k]= thigh[j];
                  Zone2Lower[k]= tlow[j];
                  Comment("Øèðèíà ïîñëåäíåãî êàíàëà=",MathAbs((thigh[j]-tlow[j])/Point));
                 }
              }
            
            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