MorningFlat

Download script
Author: Scriptong
MorningFlat

This script is designed to analyze specific price action that occurs during the early morning hours of a trading day. It automatically identifies a price "channel" formed during this period and projects potential target levels based on the expansion of that range.

Core Logic and Functionality

Timeframe and Scope Constraints The script is specifically tailored for lower timeframes (it will notify you if used on H4 charts or higher). It operates by looking at a specific window of time each day, which you can customize using the "Start Hour" and "End Hour" settings. For example, if set to start at 0 and end at 8, the script focuses on the price movements between midnight and 8:00 AM.

Morning Flat Identification The primary goal of the logic is to find the highest and lowest prices reached during your specified morning window. Once identified, the script:

  • Draws a visual "channel" representing the high and low boundaries of that morning movement.
  • Labels these boundaries with specific icons to make them clearly visible on your chart.

Projected Target Calculations Beyond just showing you what happened in the past (the morning flat), the script calculates where the price might go next. It uses a "Target Level" multiplier (defaulting to 161.8) to project potential extension points:

  • Upper Target: Calculates a projected price point above the morning high.
  • Lower Target: Calculates a projected price point below the morning low.

The script then projects these target lines forward until the start of the next trading day, providing a visual guide for potential "breakout" areas.

Visual Indicators To ensure the data is easy to read at a glance, the script uses distinct colors for different components:

  • Turquoise/Red: Used to define the boundaries of the actual morning price channel.
  • Gold/Silver: Used to highlight the projected target levels.
  • Automatic Cleanup: The script is designed to manage your chart cleanly by automatically removing its own labels when they are no longer needed, ensuring your workspace stays organized.

Summary for the User

Essentially, this tool acts as a "set-and-forget" morning analyst. It looks at how much the market moved while you were (presumably) away or during the early session, draws a box around that movement, and then creates a "roadmap" of where the price might head next based on standard mathematical extensions.

Miscellaneous
Implements a curve of type %1
13 Views
1 Downloads
0 Favorites
MorningFlat
//+------------------------------------------------------------------+
//|                                                  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*3600)+1; // Áàð, ñîîòâåòñòâóþùèé ïîñëåäíåìó áàðó "óòðåííåãî ôëýòà"
         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