Author: omelette
MTF_MA

This tool is designed to provide traders with a specialized visual aid on their trading charts. Its primary purpose is to calculate and display a Moving Average (MA)—a common technical analysis line that helps smooth out price fluctuations to reveal underlying trends—but with a unique multi-timeframe capability.

How the Logic Works

Unlike standard indicators that only look at the current chart's timeframe, this script allows you to view data from a different time period simultaneously. Here is the step-by-step logic of how it processes information:

  • Multi-Timeframe Integration: The core strength of this script is its ability to "reach out" and pull data from a specific timeframe that may be different from what you are currently viewing. For example, if you are looking at a 1-minute chart, you can set this tool to display a moving average based on the 1-hour chart.
  • Customizable Parameters: The script provides four main "knobs" for the user to adjust:
    1. MA Type: This allows you to choose the specific mathematical method used to calculate the average (e.g., Simple, Exponential, etc.).
    2. MA Price: This determines which price point the calculation is based on (such as the closing price, opening price, etc.).
    3. MA Timeframe: This is where you define the "higher" or "lower" timeframe from which the data will be pulled.
    4. MA Period: This defines the "lookback" window—how many previous candles the script should average together to determine the current line value.
  • Real-Time Processing: The script continuously scans the history of the market bars. It performs the calculation for every point on the chart, ensuring that the resulting line is smooth and accurately represents the historical trend as defined by your chosen settings.
  • Visual Output: Once the calculations are complete, the script renders a solid yellow line directly on your main price chart. This provides a clear visual signal of the trend based on the broader timeframe you selected, helping you identify potential support, resistance, or trend reversals at a glance.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
MTF_MA
//+------------------------------------------------------------------+
//|                                                       MTF_MA.mq4 |
//|                                                         omelette |
//|                                           omelette@oceanfree.net |
//+------------------------------------------------------------------+
#property copyright "omelette"
#property link      "omelette@oceanfree.net"

#property indicator_chart_window

extern int MA_Type = 0;
extern int MA_Price = 0;
extern int MA_TF = 60;
extern int MA_Period = 10;

double MA_buff[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3,Yellow);
   SetIndexBuffer(0,MA_buff);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   int i = Bars - counted_bars + 1;
   
   while (i >= 0)
   {
    MA_buff[i] = iMA(NULL,MA_TF,MA_Period,0,MA_Type,MA_Price,i);
    
    i--;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments