MTF_5TFx5MA[sw]
Download scriptThis script is a specialized technical analysis tool designed for the MetaTrader trading platform. Its primary purpose is to allow traders to visualize market trends from multiple different timeframes simultaneously within a single viewing window.
Core Functionality
The main logic of this script revolves around "Multi-Timeframe" (MTF) analysis. Instead of forcing a trader to switch back and forth between different charts (such as moving from a 1-hour chart to a Daily chart) to see the "big picture," this tool overlays data from all those different timeframes onto one single screen.
How It Works
The script calculates five distinct Moving Averages (MAs) at once. Each of these lines represents a specific timeframe, which you can customize independently:
- Multi-Timeframe Synchronization: The logic automatically calculates where the price was on a higher or lower timeframe relative to the current candle on your screen. It "syncs" this data so that the lines remain accurate regardless of which chart period you are currently viewing.
- Independent Customization: Each of the five lines can be configured with its own unique settings, including:
- Timeframe: (e.g., one line might show Weekly data, another Hourly, another Minute-based).
- Period: The mathematical "lookback" length for the moving average.
- Method: The specific type of moving average calculation used (such as Simple, Exponential, etc.).
- Price Type: Whether the calculation is based on the opening price, closing price, high, low, or a weighted average of these values.
Visual Representation
The script organizes these five data streams into a separate window on your trading platform. It assigns different colors and line thicknesses to each average, allowing you to distinguish between them at a glance. By observing how these lines interact—for instance, seeing if a short-term trend aligns with a long-term trend—traders can better identify market momentum and potential reversal points without cluttering their main price chart.
//+------------------------------------------------------------------+
//| MTF_5TFx5MA based: #RSI-3TF.mq4 ik |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| |
//| 29.10.2005 Ìîäåðíèçàöèÿ Êèì Èãîðü Â. aka KimIV |
//| http://www.kimiv.ru |
//|code change by Alex.Piech.FinGeR; mod.fxbs fx-tsd.com |
//|http://www.forex-tsd.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Maroon
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 DodgerBlue
#property indicator_color5 MediumSeaGreen
#property indicator_width1 5
#property indicator_width2 4
#property indicator_width3 3
#property indicator_width4 2
#property indicator_width5 1
//------- Âíåøíèå ïàðàìåòðû èíäèêàòîðà -------------------------------
// note: ind. colors can be changed from Color Tab only;
// colors in Inputs Tab - for refrence only;
extern color MA1_color = Maroon;
extern int TF_1 = 10080;
extern int MA1_Period = 5;
extern int MA1_method=0;
extern int MA1_applied_price=0;
extern color MA2_color = Red;
extern int TF_2 = 1440;
extern int MA2_Period = 5;
extern int MA2_method=0;
extern int MA2_applied_price=0;
extern color MA3_color = Blue;
extern int TF_3 = 240;
extern int MA3_method=0;
extern int MA3_applied_price=0;
extern int MA3_Period = 5;
extern color MA4_color = DodgerBlue;
extern int TF_4 = 60;
extern int MA4_Period = 5;
extern int MA4_method=0;
extern int MA4_applied_price=0;
extern color MA5_color = MediumSeaGreen;
extern int TF_5 = 0;
extern int MA5_Period = 5;
extern int MA5_method=0;
extern int MA5_applied_price=0;
extern string note_TF = "60H1,240H4,1440D1,10080W1,43200MN1";
extern string MA_Method = "ModeMa(SMA0,EMA1,SmmMA2,LWMA3)";
extern string MA_Price = "Price(OCHLMdTpWg)";
extern int MA1_AjShift=0;
extern int MA1_Shift=0;
extern int MA2_AjShift=0;
extern int MA2_Shift=0;
extern int MA3_AjShift=0;
extern int MA3_Shift=0;
extern int MA4_AjShift=0;
extern int MA4_Shift=0;
extern int MA5_AjShift=0;
extern int MA5_Shift=0;
extern string colors = "InputsTabColors-4refrenceOnly";
//extern int NumberOfBars = 3000; // Êîëè÷åñòâî áàðîâ îáñ÷¸òà (0-âñå)
//---- input parameters
/*************************************************************************
PERIOD_M1 1
PERIOD_M5 5
PERIOD_M15 15
PERIOD_M30 30
PERIOD_H1 60
PERIOD_H4 240
PERIOD_D1 1440
PERIOD_W1 10080
PERIOD_MN1 43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------
PRICE_CLOSE 0 Close price.
PRICE_OPEN 1 Open price.
PRICE_HIGH 2 High price.
PRICE_LOW 3 Low price.
PRICE_MEDIAN 4 Median price, (high+low)/2.
PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.
You must use the numeric value of the Applied Price that you want to use
when you set the 'applied_price' value with the indicator inputs.
**************************************************************************/
//------- Áóôåðû èíäèêàòîðà ------------------------------------------
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init() {
string short_name;
//---- indicator line
SetIndexStyle (0, DRAW_LINE);
SetIndexBuffer(0, Buffer1);
SetIndexStyle (1, DRAW_LINE);
SetIndexBuffer(1, Buffer2);
SetIndexStyle (2, DRAW_LINE);
SetIndexBuffer(2, Buffer3);
SetIndexStyle (3, DRAW_LINE);
SetIndexBuffer(3, Buffer4);
SetIndexStyle (4, DRAW_LINE);
SetIndexBuffer(4, Buffer5);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MTF_4TF_4MA");
//----
SetIndexLabel(0,"MA1["+TF_1+"]("+MA1_Period+")("+MA1_method+";"+MA1_applied_price+")");
SetIndexLabel(1,"MA2["+TF_2+"]("+MA2_Period+")("+MA2_method+";"+MA2_applied_price+")");
SetIndexLabel(2,"MA3["+TF_3+"]("+MA3_Period+")("+MA3_method+";"+MA3_applied_price+")");
SetIndexLabel(3,"MA4["+TF_4+"]("+MA4_Period+")("+MA4_method+";"+MA4_applied_price+")");
SetIndexLabel(4,"MA5["+TF_5+"]("+MA5_Period+")("+MA5_method+";"+MA5_applied_price+")");
//----
if(TF_1==0) TF_1 = Period();
SetIndexShift(0,MA1_AjShift+MA1_Shift*TF_1/Period());
if(TF_2==0) TF_2 = Period();
SetIndexShift(1,MA2_AjShift+MA2_Shift*TF_2/Period());
if(TF_3==0) TF_3 = Period();
SetIndexShift(2,MA3_AjShift+MA3_Shift*TF_3/Period());
if(TF_4==0) TF_4 = Period();
SetIndexShift(3,MA4_AjShift+MA4_Shift*TF_4/Period());
if(TF_5==0) TF_5 = Period();
SetIndexShift(4,MA5_AjShift+MA5_Shift*TF_5/Period());
//----
SetIndexDrawBegin(0,MA1_Period);
SetIndexDrawBegin(1,MA2_Period);
SetIndexDrawBegin(2,MA3_Period);
SetIndexDrawBegin(3,MA4_Period);
SetIndexDrawBegin(4,MA5_Period);
}
//+------------------------------------------------------------------+
//| MTF_4MA_4TF |
//+------------------------------------------------------------------+
void start() {
int LoopBegin, sh, nsb1,nsb2,nsb3,nsb4,nsb5, NumberOfBars=IndicatorCounted();
if (NumberOfBars==0) LoopBegin=Bars-1;
else LoopBegin=NumberOfBars-1;
for (sh=LoopBegin; sh>=0; sh--) {
nsb1=iBarShift(NULL, TF_1, Time[sh], False);
nsb2=iBarShift(NULL, TF_2, Time[sh], False);
nsb3=iBarShift(NULL, TF_3, Time[sh], False);
nsb4=iBarShift(NULL, TF_4, Time[sh], False);
nsb5=iBarShift(NULL, TF_5, Time[sh], False);
Buffer1[sh]=iMA(NULL, TF_1,MA1_Period,0,MA1_method,MA1_applied_price, nsb1);
Buffer2[sh]=iMA(NULL, TF_2,MA2_Period,0,MA2_method,MA2_applied_price, nsb2);
Buffer3[sh]=iMA(NULL, TF_3,MA3_Period,0,MA3_method,MA3_applied_price, nsb3);
Buffer4[sh]=iMA(NULL, TF_4,MA4_Period,0,MA4_method,MA4_applied_price, nsb4);
Buffer5[sh]=iMA(NULL, TF_5,MA5_Period,0,MA5_method,MA5_applied_price, nsb5);
}
}
//+------------------------------------------------------------------+
Comments