MF_BreakDown_Flat 0-1010
Download scriptThis script is designed as an automated visual tool for traders who want to identify and trade market "flats"—periods where price action moves sideways rather than in a clear trend. By automating the identification of these levels, it removes the need for manual drawing and provides a structured way to spot potential entry points.
Core Logic Overview
The script functions by analyzing historical price data over a user-defined period (defaulting to 10 days) to identify key price boundaries. It specifically focuses on identifying three types of horizontal levels for each day: Resistance, Support, and a Pivot point.
How the Automation Works
1. Timeframe Segmentation The logic calculates specific time windows for every day in the history period. It identifies the beginning of the trading day (midnight) and the end of the early session (typically around 07:00). It uses these boundaries to "slice" the market data into daily segments to find the highs and lows relevant to that specific day.
2. Data Analysis For each daily segment, the script automatically scans the price history to determine:
- The highest price reached during the session (to establish the ceiling).
- The lowest price reached during the session (to establish the floor).
- A calculated midpoint based on these extremes.
3. Visual Identification Once the data is processed, the script draws horizontal lines directly on your chart to represent these levels:
- Resistance Level: Marked in OrangeRed, this represents the "ceiling" or the maximum height reached during the early session.
- Support Level: Marked in SandyBrown, this represents the "floor" or the lowest point reached during the session.
- Pivot Point: This is a calculated middle ground between the high and low points, helping traders identify the "center" of the price range.
Purpose for the Trader
The primary goal of this logic is to simplify technical analysis for beginners and experienced traders alike. Instead of guessing where the market might bounce or stall, the script provides clear, consistent levels based on actual historical data.
According to the script's documentation, these levels are particularly useful for identifying "Double Breakouts." Traders can use these lines to see where price is being held or pushed back, allowing them to wait for a confirmed break of these boundaries as a signal to enter a trade.
//+-------------------------------------------------------------------+
//| MF_BreakDown_Flat 0-1010.mq4|
//| Copyright c YuraZZhunko |
//| ÌF YURAZ yzh@mail.ru |
//|19.12.2006 ÌF ZHUNKO zhunko@mail.ru |
//+-------------------------------------------------------------------+
//| Ïðåäñòàâëÿåì èíäèêàòîð óòðåííåãî ôëåòà. |
//| Òåïåðü íåò íåîáõîäèìîñòè ÷åðòèòü óðîâíè ðóêàìè. |
//| Äëÿ íîâè÷êîâ áóäåò î÷åíü ïîëåçåí. |
//| Ñîãëàñíî ÒÑ ÌÔ, îáû÷íî âõîä ïðè äâîéíîì ïðîáîå è ïîääåðæêè |
//| ñîþçíèêîâ ýòî ïåðâàÿ òî÷êà âõîäà. |
//+-------------------------------------------------------------------+
//| |
//| ÈÇÌÅÍÅÍÈß è ÄÎÏÎËÍÅÍÈß. |
//| 1.Èçìåíåíèÿ â MF_BreakDown_Flat 0-1010 21.12.2006 . |
//| 1.1.Îïòèìèçàöèÿ êîäà. |
//+-------------------------------------------------------------------+
#property copyright "Copyright c 2006 YuraZ-Zhunko"
#property link "yzh@mail.ru ; zhunko@mail.ru"
//----
#property indicator_chart_window
//----------------------------------------------------------------------
extern int Äíåé=10; // Ñêîëüêî äíåé â èñòîðèè ïîêàçûâàòü.
extern string sTimeEndAsia=" 07:00:00"; // Âû ìîæåòå ââåñòè ñâîè çíà÷åíè.
extern int m7=7; // Ýòî ïðèéäåòñÿ òîæå ïîïðàâèòü.
extern string sTimeEndEur =" 10:00:00"; // Âðåìÿ äî êîòîðîãî ìû òåðïèì ôëåò.
//----------------------------------------------------------------------
double Max, Max1, Min, Min1;
double Max2, Min2;
int BarsDay; // êîëè÷åñòâî áàðîâ çà äåíü
string noR="yzR";
string noS="yzS";
string noP="yzP";
int mMonth ;
int mYear ;
int mDay ;
datetime mDatBegin;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
mDatBegin=StrToTime (StringConcatenate (TimeToStr (TimeCurrent(), TIME_DATE), " 00:00:00")) - (Äíåé * 86400);
for( mYear =0; mDatBegin < TimeCurrent(); mDatBegin+=86400 )
{
mYear =TimeYear (mDatBegin);
mMonth=TimeMonth (mDatBegin);
mDay =TimeDay (mDatBegin);
//----
string d=StringConcatenate (DoubleToStr (mYear,0), ".", DoubleToStr (mMonth, 0), ".", DoubleToStr (mDay , 0), " ", "07:00");
ObjectCreate(noR+d, OBJ_TREND, 0, 0,0, 0,0,0,0); // Res ñîïðîòèâëåíèå
ObjectCreate(noS+d, OBJ_TREND, 0, 0,0, 0,0,0,0); // ïèâîò
ObjectCreate(noP+d, OBJ_TREND, 0, 0,0, 0,0,0,0); // Sup ïîääåðæêà
}
}
//+------------------------------------------------------------------+
int start()
{
string d;
if (Äíåé==0) Äíåé=1;
if (Äíåé>=100)Äíåé=100;
//----
mDatBegin=StrToTime (StringConcatenate (TimeToStr (TimeCurrent(), TIME_DATE), " 00:00:00")) - (Äíåé * 86400);
for(mYear =0; mDatBegin < TimeCurrent(); mDatBegin+=86400 )
{
mYear =TimeYear( mDatBegin);
mMonth=TimeMonth( mDatBegin);
mDay =TimeDay( mDatBegin);
//----
d=StringConcatenate (DoubleToStr (mYear,0), ".", DoubleToStr (mMonth, 0), ".", DoubleToStr (mDay , 0), " 07:00"); // sTimeEndAsia; // " " + ;
ObjectCreate (noR + d, OBJ_TREND, 0, 0,0, 0,0,0,0); // Res ñîïðîòèâëåíèå
ObjectCreate (noS + d, OBJ_TREND, 0, 0,0, 0,0,0,0); // ïèâîò
ObjectCreate (noP + d, OBJ_TREND, 0, 0,0, 0,0,0,0); // Sup ïîääåðæêà
}
mDatBegin=StrToTime (StringConcatenate (TimeToStr (TimeCurrent(), TIME_DATE), " 00:00:00")) - (Äíåé * 86400);
//----
for(mYear =0; mDatBegin < CurTime(); mDatBegin+=86400 )
{
mYear =TimeYear (mDatBegin);
mMonth=TimeMonth (mDatBegin);
mDay =TimeDay (mDatBegin);
//----
datetime ÒåêóùååÂðåìÿÒåðìèíàëà= TimeCurrent();
string strÒåêóùååÂðåìÿÒåðìèíàëà=TimeToStr (ÒåêóùååÂðåìÿÒåðìèíàëà, TIME_DATE|TIME_MINUTES|TIME_SECONDS);
if (TimeHour (ÒåêóùååÂðåìÿÒåðìèíàëà) < m7)
{
sTimeEndAsia =StringConcatenate (" ", DoubleToStr (TimeHour (ÒåêóùååÂðåìÿÒåðìèíàëà), 0), ":", DoubleToStr (TimeMinute (ÒåêóùååÂðåìÿÒåðìèíàëà), 0), ":00");
}
//----
strÒåêóùååÂðåìÿÒåðìèíàëà=StringConcatenate (DoubleToStr (mYear, 0), ".", DoubleToStr (mMonth, 0), ".", DoubleToStr (mDay , 0), " ", sTimeEndAsia);
// åñëè âðåìÿ ïîïàäàåò âíóòðè äíÿ òî ïðîñòî áåðåì
// ÄÅÍÁ ÌÅÑßÖ ÃÎÄ
// è òàðèì ê íåìó âðåìÿ îò 0 - 7 óòðà
string strTimeBegASIA=StringConcatenate (StringSubstr (strÒåêóùååÂðåìÿÒåðìèíàëà, 0, 10), " 00:00:00");
string strTimeEndASIA=StringConcatenate (StringSubstr (strÒåêóùååÂðåìÿÒåðìèíàëà, 0, 10), sTimeEndAsia);
string sTimeEndEUR =StringConcatenate (StringSubstr (strÒåêóùååÂðåìÿÒåðìèíàëà, 0, 10), sTimeEndEur);
//----
int BarsDay1=iBarShift (Symbol(), 0 , StrToTime (strTimeBegASIA), false);
int BarsDay2=iBarShift (Symbol(), 0 , StrToTime (strTimeEndASIA), false);
BarsDay=BarsDay1 - BarsDay2;
int i;
int h1=iHighest (Symbol(), 0 , MODE_HIGH, BarsDay , BarsDay2) ;
int l1=iLowest (Symbol(), 0 , MODE_HIGH, BarsDay , BarsDay2) ;
//-----
Max1=High[h1];
Min1=Low[l1];
i=iLowest (Symbol(), 0, MODE_LOW, BarsDay , BarsDay2) ;
Max2=High[i];
Min2=Low[i];
// Comment(" a "+TimeToStr(TimeCurrent( )) + " "+Max1+" "+Min1+" "+Max2+" "+Min2+" "+BarsDay+" 1 "+BarsDay1+" 2 "+BarsDay2 );
mYear =TimeYear (mDatBegin);
mMonth=TimeMonth (mDatBegin);
mDay =TimeDay (mDatBegin);
d=StringConcatenate (DoubleToStr (mYear, 0), ".", DoubleToStr (mMonth, 0), ".", DoubleToStr (mDay, 0), " 07:00");
//----
ObjectSet (noR + d, OBJPROP_RAY, false);
ObjectSet (noR + d, OBJPROP_COLOR, OrangeRed);
ObjectSet (noR + d, OBJPROP_TIME1, StrToTime (strTimeBegASIA ));
ObjectSet (noR + d, OBJPROP_PRICE1, Max1);
ObjectSet (noR + d, OBJPROP_TIME2, StrToTime (sTimeEndEUR));
ObjectSet (noR + d, OBJPROP_PRICE2, Max1);
//
ObjectSet (noP + d, OBJPROP_RAY,false);
ObjectSet (noP + d, OBJPROP_COLOR,OrangeRed);
ObjectSet (noP + d, OBJPROP_TIME1, StrToTime (strTimeBegASIA));
ObjectSet (noP + d, OBJPROP_PRICE1, Min2 + (Max1 - Min2)/2);
ObjectSet (noP + d, OBJPROP_TIME2, StrToTime (strTimeEndASIA));
ObjectSet (noP + d, OBJPROP_PRICE2, Min2 + (Max1 - Min2)/2);
//
ObjectSet (noS + d, OBJPROP_RAY, false);
ObjectSet (noS + d, OBJPROP_COLOR, SandyBrown);
ObjectSet (noS + d, OBJPROP_TIME1, StrToTime (strTimeBegASIA));
ObjectSet (noS + d, OBJPROP_PRICE1, Min2);
ObjectSet (noS + d, OBJPROP_TIME2, StrToTime (sTimeEndEUR));
ObjectSet (noS + d, OBJPROP_PRICE2, Min2);
}
return(0);
}
//+------------------------------------------------------------------+
Comments