ArrayTest

This tool functions as a momentum and trend-tracking indicator designed to help traders visualize the relationship between short-term price movements and long-term trends. By smoothing out market "noise," it allows for a clearer view of how price velocity is changing over time.

Core Logic and Mechanism

The script operates by calculating two distinct types of moving averages based on the closing prices of the asset. These averages act as "filters" that interpret price data at different speeds:

  • The Fast Component: This tracks short-term price action using a smaller window of data (defaulting to 21 periods). Because it reacts quickly, it highlights immediate shifts in momentum and current sentiment.
  • The Slow Component: This tracks long-term price trends using a much larger window of data (defaulting to 100 periods). It serves as the "anchor," representing the broader direction in which the market is moving.

How it Visualizes the Market

When these two components are plotted together on your chart, they create a visual representation of acceleration and deceleration:

  1. Trend Identification: By observing where the fast line sits in relation to the slow line, traders can identify the primary trend. When the fast line is above the slow line, it generally indicates bullish momentum; when below, it suggests bearish sentiment.
  2. Momentum Gauging: The distance between these two lines helps illustrate the strength of the current move. A widening gap suggests that the price is accelerating in its current direction, while a narrowing gap may signal that the move is losing steam (decelerating) and that a trend reversal or consolidation might be approaching.
  3. Smoothing for Clarity: Instead of looking at erratic candle-to-candle price jumps, this script uses Exponential Moving Averages (EMA). This specific calculation gives more weight to recent price data, ensuring that the indicator remains responsive to new information while still providing a smooth, readable line on the chart.

In summary, this script provides a dual-layer perspective on the market, allowing you to see not just where the price is going, but how fast it is moving to get there.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ArrayTest
//+------------------------------------------------------------------+
//|                                                  Accelerator.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Yellow

extern int SlowMAPeriod = 100;
extern int FastMAPeriod = 21;

//---- input parameters
//---- variables
double       Array1[];
double       Buffer1[];
double       Array2[];
double       Buffer2[];
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 4 additional buffers are used for counting.
   IndicatorBuffers(2);
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);

//----
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator                               |
//+------------------------------------------------------------------+
int start()
  {
   int limit,i;
   int counted_bars=IndicatorCounted();

//---- check for possible errors
   if(counted_bars<0) return(-1);

//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
// ---- Declare Size of Arrays
   ArrayResize(Array1,limit);
   ArrayResize(Buffer1,limit);
   ArrayResize(Array2,limit);
   ArrayResize(Buffer2,limit);

//---- Change Array to same sort of series Array as screen buffers
   ArraySetAsSeries(Array1,true);
   ArraySetAsSeries(Buffer1,true);
   ArraySetAsSeries(Array2,true);
   ArraySetAsSeries(Buffer2,true);
   
   for(i=0; i<limit; i++)
   {  
   Array1[i]=iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
   Array2[i]=iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
   ExtMapBuffer1[i]=Array1[i];
   ExtMapBuffer2[i]=Array2[i];
   }


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

Comments