_BZ_History_mtf
Download scriptThis tool is designed to assist traders by visually identifying specific price zones based on the opening price of a defined time period (such as the 4-hour open). Instead of manual calculation, the script automatically plots these levels directly onto your trading chart.
Core Logic and Functionality
The script operates by looking at a specific timeframe that you can customize. For every bar on your current chart, it "looks back" to find the opening price of the corresponding period on that larger timeframe. Once it identifies that opening price, it performs the following actions:
- Reference Point: It establishes the "Open" price as the central anchor for its calculations.
- Zone Mapping: From that central open price, the script calculates four distinct price levels to create two mirrored zones:
- Upper Zones (Buy/Sell Interest): It projects levels above the opening price based on a user-defined "straddle width" and an additional "channel" value. This helps define the upper boundary of a potential trading area.
- Lower Zones (Sell/Buy Interest): It projects corresponding levels below the opening price using the same width logic.
- Visual Representation: The script then draws these four levels as lines or symbols on your chart. By doing this, it creates a visual "map" of where significant price action might occur relative to the session's start.
Key User Controls
The behavior of the logic can be adjusted through several customizable settings:
- Period Selection: You can define which specific timeframe (e.g., H4) the script should reference to find the opening prices.
- Width and Channel: You can adjust how far the "zones" extend above and below the opening price, allowing you to widen or narrow the visual area depending on your trading strategy.
- Visual Customization: The tool allows you to choose the drawing style (such as solid lines, dots, or dashes) and the specific symbols (WingDings) used to mark these levels, ensuring the chart remains clear and easy to read.
In summary, this script automates the process of marking out "zones" around a session's opening price, providing traders with a consistent visual reference for identifying potential areas of interest without having to manually plot lines for every historical session.
//+------------------------------------------------------------------+
//| MTC.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
/*
Constant Value Description
DRAW_LINE 0 Drawing line.
DRAW_SECTION 1 Drawing sections.
DRAW_HISTOGRAM 2 Drawing histogram.
DRAW_ARROW 3 Drawing arrows (symbols).
DRAW_ZIGZAG 4 Drawing sections between even and odd indicator buffers.
DRAW_NONE 12 No drawing.
Drawing style. Valid when width=1. It can be any of the following values:
Constant Value Description
STYLE_SOLID 0 The pen is solid.
STYLE_DASH 1 The pen is dashed.
STYLE_DOT 2 The pen is dotted.
STYLE_DASHDOT 3 The pen has alternating dashes and dots.
STYLE_DASHDOTDOT 4 The pen has alternating dashes and double dots.
*/
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 White
#property indicator_color4 Red
#property indicator_color5 Red
//---- input parameters
extern int myWingDingL = 250 ;
extern int myWingDingO = 250 ;
extern int myWingDingS = 250 ;
extern int myLine = DRAW_LINE ;
extern int myStyle = STYLE_DOT ;
extern int myPeriod = 240;
extern string session_name = "H4 Open";
extern int straddle_width=3;
extern int channel=1;
double lgt[];
double lgb[];
double opn[];
double sht[];
double shb[];
double open_price;
double rates_h1[2][6];
string OP, BZ, BZW, SZ, SZW;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0, lgt);
SetIndexBuffer(1, lgb);
SetIndexBuffer(2, opn);
SetIndexBuffer(3, sht);
SetIndexBuffer(4, shb);
//---- indicators
SetIndexStyle(0,myLine, myStyle);
SetIndexArrow(0,myWingDingL);
SetIndexBuffer(0,lgt);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,myLine, myStyle);
SetIndexArrow(1,myWingDingL);
SetIndexBuffer(1,lgb);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,myLine, myStyle);
SetIndexArrow(2,myWingDingO);
SetIndexBuffer(2,opn);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,myLine, myStyle);
SetIndexArrow(3,myWingDingS);
SetIndexBuffer(3,sht);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,myLine, myStyle);
SetIndexArrow(4,myWingDingS);
SetIndexBuffer(4,shb);
SetIndexEmptyValue(4,0.0);
//----
//---- indicators
OP = "Open " + session_name;
BZ = "Buy zone " + session_name;
BZW = "Buy zone width " + session_name;
SZ = "Sell zone " + session_name;
SZW = "Sell zone width " + session_name;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int i, t, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
//----
for(i = limit - 1; i >= 0; i--)
{
//
// if( TimeDay(Time[i]) != TimeDay(Time[i+1]) ) { int t = i ; }
t = iBarShift(Symbol(), myPeriod, Time[i], false);
// opn[i] = iOpen(Symbol(), myPeriod,t);
opn[i] = iOpen(NULL, myPeriod,t);
lgt[i] = opn[i]+straddle_width*Point ;
lgb[i] = opn[i]+(straddle_width+channel)*Point ;
sht[i] = opn[i]-straddle_width*Point ;
shb[i] = opn[i]-(straddle_width+channel)*Point ;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments