MorningFlat[1]

Download script
Author: Scriptong
MorningFlat[1]

This script is designed as a technical analysis tool for MetaTrader 4 to help traders identify and visualize specific price boundaries based on market activity during the early morning hours. It focuses on identifying a "Morning Flat" range and projecting potential price targets for the rest of the trading day.

Core Functionality

Time-Based Monitoring The script specifically monitors a defined window of time every day (customizable by the user). It looks back at the price action between a specific start hour and an end hour to establish a reference zone. For instance, if configured for the early morning, it captures the high and low prices reached during that specific period.

Range Identification Once the designated time window concludes, the script identifies two key price points:

  • The High Boundary: The highest price reached during the morning period.
  • The Low Boundary: The lowest price reached during the morning period.

The tool then draws visual lines on your chart to represent this "flat" range, making it easier to see the boundaries of the morning's price movement.

Target Projection Beyond just marking the current range, the script calculates potential "breakout" targets. Based on a user-defined Fibonacci-style level (defaulting to 161.8), the script projects where the price might move if it breaks out of the established morning flat. It calculates:

  • An Upper Target based on the distance of the morning range multiplied by the target factor.
  • A Lower Target calculated similarly in the opposite direction.

These targets are projected forward onto the chart for the remainder of the trading day, providing a visual guide for potential price destinations.

Visual Elements and Compatibility To keep the chart clean and readable:

  • The script automatically places labels (arrows) at the beginning of the day's high/low range and at the specific points where the target projections begin.
  • It uses distinct colors to differentiate between the current morning range and the projected targets.
  • It includes built-in safety checks to ensure it only runs on appropriate timeframes (lower than H4) and validates that the user-entered hours are logically correct.

Summary for the Trader

Essentially, this tool automates the tedious task of measuring daily "opening" ranges. It marks where the market spent its morning, highlights the boundaries of that movement, and pre-calculates exactly where price might head if it decides to break out of that initial morning zone.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
MorningFlat[1]
//+------------------------------------------------------------------+
//|                                                  MorningFlat.mq4 |
//|                                                        Scriptong |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Scriptong"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Turquoise
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Silver

extern int StartHour = 0;
extern int EndHour = 8;
extern double TargetLevel = 161.8;
extern color UpColor = Turquoise;
extern color DnColor = Red;
extern color TargetUpColor = Gold;
extern color TargetDnColor = Silver;

//---- buffers
double Up[];
double Down[];
double TargetUp[];
double TargetDn[];
bool Activate = False;
datetime LastDay;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if(Period() > PERIOD_H1) 
     {
      Comment("Èíäèêàòîð ðàáîòàåò íà òàéìôðåéìàõ ìåíüøå H4!");
      return(0);   
     }
   if(StartHour < 0 || EndHour < 0 || StartHour > 23 || EndHour > 23 || StartHour >= EndHour)
     {
      Comment("Çíà÷åíèÿ StartHour è EndHour äîëæíû ëåæàòü â äèàïàçîíå îò 0 äî 24 è StartHour < EndHour.");
      return(0);
     } 
    
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Up);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Down);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,TargetUp);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,TargetDn);
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   
   Activate = True;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   // Óäàëåíèå  îáúåêòîâ-öåíîâûõ ìåòîê
   for (int i = ObjectsTotal()-1; i >= 0; i--)
     { 
      string Name = ObjectName(i);
      if (StringSubstr(Name, 0, 3) == "Lab")
        ObjectDelete(Name);
     }
   Comment("");
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Öåíîâàÿ ìåòêà ñî çíà÷åíèåì óðîâíÿ                                |
//+------------------------------------------------------------------+
void DrawLabel(datetime TimeL, double Price, bool Upper, color Col, int Code)
{
 if(Upper)
   string Name = "Lab"+DoubleToStr(TimeL, 0)+"U";
  else
   Name = "Lab"+DoubleToStr(TimeL, 0)+"D"; 

 if(ObjectCreate(Name, OBJ_ARROW, 0, TimeL, Price))
   {
    ObjectSet(Name, OBJPROP_ARROWCODE, Code);
    ObjectSet(Name, OBJPROP_COLOR, Col);
   } 
}
  
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   if(!Activate) return(0);

   LastDay = 0;
   int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   for(int i=limit; i>=0; i--)
     if(TimeHour(Time[i]) >= EndHour)
       {
         datetime BeginDay = iTime(Symbol(), PERIOD_D1, iBarShift(Symbol(), PERIOD_D1, Time[i]));  // Ðàñ÷åò âðåìåíè íà÷àëà ñóòîê
         datetime NextDay = BeginDay+86400;  // Ðàñ÷åò âðåìåíè íà÷àëà ñëåäóþùèõ ñóòîê
         if(LastDay >= BeginDay) continue; // Åñëè â ýòîò äåíü óæå ðèñîâàëè óðîâíè, òî ïðîäîëæàåì îñíîâíîé öèêë
         int StartBar = iBarShift(Symbol(), 0, BeginDay+StartHour*3600);   // Áàð, ñîîòâåòñâóþùèé íà÷àëó ñóòîê ïëþñ ñìåùåíèå â ÷àñàõ
         int FinishBar = iBarShift(Symbol(), 0, BeginDay+(EndHour-1)*3600); // Áàð, ñîîòâåòñòâóþùèé ïîñëåäíåìó áàðó "óòðåííåãî ôëýòà"
         double LowV = Low[iLowest(Symbol(), 0, MODE_LOW, StartBar-FinishBar+1, FinishBar)];  // Íèæíÿÿ ãðàíèöà
         double HighV = High[iHighest(Symbol(), 0, MODE_HIGH, StartBar-FinishBar+1, FinishBar)]; // Âåðõíÿÿ ãðàíèöà
         double TargetU = (HighV-LowV)*(TargetLevel-100)/100+HighV;
         double TargetD = LowV-(HighV-LowV)*(TargetLevel-100)/100;
         // Êàíàë "óòðåííåãî ôëýòà"
         for(int j = StartBar; j >= FinishBar; j--)
           {
            Up[j] = HighV;
            Down[j] = LowV;
           }
         // -----------------------
         // Îæèäàåìûå öåëè ïðè ïðîáîå ôëýòà  
         for(j = FinishBar; Time[j] < NextDay && j >= 0; j--)
           {
            TargetUp[j] = TargetU;
            TargetDn[j] = TargetD;
           }
         // -------------------  
           
         DrawLabel(Time[iBarShift(Symbol(), 0, BeginDay)], HighV, True, UpColor, 5);   // Ðèñóåì âåðõíþþ öåíîâóþ ìåòêó êàíàëà
         DrawLabel(Time[iBarShift(Symbol(), 0, BeginDay)], LowV, False, DnColor, 5);   // Ðèñóåì íèæíþþ öåíîâóþ ìåòêó êàíàëà
         DrawLabel(Time[FinishBar], TargetU, True, TargetUpColor, 5);   // Ðèñóåì âåðõíþþ öåíîâóþ ìåòêó öåëè
         DrawLabel(Time[FinishBar], TargetD, False, TargetDnColor, 5);   // Ðèñóåì íèæíþþ öåíîâóþ ìåòêó öåëè
         LastDay = BeginDay;  // Îòìå÷àåì, ÷òî â ýòîò äåíü óðîâíè óæå áûëè íàðèñîâàíû
       }

   WindowRedraw();
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments