Better_M5_1

Download script
Author: Copyright � 2007, MetaQuotes Software Corp.
Better_M5_1

The Better_MA script is a specialized technical analysis tool designed to provide traders with a multi-dimensional view of market trends by synchronizing data across different timeframes. Rather than looking at the price action in isolation, this tool aggregates information from several distinct periods simultaneously to create a more comprehensive overview of market momentum.

Core Logic and Functionality

The primary objective of this script is to calculate and display Moving Average (MA) values derived from three different trading intervals: 5-minute, 1-hour, and 4-hour periods. By processing these different timeframes at once, the tool allows a trader to see how short-term price fluctuations relate to broader, long-term trends.

How it processes information:

  • Timeframe Synchronization: The script identifies specific points in time across three different scales (M5, H1, and H4). It ensures that the data being pulled from these various charts is accurately aligned with the current price action.
  • Multi-Layered Moving Averages: For each of the three timeframes mentioned above, the script calculates three distinct Simple Moving Averages (SMA) based on different lengths (specifically 5, 10, and 15 periods).
  • Data Integration: It captures these specific moving average values and maps them onto a single indicator window. This means that at any given moment, you are seeing the "heartbeat" of the market across three different layers of time.

Visual Output

The tool produces three distinct lines on your chart's sub-window:

  1. Lime Line: Represents the primary moving average data.
  2. Aqua Line: Represents the secondary moving average data.
  3. White Line: Represents the tertiary moving average data.

Practical Application for Traders

By utilizing this logic, traders can move beyond simple price watching. Because the script pulls from the 5-minute, 1-hour, and 4-hour charts simultaneously, it helps identify "confluence"—situations where short-term momentum aligns with long-term trends. If the lines moving across these different timeframes show similar behaviors, it can provide a stronger confirmation of the market's current direction, helping to filter out "noise" that often occurs on single-chart views.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Better_M5_1
//+------------------------------------------------------------------+
//|                                                   Better_MA.mq4  |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Aqua
#property indicator_color3 White



extern int NrBars=1000;

string SymbolName;
int PeriodMinutes1=0;
int PeriodMinutes5=PERIOD_M5;
int PeriodMinutes60=PERIOD_H1;
int PeriodMinutes240=PERIOD_H4;


//---- buffers
double VolBuffer1[];
double VolBuffer2[];
double VolBuffer3[];
double x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {


    SymbolName = Symbol();


   IndicatorBuffers(3);
   
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0, VolBuffer1);

   SetIndexEmptyValue(0,EMPTY_VALUE);
   
   SetIndexStyle(1,DRAW_LINE,0,1);
   SetIndexBuffer(1, VolBuffer2);

   SetIndexEmptyValue(1,EMPTY_VALUE);
   
   SetIndexStyle(2,DRAW_LINE,0,1);
   SetIndexBuffer(2, VolBuffer3);

   SetIndexEmptyValue(2,EMPTY_VALUE);

   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   for (int i=NrBars-1;i>=0;i--)
      {
      datetime time1=iTime(SymbolName,PeriodMinutes1,i);
      
      int b5=iBarShift(SymbolName,PeriodMinutes5,time1,true);
      int b60=iBarShift(SymbolName,PeriodMinutes60,time1,true);
      int b240=iBarShift(SymbolName,PeriodMinutes240,time1,true);
    

      if(b5>=0)
      {
        x0=iClose(SymbolName,PeriodMinutes5,b5);      
        x1=iMA(SymbolName,PeriodMinutes5,5,0,MODE_SMA,PRICE_CLOSE,b5+1);
        x2=iMA(SymbolName,PeriodMinutes5,10,0,MODE_SMA,PRICE_CLOSE,b5+1);
        x3=iMA(SymbolName,PeriodMinutes5,15,0,MODE_SMA,PRICE_CLOSE,b5+1);
      }
      if(b60>=0)
      {        
        x4=iMA(SymbolName,PeriodMinutes60,5,0,MODE_SMA,PRICE_CLOSE,b60+1);
        x5=iMA(SymbolName,PeriodMinutes60,10,0,MODE_SMA,PRICE_CLOSE,b60+1);
        x6=iMA(SymbolName,PeriodMinutes60,15,0,MODE_SMA,PRICE_CLOSE,b60+1);
      }       
      if(b240>=0)
      {             
        x7=iMA(SymbolName,PeriodMinutes240,5,0,MODE_SMA,PRICE_CLOSE,b240+1);
        x8=iMA(SymbolName,PeriodMinutes240,10,0,MODE_SMA,PRICE_CLOSE,b240+1);
        x9=iMA(SymbolName,PeriodMinutes240,15,0,MODE_SMA,PRICE_CLOSE,b240+1);
      }
	  VolBuffer1[i]=x1; 
 	  VolBuffer2[i]=x2;   
 	  VolBuffer3[i]=x3;      
  
  }
  
 
   
		

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

Comments