Author: Integer

This script is a sophisticated technical analysis tool designed to generate a custom trend indicator by blending multiple mathematical concepts: Standard Deviation, Bollinger Bands principles, and Exponential Moving Averages (EMA).

Instead of simply following the price, this tool processes market data through several layers of logic to create a smoother, more reactive visualization for traders. Here is a breakdown of how the logic operates:

1. Core Data Inputs

The script begins by gathering three primary types of market information:

  • Volatility (Standard Deviation): It measures how much the price fluctuates over a set period.
  • Trend (Moving Averages): It calculates a fast-reacting average to capture immediate momentum and a slower average to establish the broader trend.
  • Range Awareness: It monitors the "highs" and "lows" within specific timeframes to understand the relative space the price is occupying.

2. The Volatility Transformation

The tool does not use volatility as a raw number. Instead, it normalizes the current volatility against the broader trend. By comparing the current Standard Deviation to the overall moving average, the script determines where the market "stands" in relation to its recent history. It then identifies the maximum and minimum peaks within the lookback period to calculate a relative position (a percentage of movement).

3. Dynamic Sensitivity Scaling

One of the most unique aspects of this script is its ability to adjust its own behavior based on user input:

  • Power Curves: The logic uses specific mathematical powers (exponential growth formulas) to weight the volatility data. This ensures that extreme market moves are weighted differently than minor fluctuations.
  • Sensitivity Adjustment: Through a custom "Sensitivity" parameter, the user can manually stretch or compress how aggressively the indicator reacts to new data. If the sensitivity is high, the indicator will lean more heavily toward the primary trend; if adjusted otherwise, it may become more responsive to sudden price spikes.

4. Final Smoothing and Output

The final step of the logic combines all these calculations into a single, refined line on your chart. It uses a weighted formula to blend the current fast-moving average with the previous value of the indicator. This ensures that the resulting line is fluid and lacks the "jitter" often found in standard indicators, providing a cleaner visual representation of market direction.

Summary for the User

In simple terms, this script looks at how much the market is "swinging" versus how much it is "moving." It then calculates a multiplier based on those swings, applies your preferred sensitivity level, and draws a smoothed line that helps you identify the trend while filtering out unnecessary market noise.

Indicators Used
Standard Deviation indicatorMoving average indicator
Miscellaneous
It issuies visual alerts to the screen
12 Views
0 Downloads
0 Favorites
EMA_BB_VA
//+------------------------------------------------------------------+
//|                                                    EMA_BB_VA.mq5 |
//|                                                          Integer |
//|                          https://login.mql5.com/en/users/Integer |
//+------------------------------------------------------------------+
#property copyright "Integer"
#property link      "https://login.mql5.com/en/users/Integer"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int                STDPeriod   =  14;          // StdDev period
input double             EMAPeriods  =  14;          // EMA period
input double             Sensitivity =  100;         // Sensitivity (-100 to 100)
input ENUM_APPLIED_PRICE Price       =  PRICE_CLOSE; // Applied price

int STDHand;
int MAHand;
int MABBHand;
double sens;
//--- indicator buffers
double Label1Buffer[];
double STDBuf[];
double MABuf[];
double MABBBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   sens=Sensitivity/100.0;

   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,STDBuf,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,MABuf,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,MABBBuf,INDICATOR_CALCULATIONS);

   STDHand=iStdDev(NULL,PERIOD_CURRENT,STDPeriod,0,0,Price);
   MAHand=iMA(NULL,PERIOD_CURRENT,1,0,0,Price);
   MABBHand=iMA(NULL,PERIOD_CURRENT,STDPeriod,0,0,Price);
   if(STDHand==INVALID_HANDLE || MAHand==INVALID_HANDLE || MABBHand==INVALID_HANDLE)
     {
      Alert("Error in creation of indicator. Please try again");
      return(-1);
     }

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,STDPeriod*2);
   PlotIndexSetString(0,PLOT_LABEL,MQL5InfoString(MQL5_PROGRAM_NAME));

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   static bool error=true;
   int start;
   if(prev_calculated==0)
     {
      error=true;
     }
   if(error)
     {
      start=STDPeriod*2;
      Label1Buffer[start-1]=close[start-1];
      error=false;
     }
   else
     {
      start=prev_calculated-1;
     }
   if(CopyBuffer(STDHand,0,0,rates_total-start,STDBuf)==-1 || 
      CopyBuffer(MAHand,0,0,rates_total-start,MABuf)==-1 || 
      CopyBuffer(MABBHand,0,0,rates_total-start,MABBBuf)==-1
      )
     {
      error=true;
      return(0);
     }
   for(int i=start;i<rates_total;i++)
     {
      STDBuf[i]=2.0*STDBuf[i]/MABBBuf[i];
      double mxv=STDBuf[ArrayMaximum(STDBuf,i-STDPeriod+1,STDPeriod)];
      double mnv=STDBuf[ArrayMinimum(STDBuf,i-STDPeriod+1,STDPeriod)];
      double r=mxv-mnv;
      if(r==0)
        {
         Label1Buffer[i]=Label1Buffer[i-1];
         continue;
        }
      double ATRvlty=(STDBuf[i]-mnv)/r;
      double multi;
      if(ATRvlty<=0.5)
        {
         multi=10.0*MathPow(ATRvlty,3.4739)+0.1;
        }
      else
        {
         multi=10*MathPow(ATRvlty,3.32)+0.000001;
        }
      if(sens>0)
        {
         multi=1.0/multi;
        }
      if(multi<1.0)
        {
         multi=1.0-(1.0-multi)*MathAbs(sens);
        }
      else
        {
         multi=(multi-1.0)*MathAbs(sens)+1.0;
        }
      double pdsx=EMAPeriods*multi;
      if(pdsx<1.0)
        {
         pdsx=1.0;
        }
      Label1Buffer[i]=MABuf[i]*2.0/(pdsx+1.0)+Label1Buffer[i-1]*(1.0-2.0/(pdsx+1.0));
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments