Better_H4_2

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

The Better_MA tool is designed to provide traders with a multi-timeframe perspective on price trends by consolidating data from various intervals into a single visual display. Instead of forcing a user to switch between different charts to see the "big picture," this script automatically gathers information from three specific timeframes—5 minutes, 1 hour, and 4 hours—and displays them simultaneously.

How the Logic Works:

1. Multi-Timeframe Synchronization The core functionality of this script relies on its ability to look across different time horizons at once. It scans the current market data and identifies the corresponding candles for the 5-minute, 60-minute (1 hour), and 240-minute (4 hour) periods. By doing this, it ensures that the data being displayed is perfectly aligned with the current moment in time.

2. Moving Average Calculation For each of these three timeframes, the script calculates specific Simple Moving Averages (SMA). It focuses on three different lengths for each period: 5, 10, and 15 units. These averages help smooth out market "noise," making it easier to identify the underlying direction of the price movement.

3. Data Extraction and Processing The script performs a specific calculation by looking slightly back into the history (specifically two steps back) on each timeframe. This historical look-back helps provide a stable reading of the average price without being overly influenced by the immediate, volatile fluctuations of the current active candle.

4. Visual Output Finally, the script takes the results from the 4-hour timeframe's averages and maps them onto three distinct visual lines on your chart (represented in Lime, Aqua, and White). This allows a trader to see the high-level trend of the 4-hour market while the system does the heavy lifting of calculating those values based on the broader market structure.

Summary for the User:

Essentially, this tool acts as a "trend filter." It tells you what the larger market trends look like by pulling data from different timeframes and drawing them as clear lines on your screen. It simplifies your analysis by providing high-level market context without requiring you to manage multiple open windows or manually calculate complex averages.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Better_H4_2
//+------------------------------------------------------------------+
//|                                                   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+2);
        x2=iMA(SymbolName,PeriodMinutes5,10,0,MODE_SMA,PRICE_CLOSE,b5+2);
        x3=iMA(SymbolName,PeriodMinutes5,15,0,MODE_SMA,PRICE_CLOSE,b5+2);
      }
      if(b60>=0)
      {        
        x4=iMA(SymbolName,PeriodMinutes60,5,0,MODE_SMA,PRICE_CLOSE,b60+2);
        x5=iMA(SymbolName,PeriodMinutes60,10,0,MODE_SMA,PRICE_CLOSE,b60+2);
        x6=iMA(SymbolName,PeriodMinutes60,15,0,MODE_SMA,PRICE_CLOSE,b60+2);
      }       
      if(b240>=0)
      {             
        x7=iMA(SymbolName,PeriodMinutes240,5,0,MODE_SMA,PRICE_CLOSE,b240+2);
        x8=iMA(SymbolName,PeriodMinutes240,10,0,MODE_SMA,PRICE_CLOSE,b240+2);
        x9=iMA(SymbolName,PeriodMinutes240,15,0,MODE_SMA,PRICE_CLOSE,b240+2);
      }
	  VolBuffer1[i]=x7; 
 	  VolBuffer2[i]=x8;   
 	  VolBuffer3[i]=x9;      
  
  }
  
 
   
		

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

Comments