ArrayTest_v1
Download scriptThis script functions as a visual trading tool designed to help market participants analyze price momentum by identifying trends through the relationship between two different speeds of movement. It works by calculating two distinct "moving averages" and plotting them on your chart simultaneously.
How the Logic Works
1. Two Speeds of Analysis The core logic relies on comparing a "Fast" data point with a "Slow" data point.
- The Fast Component: This looks at the most recent price activity over a short period (set by the Fast Map Period). Because it covers a small amount of time, it reacts quickly to sudden shifts in the market.
- The Slow Component: This looks at price activity over a much larger timeframe (set by the Slow Map Period). This acts as a stabilizer, showing you the broader, long-term direction of the market while filtering out minor "noise" or temporary fluctuations.
2. Calculating the Movement The script uses an "Exponential Moving Average" method for both components. Unlike a simple average that treats all past days equally, this method gives more weight to recent price action. This ensures that the lines on your chart are responsive to what is happening right now while still respecting the historical trend.
3. Visualizing the Relationship The script generates two distinct lines on your trading screen:
- One line represents the short-term momentum (displayed in Yellow).
- One line represents the long-term trend (displayed in Red).
Purpose for the Trader
By observing these two lines together, you can see how the immediate price action is behaving relative to the larger trend. When the lines move in different directions or show varying degrees of "acceleration" or "deceleration," it provides a visual cue regarding whether the current market strength is picking up speed, slowing down, or potentially reversing.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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