This tool is designed to analyze price momentum by identifying shifts in the speed and direction of a currency pair's movement. It functions as an "Accelerator Oscillator," which essentially measures how much the market is speeding up or slowing down, rather than just showing the price itself.
Core Logic and Mechanics
1. Data Calculation The script begins by calculating two primary moving averages based on different timeframes (specifically, a short-term 5-period average and a longer-term 34-period average). By subtracting these from one another, the tool determines the current "momentum" of the market. It then creates a "signal line"—a secondary smoothing of that momentum—to help filter out minor price fluctuations and focus on more significant trends.
2. Trend Detection The script constantly compares the current value of the momentum against the previous values. It looks for specific "inflection points" where the trend changes:
- Bullish Momentum: When the momentum value begins to rise compared to its previous state, the tool identifies a potential upward move.
- Bearish Momentum: When the momentum value begins to drop compared to its previous state, it identifies a potential downward move.
3. Confirmation Filters To reduce "false signals" (where the market might appear to move but lacks substance), the script employs two specific filters:
- Volume Check: The tool ensures that there is active trading volume present before confirming a signal. This helps prevent the tool from triggering alerts during periods of extremely low liquidity or "dead" markets.
- Trend Memory: The logic tracks whether it has already identified an "Up Trend" or "Down Trend." This prevents the tool from sending repetitive alerts for the same move, ensuring that you are only notified at the start of a new directional shift.
Visual and Audio Notifications
The script provides three distinct ways for a user to receive these signals:
- On-Chart Arrows: It automatically places visual markers on your trading chart. Green arrows indicate potential upward momentum, while Red arrows indicate potential downward momentum. These are placed at specific distances above or below the candles to ensure they remain clearly visible.
- Pop-Up Alerts: If enabled in the settings, the tool will trigger a text notification box on your screen, providing the name of the currency pair, the timeframe, and the current bid price as soon as a new signal is confirmed.
- Audio Alerts: The script can play a specific sound file (by default "alert2.wav") to provide an audible cue, allowing traders to react quickly even if they are not looking directly at the screen.
Summary of Operation
In short, this script monitors the "acceleration" of price movement. When it detects that momentum is shifting in a new direction and confirms that there is enough trading volume to support that move, it notifies the user through visual arrows, sound, and pop-up alerts.
//+------------------------------------------------------------------+
//| AcceleratorAlert.mq4 |
//| Copyright © 2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| Alerts & Arrows added by cja |
//| Thanks to mladen for the Arrow code & IgorAD for the Alert code |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_width2 2
#property indicator_width3 2
extern bool PopUP_Alert_ON = false;
extern bool SoundAlert_ON = false;
extern string SoundFile ="alert2.wav";
extern bool Show_Arrows = true;
extern int Arrow_Size = 1;
extern int ArrowUP = 233;//241
extern int ArrowDN = 234;//242
extern int Arrow_Shift = 4;
//---- indicator buffers
double ExtBuffer0[];
double ExtBuffer1[];
double ExtBuffer2[];
double ExtBuffer3[];
double ExtBuffer4[];
bool UpTrend=false, DownTrend=false;
int maxArrows;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexStyle(2,DRAW_HISTOGRAM);
IndicatorDigits(Digits+2);
SetIndexDrawBegin(0,38);
SetIndexDrawBegin(1,38);
SetIndexDrawBegin(2,38);
//---- 4 indicator buffers mapping
SetIndexBuffer(0,ExtBuffer0);
SetIndexBuffer(1,ExtBuffer1);
SetIndexBuffer(2,ExtBuffer2);
SetIndexBuffer(3,ExtBuffer3);
SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("AC");
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//ObjectsDeleteAll(0,OBJ_ARROW);
// ObjectDelete("ACC_BUY");
// ObjectDelete("ACC-SELL");
DeleteArrows();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ExtBuffer3[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,5,0,MODE_SMA,i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ExtBuffer3[i]-ExtBuffer4[i];
prev=ExtBuffer3[i+1]-ExtBuffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ExtBuffer2[i]=current;
ExtBuffer1[i]=0.0;
}
else
{
ExtBuffer1[i]=current;
ExtBuffer2[i]=0.0;
}
ExtBuffer0[i]=current;
}
if (Show_Arrows)
for (i=0; i<WindowBarsPerChart() ;i++)//Bars for showing total history of signals
{
if( ExtBuffer3[i]-ExtBuffer4[i]<ExtBuffer3[i+1]-ExtBuffer4[i+1]
&& ExtBuffer3[i+1]-ExtBuffer4[i+1]>ExtBuffer3[i+2]-ExtBuffer4[i+2]
&& Volume[0]>1 && !UpTrend) DrawArrow(i,"up");
if ( ExtBuffer3[i]-ExtBuffer4[i]>ExtBuffer3[i+1]-ExtBuffer4[i+1]
&& ExtBuffer3[i+1]-ExtBuffer4[i+1]<ExtBuffer3[i+2]-ExtBuffer4[i+2]
&& Volume[0]>1 && !DownTrend) DrawArrow(i,"down");
}
if ( current>prev && Volume[0]>1 && !UpTrend)
{
if ( PopUP_Alert_ON==true ) Alert(""+Symbol()+" M"+Period()+": ACC Signal for BUY & "+DoubleToStr(Bid,Digits)+"");
if(SoundAlert_ON==true)PlaySound(SoundFile);
UpTrend=true; DownTrend=false;
}
if ( current<prev && Volume[0]>1 && !DownTrend)
{
if ( PopUP_Alert_ON==true ) Alert(""+Symbol()+" M"+Period()+": ACC Signal for SELL & "+DoubleToStr(Bid,Digits)+"");
if(SoundAlert_ON==true)PlaySound(SoundFile);
DownTrend=true; UpTrend=false;
}
//---- done
return(0);
}
void DrawArrow(int i,string type)//Arrow_Size
{
maxArrows++;
ObjectCreate("AC_ArrowALERT"+maxArrows,OBJ_ARROW,0,Time[i],0);
if (type=="up")
{
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_PRICE1,High[i]+((4+Arrow_Shift)*Point));
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_ARROWCODE,ArrowDN);
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_WIDTH,Arrow_Size);
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_COLOR,Red);
}
else
{
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_PRICE1,Low[i]-((2+Arrow_Shift)*Point));
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_ARROWCODE,ArrowUP);
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_WIDTH,Arrow_Size);
ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_COLOR,LimeGreen);
}
}
void DeleteArrows()
{
while(maxArrows>0) { ObjectDelete("AC_ArrowALERT"+maxArrows); maxArrows--; }
}
Comments