SDX-TzBreaktout

Download script
Author: Copyright Shimodax
SDX-TzBreaktout

The TZ-Breaktout script is a specialized charting tool designed to help traders visualize specific price "zones" based on time intervals. Rather than looking at the entire day's price action, this script identifies and highlights significant price movements during the early morning sessions to help identify potential breakout points for the rest of the day.

Core Logic and Functionality

1. Timezone Synchronization The script allows you to synchronize the data with your specific local time. Because different trading servers operate on different time offsets, it calculates the difference between your local time and the "destination" time to ensure the price zones are drawn accurately according to your specific region's hours.

2. Defined Time Periods The logic divides the trading day into three distinct phases:

  • Period 1 (Early Morning): From 04:00 to 08:00.
  • Period 2 (Mid Morning): From 08:00 to 12:00.
  • The Remainder of the Day: Any time after 12:00.

3. Zone Identification The script scans the price history during these specific windows to find the "High" and "Low" prices reached in each period.

  • Once Period 1 finishes, the script identifies its highest and lowest points.
  • Once Period 2 finishes, it identifies its highest and lowest points.

4. Visual Projection (The Breakout Zones) Once these high/low values are captured from the morning sessions, the script projects them forward onto the chart for the rest of the trading day. It draws:

  • Upper Boundaries: The highest price of the period plus a user-defined "buffer" (in pips) to account for entry space.
  • Lower Boundaries: The lowest price of the period minus that same buffer.

How Traders Use This Logic

The goal of this script is to create a visual "boundary box." By highlighting these zones, a trader can easily see where the market established its range during the early hours.

The trading logic implied by these visuals is typically a Breakout Strategy:

  • If the price moves above the upper zone projected from the morning sessions, it may signal a bullish breakout.
  • If the price moves below the lower zone, it may signal a bearish breakout.

By automating the calculation of these highs and lows, the script removes the manual effort of measuring price ranges, allowing traders to focus on whether the market is successfully "breaking out" of the morning's established boundaries.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
SDX-TzBreaktout

//+------------------------------------------------------------------+
//|  TZ-Breaktout.mq4                                                |
//|  Shimodax                                                        |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "Copyright Shimodax"
#property link      "http://www.strategybuilderfx.com/forums/showthread.php?t=15439"


/* Introduction:

   Draw ranges for "Simple Combined Breakout System for EUR/USD and GBP/USD" thread
   (see http://www.strategybuilderfx.com/forums/showthread.php?t=15439)

   LocalTimeZone: TimeZone for which MT4 shows your local time, 
                  e.g. 1 or 2 for Europe (GMT+1 or GMT+2 (daylight 
                  savings time).  Use zero for no adjustment.
                  
                  The MetaQuotes demo server uses GMT +2.   
   Enjoy  :-)
   
   Markus

*/


#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Gray
#property indicator_color2 Gray
#property indicator_color3 LightGray
#property indicator_color4 LightGray
#property indicator_color5 Blue


extern int LocalTimeZone= 2;
extern int DestTimeZone= 0;
extern int PipsForEntry= 5;




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



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

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Zone1Lower);
   SetIndexEmptyValue(1, 0.0);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Zone2Upper);
   SetIndexEmptyValue(2, 0.0);

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Zone2Lower);
   SetIndexEmptyValue(3, 0.0);

   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4, 156);
   SetIndexBuffer(4, SignalsBuffer);

   return(0);
}

int deinit()
{

   return(0);
}
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars= IndicatorCounted(),
         lastbar, result;

   if (Bars<=100) 
      return(0);
      
   if (counted_bars>0)
      counted_bars--;
      
   lastbar= Bars - counted_bars;
   
   BreakoutRanges(0, lastbar, LocalTimeZone, DestTimeZone);
   
   return(0);
}

 
//+------------------------------------------------------------------+
//| Compute index of first/last bar of yesterday and today           |
//+------------------------------------------------------------------+
int BreakoutRanges(int offset, int lastbar, int tzlocal, int tzdest)
{     
   int i, j, k,
       tzdiff= tzlocal - tzdest,
       tzdiffsec= tzdiff*3600, 
       tidxstart[2]= { 0, 0}, 
       tidxend[2]= { 0, 0 };
   double thigh[2]= { 0.0, 0.0 }, 
           tlow[2]= { 99999.9, 99999.9 };
   string tfrom[3]= { "04:00", "08:00" ,  /*rest of day: */ "12:00"},
          tto[3]=   { "08:00", "12:00",   /*rest of day: */ "24:00" },
          tday;
   bool inperiod= -1;
   datetime timet;
   

   //
   // search back for the beginning of the day
   //
   tday= TimeToStr(Time[lastbar]-tzdiffsec, TIME_DATE);   
   for (  ; lastbar<Bars; lastbar++) {
      if (TimeToStr(Time[lastbar] - tzdiffsec, 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] - tzdiffsec;   // 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
      
            if (inperiod!=j) { // entered new period, so last one is completed
                                 
               if (j>0) {      // now draw high/low back over the recently completed period
               
                  for (k= tidxstart[j-1]; k>=tidxend[j-1]; k--) {
                     if (j-1==0) {
                        Zone1Upper[k]= thigh[j-1];
                        Zone1Lower[k]= tlow[j-1];
                     }

                     if (j-1==1) {
                        Zone2Upper[k]= thigh[j-1];
                        Zone2Lower[k]= tlow[j-1];
                     }
                  }
               }
               
               inperiod= j;   // remember current period
            }
            
            if (inperiod==2)   // inperiod==2 (end of day) is just to check completion of zone 2
               break;


            // 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]);
         }
      }
      
      
      // 
      // carry forward the periods for which we have definite high/lows
      //
      if (inperiod>=1 && tday==thisday) { // first time period completed
         Zone1Upper[i]= thigh[0] + PipsForEntry*Point;
         Zone1Lower[i]= tlow[0] - PipsForEntry*Point;
         
         if (inperiod>=2) {   // second period completed
            Zone2Upper[i]= thigh[1] + PipsForEntry*Point;
            Zone2Lower[i]= tlow[1] - PipsForEntry*Point;
         }
      }
      else {   // none yet to carry forward (zero to clear old values, e.g. from switching timeframe)
         Zone1Upper[i]= 0;
         Zone1Lower[i]= 0;
         Zone2Upper[i]= 0;
         Zone2Lower[i]= 0;
      }
     

      //
      // at the beginning of a new day reset everything
      //
      if (tday!="XXX" && tday!=thisday) {
         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