This script is a multi-timeframe technical analysis tool designed to overlay several moving averages onto a single chart simultaneously. Its primary purpose is to allow traders to visualize price trends across different time horizons—from short-term fluctuations to long-term movements—without having to switch between various charts manually.
Core Functionality
The logic operates by calculating five distinct moving averages, each assigned to a specific timeframe. While you view your current chart (e.g., a 15-minute chart), the indicator reaches out to grab data from other timeframes—such as Hourly, Daily, Weekly, or Monthly levels—and projects those trends onto your current screen.
Key Components of the Logic:
- Multi-Timeframe Synchronization: The script uses a "shifting" logic. It calculates exactly where a specific bar on a larger timeframe (like a Day) corresponds to the current time on a smaller timeframe (like a Minute). This ensures that the lines displayed are chronologically accurate and perfectly aligned with the current price action.
- Customizable Timeframes: You can define five independent timeframes. For example, you can set one line to represent the Weekly trend, another for the Daily trend, and another for the Hourly trend.
- Variable Averaging Methods: Each of the five lines can be configured with different mathematical calculation methods (such as Simple, Exponential, Smoothed, or Linear Weighted). This allows you to choose how "reactive" or "smooth" each specific timeframe's line appears on your chart.
- Price Source Flexibility: The tool allows for customization regarding which price point is used for the calculation. You can choose to base the averages on the Closing price, Opening price, High/Low extremes, or various weighted averages (like Median or Typical prices).
- Visual Differentiation: To ensure clarity, each of the five moving averages can be assigned different colors and line thicknesses. This helps traders instantly distinguish between short-term "noise" and long-term structural trends at a glance.
Practical Application
By using this logic, a trader can see a "big picture" summary on one screen. If the lines for the Daily and Weekly timeframes are pointing upward while the shorter timeframe line is dipping, a trader might interpret this as a temporary pullback within a larger bullish trend. It effectively condenses complex, multi-chart analysis into a single, streamlined visual representation.
//+------------------------------------------------------------------+
//| 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_chart_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