MultiStrend

Download script
Author: Rosh
MultiStrend

This script is designed as a multi-layered technical analysis tool for the MetaTrader platform. Its primary purpose is to visualize "Supertrend" data across three different timeframes simultaneously on a single chart, allowing traders to see market direction at multiple scales at once.

Core Functionality

The logic operates by identifying the current timeframe you are viewing (for example, a 1-hour chart) and automatically calculating two higher timeframes relative to it. By doing this, the script creates a "stacked" visual representation of market trends:

  • Current Timeframe: It captures the immediate trend data based on the chart period you currently have open.
  • Super Period: It pulls data from the next chronological timeframe up (e.g., if you are on 15-minute charts, it looks at the 30-minute trend).
  • Super2 Period: It pulls data from two timeframes higher (e.g., if you are on 15-minute charts, it looks at the 1-hour trend).

How the Logic Works

  1. Automatic Detection: When the script is loaded, it analyzes your current chart settings. Instead of requiring you to manually type in different timeframes, it detects where you are and automatically assigns the next two logical steps in the trading hierarchy.
  2. Data Synchronization: Because different timeframes have different numbers of candles, the script performs a "time-shift" calculation. It ensures that the data points displayed from the higher timeframes align perfectly with the current price candle on your screen. This prevents the data from appearing "shifted" or out of sync.
  3. Trend Mapping: The script retrieves two distinct types of information for each of the three timeframes: an upward trend signal and a downward trend signal.
  4. Visual Output: It plots these six distinct data streams onto your chart using different line styles (dots, dashes, and solid lines) and colors. This allows you to visually distinguish between the immediate market sentiment and the broader long-term trends.

Summary for the User

Essentially, this tool acts as a "trend aggregator." Instead of having to flip back and forth between three different charts to see if the short-term, medium-term, and long-term trends are all moving in the same direction, this script overlays that information onto one screen. It provides a bird's-eye view of market momentum, helping you identify when multiple timeframes are aligned in favor of a specific trade direction.

Miscellaneous
Implements a curve of type %1
19 Views
0 Downloads
0 Favorites
MultiStrend
//+------------------------------------------------------------------+
//|                                                  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",1,k);
         if (m1>10000) m1=0;
         ExtMapBuffer1[k]=m1;

         m2=iCustom(NULL,0,"Supertrend",0,k);
         if (m2>10000) m2=0;
         
         ExtMapBuffer2[k]=m2;
         k1=iBarShift(NULL,PeriodNumber(superPeriod),Time[k]);
         var1=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend",1,k1);
         if (var1>10000) var1=0;
         
         var2=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend",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",1,k2);
         if (var1>10000) var1=0;

         var2=iCustom(NULL,PeriodNumber(super2),"Supertrend",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",0,k);
         if (m2>10000) m2=0;
         ExtMapBuffer2[k]=m2;

         k1=iBarShift(NULL,PeriodNumber(superPeriod),Time[k]);
         var1=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend",1,k1);
         if (var1>10000) var1=0;
         
         var2=iCustom(NULL,PeriodNumber(superPeriod),"Supertrend",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",1,k2);
         if (var1>10000) var1=0;

         var2=iCustom(NULL,PeriodNumber(super2),"Supertrend",0,k2);
         if (var2>10000) var2=0;

         ExtMapBuffer5[k]=var1;
         ExtMapBuffer6[k]=var2;
         
         
         
         }
         
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments