_2523MTF_TMA

Download script
Author: Copyright � 2005, MetaQuotes Software Corp.
_2523MTF_TMA

This script is designed to provide traders with a multi-timeframe visual analysis tool. Its primary purpose is to overlay price data from four different time periods simultaneously onto a single chart, allowing you to see broader market trends while looking at smaller price movements.

Core Functionality

The tool retrieves and displays information for four specific timeframes: 5 Minutes (M5), 15 Minutes (M15), 30 Minutes (M30), and 1 Hour (H1). By consolidating these into one view, the script helps you identify how different "speeds" of the market are interacting with each other at any given moment.

How it Works

To achieve this, the script performs the following logical steps:

  • External Data Integration: It connects to a specific external indicator (the "TMA") and pulls its calculations from the four mentioned timeframes. Instead of you having to open four different windows to see what is happening on the 5-minute chart versus the 1-hour chart, the script does this work automatically in the background.
  • Time Synchronization: Because different timeframes (like 5 minutes and 60 minutes) have different numbers of bars, the script includes a "time-matching" logic. It scans through the historical data to ensure that the values displayed on your current chart correspond correctly to the specific points in time on the larger and smaller timeframes.
  • Visual Mapping: The results of these calculations are then plotted as four distinct lines on your screen. This allows for a "top-down" view of the market, where you can see if the short-term momentum (M5/M15) is aligned with or diverging from the longer-term trend (M30/H1).

Key Features

  • Multi-Timeframe Visibility: View four different time horizons at once without cluttering your workspace with multiple charts.
  • Automated Data Fetching: The script automatically handles the complex math of pulling data from different periods and aligning it with your current view.
  • Customizable Inputs: It allows for adjustable parameters (such as the "Periods" or "ApplyTo" settings) so that you can fine-tune how the underlying data is calculated to suit your specific trading strategy.
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
_2523MTF_TMA
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                            #MTF_4_CoeffoLine.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"





#property indicator_chart_window

#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Blue
#property indicator_color4 Blue
//---- input parameters

//---- buffers
double Buffer_M5[];
double Buffer_M15[];
double Buffer_M30[];
double Buffer_H1[];


datetime dt5[200], dt15[200], dt30[200], dth1[200];   

extern string CustomIndicator = "TMA";
extern int CustomIndIndex = 0;
extern int PRD_1 = 5;
extern int PRD_2 = 15;
extern int PRD_3 = 30;
extern int PRD_4 = 60;

//-----------------------
extern int       Periods=30;
extern int       ApplyTo=0;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buffer_M5);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Buffer_M15);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Buffer_M30);

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Buffer_H1);
   
   IndicatorShortName("MTF_4_TMA M5,M15,M30,M60");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit, shift;
   if(counted_bars<0) return(-1);
   if (counted_bars==0) limit=Bars-1;  // limit = Bars-MinBars-1;
//---- last counted bar will be recounted
   if(counted_bars>0) limit=Bars-counted_bars;
   limit--;

   int i5 = 0, i15 = 0, i30 = 0, ih1 = 0;

   static bool fft = true;
   
   //if (NewBar()) // Update array every 15 minutes
   {
      ArrayCopySeries(dt5,MODE_TIME,Symbol(),PRD_1); 
      ArrayCopySeries(dt15,MODE_TIME,Symbol(),PRD_2); 
      ArrayCopySeries(dt30,MODE_TIME,Symbol(),PRD_3); 
      ArrayCopySeries(dth1,MODE_TIME,Symbol(),PRD_4); 
   }   
   
   if ((fft) && (Symbol() == "EURUSD"))
   {
      fft = false;
      datetime d = iTime(NULL, PERIOD_D1, 0);
      for (int j=0; j<80; j++)
      {
         Print(j,") ",dt5[j]-d," ",dt15[j]-d, " ", dt30[j]-d," ", dth1[j]-d);
      }
   }
   for(int i=0; i<limit; i++)
   {   
      datetime ddt = iTime(NULL, 0, i);
      if (ddt<dt5[i5]) i5++;
      if (ddt<dt15[i15]) i15++;
      if (ddt<dt30[i30]) i30++;
      if (ddt<dth1[ih1])  ih1++;
      
      
       double COG5=iCustom(NULL,PERIOD_M5,CustomIndicator,Periods,ApplyTo,CustomIndIndex,i5);
       double COG5S=0;
      
      
      double  COG15=iCustom(NULL,PERIOD_M15,CustomIndicator,Periods,ApplyTo,CustomIndIndex,i15);
      double  COG15S=0;
      
      
     double   COG30=iCustom(NULL,PERIOD_M30,CustomIndicator,Periods,ApplyTo,CustomIndIndex,i30);
     double  COG30S=0;
      
      
      double COGH1=iCustom(NULL,PERIOD_H1,CustomIndicator,Periods,ApplyTo,CustomIndIndex,ih1);
      double COGH1S=0;
      
      
      Buffer_M5[i] = COG5;  
      Buffer_M15[i] = COG15;  
      Buffer_M30[i]  = COG30; 
      Buffer_H1[i]  = COGH1;  
   }

   return(0);
  }
//+------------------------------------------------------------------+

/*
bool NewBar()
{
   static datetime dt = 0;
   if (dt != iTime(NULL, PERIOD_M15, 0))
   {
      dt = iTime(NULL, PERIOD_M15, 0);
   }
   return(false);
}
*/

Comments