Price_BarsM2_MTF
Download scriptThis script is designed for MetaTrader users who need to visualize price action from a higher timeframe directly on their current lower timeframe chart. It acts as a bridge, allowing you to see the "big picture" (such as hourly or daily movements) while still looking at the granular details of smaller timeframes (like minutes).
Core Functionality
The primary goal of this tool is to project price data from a selected higher timeframe onto your active trading screen. Instead of constantly switching tabs between different charts, this script captures the essential price points—specifically the Open, High, Low, and Close prices—of a larger time period and displays them as visual histograms on your current chart.
How the Logic Works
- Timeframe Synchronization: You can specify exactly which higher timeframe you want to track (e.g., watching the Daily movement while trading on a 15-minute chart). The script automatically calculates the correct alignment so that the data matches up with your current view.
- Data Extraction: The script scans through historical data to find the specific "candles" of the higher timeframe. It identifies the exact price levels for each bar:
- The highest point reached (High).
- The lowest point reached (Low).
- The starting price (Open).
- The ending price (Close).
- Visual Mapping: Once the data is gathered, it draws four distinct histogram lines. It intelligently organizes these lines based on whether a candle was "bullish" (closed higher than it opened) or "bearish" (closed lower than it opened), ensuring the visual representation remains consistent and easy to read.
- Customizable Display: The logic includes specific settings to control how far back the data should be calculated, how much the visual elements are shifted for better clarity, and whether you want to see a simplified view of the price action or a more detailed multi-bar representation.
Summary of Benefits
Essentially, this tool removes the "mental math" required to keep track of larger trends. By visualizing the high, low, open, and close of a major timeframe on your current chart, it provides a clear visual boundary of where the "big money" is moving, helping you stay aligned with the broader market trend while making your immediate trading decisions.
//+------------------------------------------------------------------+
//| Price_MTF .mq4 |
//| Copyright © 2006, Keris2112 |
//| 2008forextsd ki pubilc |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Keris2112"
#property link "public" // Keris f-la; IgorAd Mladen; KI put together :)
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_color3 Red
#property indicator_color4 DodgerBlue
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 5
#property indicator_width4 5
//----
extern int TimeFrame = 60;
extern int Shift=0;
extern int xShift=0;
extern bool SetShift0ToTFBarCloseTime = true;
extern bool ShowMultipleBars = false;
extern int MaxBarsToCount = 1500;
extern string note_timeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN";
//----
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
int ShiftToBarClose;
//+------------------------------------------------------------------+
int init()
{
//----
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexBuffer(3, ExtMapBuffer4);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexStyle(3,DRAW_HISTOGRAM);
//----
if(TimeFrame==0) TimeFrame = Period();
if (SetShift0ToTFBarCloseTime)ShiftToBarClose =TimeFrame/Period()-1;
SetIndexShift(0, Shift+xShift*TimeFrame/Period()+ShiftToBarClose);
SetIndexShift(1, Shift+xShift*TimeFrame/Period()+ShiftToBarClose);
SetIndexShift(2, Shift+xShift*TimeFrame/Period()+ShiftToBarClose);
SetIndexShift(3, Shift+xShift*TimeFrame/Period()+ShiftToBarClose);
switch(TimeFrame)
{
case 1 : string TimeFrameStr= "M1"; break;
case 5 : TimeFrameStr= "M5"; break;
case 15 : TimeFrameStr= "M15"; break;
case 30 : TimeFrameStr= "M30"; break;
case 60 : TimeFrameStr= "H1"; break;
case 240 : TimeFrameStr= "H4"; break;
case 1440 : TimeFrameStr= "D1"; break;
case 10080 : TimeFrameStr= "W1"; break;
case 43200 : TimeFrameStr= "MN1"; break;
default : TimeFrameStr= "TF0";
}
IndicatorShortName("Price ["+TimeFrameStr+"]");
if (TimeFrame<Period()) TimeFrame=Period();
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
int start()
{
double open, close, high, low;
datetime TimeArray[];
int i,limit,y=0,counted_bars=IndicatorCounted();
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
limit= Bars-counted_bars;
limit= MathMax(limit,TimeFrame/Period());
limit= MathMin(limit,MaxBarsToCount);
for(i=0,y=0;i<limit;i++)
{
if (Time[i]<TimeArray[y]) y++;
open = iOpen (NULL,TimeFrame,y);
close= iClose(NULL,TimeFrame,y);
high = iHigh (NULL,TimeFrame,y);
low = iLow (NULL,TimeFrame,y);
if (!ShowMultipleBars)
{
if(Time[i]==TimeArray[y])
{
if (open<close)
{
ExtMapBuffer1[i]=low;
ExtMapBuffer2[i]=high;
}
else
{
ExtMapBuffer1[i]=high;
ExtMapBuffer2[i]=low;
}
ExtMapBuffer3[i]=open;
ExtMapBuffer4[i]=close;
}
}
else
{
if (open<close)
{
ExtMapBuffer1[i]=low;
ExtMapBuffer2[i]=high;
}
else
{
ExtMapBuffer1[i]=high;
ExtMapBuffer2[i]=low;
}
ExtMapBuffer3[i]=open;
ExtMapBuffer4[i]=close;
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments