MTF_Supertrand2_BarsM_M5H1
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader platform. Its primary purpose is to aggregate and visualize trend data from multiple different timeframes simultaneously, allowing traders to see "the big picture" without constantly switching between different charts.
Core Functionality
The logic operates by pulling data from four distinct timeframes (configured as M5, M15, M30, and H1) and condensing that information into a single view. It specifically looks for a "SuperTrend" signal—a common trading metric used to determine if the market is currently in an upward or downward move.
How it Works
The script follows a systematic process to provide visual cues on your chart:
- Multi-Timeframe Synchronization: Instead of just showing you what is happening on your current screen, the script "scans" four other timeframes at once. It identifies the corresponding price point for each timeframe relative to the current moment in time.
- Trend Detection: For each of those four timeframes, it checks the relationship between specific high and low price boundaries. It is essentially asking: "Is the trend on the 5-minute chart bullish? Is it also bullish on the 1-hour chart?"
- Visual Signaling: Once the script determines the trend for each timeframe, it places visual markers (arrows) on your main chart. These markers serve as a shorthand for the market's momentum:
- If the trend is identified as "Up" on a specific timeframe, it triggers one set of markers.
- If the trend is identified as "Down," it triggers a different set of markers.
- Color Coordination: The script uses color-coding (Red/FireBrick for bearish signals and Green for bullish signals) to make it easy to distinguish at a glance which timeframes are supporting which market direction.
Practical Use for Traders
The logic is designed to give you a high-level summary of market sentiment. By looking at the markers provided by this script, a trader can quickly see if all timeframes are aligned (confluence). For example, if the signals for all four timeframes are green, it indicates a strong bullish trend across the board; conversely, if they are mixed, it suggests a period of high volatility or transition in the market.
//+------------------------------------------------------------------+
//| MTF_Supertrend2_Bars.mq4 ik |
//| Copyright © 2005, Jason Robinson (jnrtrading). |
//| http://www.jnrtrading.co.uk www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © Eli hayun. © 2005, Jason Robinson"
#property link "http://www.elihayun.com http://www.jnrtrading.co.uk"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_buffers 8
#property indicator_color1 FireBrick
#property indicator_color2 FireBrick
#property indicator_color3 FireBrick
#property indicator_color4 FireBrick
#property indicator_color5 Green
#property indicator_color6 Green
#property indicator_color7 Green
#property indicator_color8 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
extern string CustomIndicator = "Super_Trend2";
extern int Maxbars = 1000;
extern int NbPeriods = 10;
//extern int LSMA_Period = 5;
extern int TF4 = PERIOD_M5;
extern int TF3 = PERIOD_M15;
extern int TF2 = PERIOD_M30;
extern int TF1 = PERIOD_H1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,110);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,110);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,110);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,110);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,110);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,110);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,110);
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,110);
SetIndexBuffer(7,ExtMapBuffer8);
SetIndexEmptyValue(7,0.0);
//----
SetIndexLabel(0,"MTF_ST2("+TF4+")");
SetIndexLabel(1,"MTF_ST2("+TF3+")");
SetIndexLabel(2,"MTF_ST2("+TF2+")");
SetIndexLabel(3,"MTF_ST2("+TF1+")");
SetIndexLabel(4,"MTF_ST2("+TF4+")");
SetIndexLabel(5,"MTF_ST2("+TF3+")");
SetIndexLabel(6,"MTF_ST2("+TF2+")");
SetIndexLabel(7,"MTF_ST2("+TF1+")");
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int limit;
int TF[] = {0,0,0,0};
TF[0] = TF1;
TF[1] = TF2;
TF[2] = TF3;
TF[3] = TF4;
limit = MathMin(counted_bars,Maxbars);
if (limit ==0)
limit = Maxbars;
for (int ii=0; ii<limit; ii++)
{
ExtMapBuffer1[ii] = 0;
ExtMapBuffer2[ii] = 0;
ExtMapBuffer3[ii] = 0;
ExtMapBuffer4[ii] = 0;
ExtMapBuffer5[ii] = 0;
ExtMapBuffer6[ii] = 0;
ExtMapBuffer7[ii] = 0;
ExtMapBuffer8[ii] = 0;
for (int jj=0; jj<4; jj++)
{
int y = iBarShift(NULL, TF[jj], Time[ii]);
SetIndicator(GetCustomBars(TF[jj], y), jj, ii);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
bool GetCustomBars(int TF, int shift)
{
double h = iCustom(Symbol(), TF, CustomIndicator, NbPeriods, 1, shift);
double l = iCustom(Symbol(), TF, CustomIndicator, NbPeriods, 2, shift);
return(h<l);
}
void SetIndicator(bool isUP, int ind, int shift)
{
if (isUP)
{
switch (ind)
{
case 3: ExtMapBuffer1[shift] = ind+1; break;
case 2: ExtMapBuffer2[shift] = ind+1; break;
case 1: ExtMapBuffer3[shift] = ind+1; break;
case 0: ExtMapBuffer4[shift] = ind+1; break;
}
} else {
switch (ind)
{
case 3: ExtMapBuffer5[shift] = ind+1; break;
case 2: ExtMapBuffer6[shift] = ind+1; break;
case 1: ExtMapBuffer7[shift] = ind+1; break;
case 0: ExtMapBuffer8[shift] = ind+1; break;
}
}
}
Comments