BatFink (Target 4)
Download scriptThis script is designed to identify and visualize specific price boundaries on your trading chart based on historical price action within defined time windows. It serves as a tool for traders who want to see how the market behaves during certain parts of the day and use those movements to establish entry zones.
Core Logic and Functionality
The primary purpose of this indicator is to analyze "price ranges" across three distinct periods of a trading day. It automatically scans historical data to determine the highs and lows of these sessions and projects that information onto your current chart.
1. Time Zone Synchronization The script includes a mechanism to handle different time zones. By allowing you to input your local time and the destination (server) time, it ensures that the calculations for "07:00," "08:00," and "12:00" align correctly with your specific geographic location or the broker's clock.
2. Period Analysis The logic divides the trading day into three specific time blocks:
- Period 1: 07:00 to 08:00
- Period 2: 08:00 to 12:00
- Rest of Day: 12:00 onwards
The script scans these segments to find the most extreme price points (the highest opening and lowest closing prices) reached during those specific windows.
3. Dynamic Boundary Projection Once the script identifies the price action from the first period (07:00–08:00), it uses that data to draw a "Zone." Instead of just showing a single line, it creates a corridor based on a user-defined number of pips.
For example, if you set your "Pips for Entry" to 100, the script will project a zone extending 100 pips above and 100 pips below the price established in the first period. This provides a visual "buffer" or area of interest for traders to monitor.
4. Automated Reset The logic is designed to be self-cleaning. It automatically detects when a new calendar day begins. When this happens, it resets all its internal calculations—clearing the previous day's highs and lows—and begins scanning the new day’s price action from scratch.
Summary for the User
In simple terms, this tool looks at what happened during the early morning session (the first hour of the day), calculates the boundaries of that movement, and draws a colored zone on your chart. This allows you to see at a glance where the market was positioned during the start of the day and helps you visualize your "entry zone" based on those specific historical movements.
//+------------------------------------------------------------------+
//| Batfink Daily Range.MT4 |
//| |
//+------------------------------------------------------------------+
/* Introduction:
Draw Line at 00:00GMT + and - 100
TimeZONE Information - Indicator can be used for different Time Zones.
For Batfink settings set to -5 for MetaQuotes demo Server
This will place home line at 00:00GMT Time
*/
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 OrangeRed
#property indicator_color2 Blue
extern int LocalTimeZone= 2;
extern int DestTimeZone= 0;
extern int PipsForEntry= 100;
double Zone1Upper[];
double Zone1Lower[];
//+------------------------------------------------------------------+
//| 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);
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 topen[2]= { 0.0, 0.0 },
tclose[2]= { 99999.9, 99999.9 };
string tfrom[3]= { "07: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]= tclose[j-1];
Zone1Lower[k]= tclose[j-1];
}
}
inperiod= j; // remember current period
}
// for the current period find idxstart, idxend and compute high/low
if (tidxstart[j]==0) {
tidxstart[j]= i;
tday= thisday;
}
tidxend[j]= i;
topen[j]= MathMax(topen[j], Open[i]);
tclose[j]= MathMin(tclose[j], Close[i]);
}
}
//------------------------------------------------------------------------
// carry forward the periods for which we have definite high/lows
//
if (inperiod>=1 && tday==thisday) { // first time period completed
Zone1Upper[i]= tclose[0] + PipsForEntry*Point;
Zone1Lower[i]= tclose[0] - PipsForEntry*Point;
}
}
//
// 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;
topen[j]= 0;
tclose[j]= 99999;
}
}
}
return (0);
}
Comments