MTF_Supertrand2_BarsM6

Author: Copyright � 2006, Eli hayun.
MTF_Supertrand2_BarsM6

The provided script is a specialized multi-timeframe (MTF) analysis tool designed to help traders visualize market trends across different time horizons simultaneously. Instead of forcing a trader to switch between various charts to see what is happening on different scales, this script pulls that data into a single view.

Core Logic and Functionality

Multi-Timeframe Integration The primary purpose of this logic is to monitor four distinct timeframes (H1, H4, D1, and W1) at once. By aggregating this data, the script allows you to see the "big picture" (weekly and daily trends) while still observing shorter-term movements (hourly trends).

Trend Detection Mechanism The script relies on a secondary underlying calculation called "Super Trend 2." It looks for specific price action signals—specifically identifying whether the market is in an "Up" or "Down" state.

  • It evaluates high and low price points based on a set number of periods.
  • It compares these values to determine the direction of the trend.

Data Visualization Rather than drawing complex lines that might clutter the screen, this script uses a system of visual markers (arrows).

  • Directional Signaling: When the logic detects an upward trend on any of the monitored timeframes, it triggers a specific marker. Conversely, if it detects a downward trend, it triggers a different set of markers.
  • Color Coding: The script uses distinct colors (Maroon for one direction and Dark Green for the other) to provide immediate visual feedback on market sentiment across all four timeframes.

Dynamic Time Alignment One of the most sophisticated parts of this logic is how it handles time synchronization. Because a "Daily" bar covers 24 hours while an "Hourly" bar covers only one, the script automatically calculates the correct "shift." This ensures that the data displayed for a Weekly trend aligns perfectly with the current moment on your Hourly chart, preventing any chronological confusion.

Summary for the User

In simple terms, this script acts as a "multi-lens" telescope. It looks at four different timeframes simultaneously and places colored signals on your current screen. If the markers are Green, the trend is positive across those timeframes; if they are Maroon, the trend is negative. This allows you to make informed decisions based on how all timeframes are aligning in real-time.

Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
MTF_Supertrand2_BarsM6
//+------------------------------------------------------------------+
//|                                         MTF_Supertrend2_Bars.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli hayun."
#property link      "http://www.elihayun.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_buffers 8
#property indicator_color1 Maroon
#property indicator_color2 Maroon
#property indicator_color3 Maroon
#property indicator_color4 Maroon
#property indicator_color5 DarkGreen
#property indicator_color6 DarkGreen
#property indicator_color7 DarkGreen
#property indicator_color8 DarkGreen
//---- 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_H1;
extern int    TF3  = PERIOD_H4;
extern int    TF2  = PERIOD_D1;
extern int    TF1  = PERIOD_W1;

//+------------------------------------------------------------------+
//| 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 = Bars-counted_bars;
 limit = MathMax(limit,TF1/Period());
 limit = MathMax(limit,TF2/Period());
 limit = MathMax(limit,TF3/Period());
 limit = MathMax(limit,TF4/Period());
 limit = MathMin(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