Var Mov Avg3

Author: Copyright � 2004, by GOODMAN & Mstera � AF
Var Mov Avg3

This tool is designed as a visual assistant for traders to identify momentum shifts and potential entry points in the financial markets. Rather than simply following price movements blindly, the logic focuses on distinguishing between meaningful trends and minor market "noise."

Core Logic Overview

The script operates by calculating a specialized moving average (AMA). Unlike standard averages that give equal weight to all past data points, this calculation uses a dynamic approach to determine how much influence new price information should have.

1. Noise Filtering The system first evaluates the current market volatility. It calculates the "noise" by measuring the fluctuations between consecutive price points over a specific period. By comparing the actual price change against this noise level, the indicator can determine if a price move is a significant trend or just a minor vibration.

2. Adaptive Smoothing The tool uses two different speed settings (fast and slow) to create a balance in the calculation. It adjusts the smoothing factor based on the ratio of these speeds. This allows the resulting line to react more quickly when a strong trend is established while remaining smooth enough to ignore insignificant price flickers.

3. Trend Generation The final moving average value is produced by blending the previous average with the current price, adjusted by the calculated noise and speed factors. This creates a "smoothed" path that attempts to follow the true direction of the market flow.

Visual and Audio Signals

To make the data actionable for the user, the script translates these mathematical movements into three distinct visual and audible alerts:

  • The Trend Line: A continuous line (colored Sienna) that shows the smoothed direction of the price.
  • Buy Signals: When the smoothed average moves upward with sufficient momentum—surpassing a specific threshold—the script places an upward arrow on the chart.
  • Sell Signals: Conversely, when the average drops with significant momentum, it places a downward arrow.

Notifications

To ensure traders don't miss high-probability moments, the script includes an automated alert system. When a valid Buy or Sell signal is confirmed, the tool will:

  • Trigger an audible sound alert.
  • Generate a pop-up alert message.
  • Place a text comment directly on the chart screen showing the current price and the action suggested.

By combining noise filtering with adaptive smoothing, this logic aims to provide a clearer picture of market direction than raw price action alone.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
Var Mov Avg3
//+------------------------------------------------------------------+
//|                                                   AMA&AMAsig.mq4 |                                                             
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by GOODMAN & Mstera è AF "
      
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Sienna
#property indicator_color2 Green
#property indicator_color3 Red
//---- input parameters
extern int       periodAMA=50;
extern int       nfast=15;
extern int       nslow=10;
extern double    G=1.0;
extern double    dK=0.1; 

//---- buffers
double kAMAbuffer[];
double kAMAupsig[];
double kAMAdownsig[];
extern bool UseSound = True;
extern string SoundFile = "expert.wav"; 
//+------------------------------------------------------------------+
int    cbars=0, prevbars=0, prevtime=0;
double slowSC,fastSC;
bool SoundBuy = False;
bool SoundSell = False;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID, 2);
   SetIndexArrow(1,159);
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID, 2);
   SetIndexArrow(2,159);
   //SetIndexDrawBegin(0,nslow+nfast);
   SetIndexBuffer(0,kAMAbuffer);
   SetIndexBuffer(1,kAMAupsig);
   SetIndexBuffer(2,kAMAdownsig);
   IndicatorDigits(4);
   //slowSC=0.064516;
   //fastSC=0.2;
   //cbars=IndicatorCounted();
//----
   return(0);
  }
int last_dir = 0;
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,pos=0;
   double noise=0.000000001,AMA,AMA0,signal,ER;
   double dSC,ERSC,SSC,ddK;
   
   if (prevbars==Bars) return(0);
    
//---- TODO: add your code here
   slowSC=(2.0 /(nslow+1));
   fastSC=(2.0 /(nfast+1));
   cbars=IndicatorCounted();
   if (Bars<=(periodAMA+2)) return(0);
//---- check for possible errors
   if (cbars<0) return(-1);
//---- last counted bar will be recounted
   if (cbars>0) cbars--;
   pos=Bars-periodAMA-2;
   AMA0=Close[pos+1];
   int dir = 0;
   while (pos>=0)
     {
      if(pos==Bars-periodAMA-2) AMA0=Close[pos+1];
      signal=MathAbs(Close[pos]-Close[pos+periodAMA]);
      noise=0.000000001;
      for(i=0;i<periodAMA;i++)
       {
        noise=noise+MathAbs(Close[pos+i]-Close[pos+i+1]);
       }
      ER =signal/noise;
      dSC=(fastSC-slowSC);
      ERSC=ER*dSC;
      SSC=ERSC+slowSC;
      AMA=AMA0+(MathPow(SSC,G)*(Close[pos]-AMA0));
      kAMAbuffer[pos]=AMA;

      ddK=(AMA-AMA0);
      if ((MathAbs(ddK)) > (dK*Point) && (ddK > 0)) kAMAupsig[pos] =AMA; else kAMAupsig[pos]=0;
      if ((MathAbs(ddK)) > (dK*Point) && (ddK < 0)) kAMAdownsig[pos]=AMA; else kAMAdownsig[pos]=0; 

     
      AMA0=AMA;
      pos--;
     }
if (kAMAupsig[0] != EMPTY_VALUE && kAMAupsig[0] != 0 && SoundBuy)
  {
   SoundBuy = False;
   if (UseSound) PlaySound (SoundFile);
   Comment (Symbol()," ",Period(),"hellkkas BUY @ ",Ask);
   Alert (Symbol()," ",Period(),"hellkkas BUY @ ",Ask);
  } 
if (!SoundBuy && (kAMAupsig[0] == EMPTY_VALUE || kAMAupsig[0] == 0)) SoundBuy = True;  
  
if (kAMAdownsig[0] != EMPTY_VALUE && kAMAdownsig[0] != 0 && SoundSell)
  {
   SoundSell = False;
   if (UseSound) PlaySound (SoundFile);
   Comment (Symbol()," ",Period(), "hellkkas Sell @",Bid);
   Alert (Symbol()," ",Period(), "hellkkas Sell @",Bid);
  }
if (!SoundSell && (kAMAdownsig[0] == EMPTY_VALUE || kAMAdownsig[0] == 0)) SoundSell = True;  

   prevbars=Bars;
   return(0);
  }

Comments