ST_MultiStrend_JR_R_MTF
Download scriptThis script is designed to provide a comprehensive visual overview of market trends by combining data from multiple timeframes simultaneously into a single chart view. Instead of requiring you to switch between different windows to see what is happening on short-term and long-term scales, it "layers" this information so you can see the "big picture" at a glance.
Core Functionality
Multi-Timeframe Synchronization The primary logic of this tool is its ability to detect which timeframe chart you are currently viewing (e.g., 15-minute, 1-hour, etc.) and automatically calculate the relative "higher" timeframes. It establishes a hierarchy of three distinct trends:
- Current Trend: The data based on your active chart timeframe.
- Super Trend: Data from one level higher than your current timeframe.
- Super 2 Trend: Data from two levels higher than your current timeframe.
Data Aggregation The script fetches specific "Supertrend" data—a common technical analysis tool used to identify the direction of market movement—from all three of these levels. It processes this information and maps it onto your screen as six different visual lines:
- Two lines represent the Upward and Downward trends for your current timeframe (shown with dotted lines).
- Two lines represent the Upward and Downward trends for the first higher timeframe (shown with dashed lines).
- Two lines represent the Upward and Downward trends for the second higher timeframe (shown with solid lines).
Visual Logic and User Experience
The script uses different line styles (Dotted, Dashed, and Solid) and colors to help distinguish between these layers. This allows a trader to immediately identify:
- Confluence: When all three sets of lines are moving in the same direction, it suggests a strong, high-probability trend.
- Divergence: If the current timeframe shows one direction but the "Super 2" higher timeframe shows another, it warns the user that the immediate move might be contrary to the broader market flow.
Technical Automation
To ensure accuracy, the script handles the complex math of "time shifting." Because higher timeframes (like a 4-hour candle) contain multiple smaller candles (like 1-minute candles), the script automatically calculates which specific historical point on the smaller chart corresponds exactly to the current moment on the larger timeframe. This ensures that the data displayed is perfectly synced in real-time without manual adjustment.
//+------------------------------------------------------------------+
//| MultiStrend.mq4 |
//| Rosh |
//| http://www.alpari-idc.ru/ru/experts/articles/ |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link "http://www.alpari-idc.ru/ru/experts/articles/"
//----
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 DarkBlue
#property indicator_color3 Red
#property indicator_color4 DarkBlue
#property indicator_color5 Red
#property indicator_color6 DarkBlue
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
int myPeriod,superPeriod,super2;
//+------------------------------------------------------------------+
//| âîçâðàùàåò ïåðèîä |
//+------------------------------------------------------------------+
int PeriodNumber(int number)
{
int per_min;
switch (number)
{
case 0: per_min=PERIOD_M1;break;
case 1: per_min=PERIOD_M5;break;
case 2: per_min=PERIOD_M15;break;
case 3: per_min=PERIOD_M30;break;
case 4: per_min=PERIOD_H1;break;
case 5: per_min=PERIOD_H4;break;
default: per_min=PERIOD_D1;break;
}
return(per_min);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
bool periodNotDetect=true;
int k;
//---- indicators
SetIndexStyle(0, DRAW_LINE, STYLE_DOT, 0);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1, DRAW_LINE, STYLE_DOT, 0);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2, DRAW_LINE, STYLE_DASH, 1);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3, DRAW_LINE, STYLE_DASH, 1);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(5,ExtMapBuffer6);
//
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
SetIndexEmptyValue(2,0.0);
SetIndexEmptyValue(3,0.0);
SetIndexEmptyValue(4,0.0);
SetIndexEmptyValue(5,0.0);
//----
while(periodNotDetect)
{
if (PeriodNumber(k)==Period()) {periodNotDetect=false;break;}
k++;
}
myPeriod=k;
superPeriod=k+1;
super2=k+2;
//Print("Number Period=",myPeriod,", Period on Number=",PeriodNumber(myPeriod));
SetIndexLabel(0,"UP_Strend-"+Period());
SetIndexLabel(1,"Down_Strend-"+Period());
SetIndexLabel(2,"UP_Strend-"+PeriodNumber(superPeriod));
SetIndexLabel(3,"Down_Strend-"+PeriodNumber(superPeriod));
SetIndexLabel(4,"UP_Strend-"+PeriodNumber(super2));
SetIndexLabel(5,"Down_Strend-"+PeriodNumber(super2));
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int limit,limit1,limit2,k1,k2;
double var1,var2;
double m1,m2;
if (counted_bars==0)
{
limit=Bars-1;
limit1=iBars(Symbol(),PeriodNumber(superPeriod));
limit2=iBars(Symbol(),PeriodNumber(super2));
if (limit1==0) return;
if (limit2==0) return;
for(int k=limit;k>=0;k--)
{
m1=iCustom(NULL,0,"Supertrend_jr",1,k);
if (m1>10000) m1=0;
ExtMapBuffer1[k]=m1;
m2=iCustom(NULL,0,"Supertrend_jr",0,k);
if (m2>10000) m2=0;
ExtMapBuffer2[k]=m2;
k1=iBarShift(NULL,PeriodNumber(superPeriod),Time[k]);
var1=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend_jr",1,k1);
if (var1>10000) var1=0;
var2=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend_jr",0,k1);
if (var2>10000) var2=0;
ExtMapBuffer3[k]=var1;
ExtMapBuffer4[k]=var2;
k2=iBarShift(NULL,PeriodNumber(super2),Time[k]);
var1=iCustom(NULL,PeriodNumber(super2),"Supertrend_jr",1,k2);
if (var1>10000) var1=0;
var2=iCustom(NULL,PeriodNumber(super2),"Supertrend_jr",0,k2);
if (var2>10000) var2=0;
ExtMapBuffer5[k]=var1;
ExtMapBuffer6[k]=var2;
}
}
else
{
limit=Bars-counted_bars;
for(k=limit;k>=0;k--)
{
m1=iCustom(NULL,0,"Supertrend",1,k);
if (m1>10000) m1=0;
ExtMapBuffer1[k]=m1;
m2=iCustom(NULL,0,"Supertrend_jr",0,k);
if (m2>10000) m2=0;
ExtMapBuffer2[k]=m2;
k1=iBarShift(NULL,PeriodNumber(superPeriod),Time[k]);
var1=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend_jr",1,k1);
if (var1>10000) var1=0;
var2=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend_jr",0,k1);
if (var2>10000) var2=0;
ExtMapBuffer3[k]=var1;
ExtMapBuffer4[k]=var2;
k2=iBarShift(NULL,PeriodNumber(super2),Time[k]);
var1=iCustom(NULL,PeriodNumber(super2),"Supertrend_jr",1,k2);
if (var1>10000) var1=0;
var2=iCustom(NULL,PeriodNumber(super2),"Supertrend_jr",0,k2);
if (var2>10000) var2=0;
ExtMapBuffer5[k]=var1;
ExtMapBuffer6[k]=var2;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments