Vidya_zone_2

Download script
Author: mladen
Vidya_zone_2

This script is a technical analysis tool designed to help traders visualize price trends and momentum by calculating the "Vidya" (Variable Index Dynamic Average). Unlike standard moving averages that treat all price movements equally, this logic adapts itself based on the intensity of the market's movement.

Core Logic Overview

The primary objective of this script is to create a dynamic "envelope" or zone around the current market price. It achieves this by calculating three distinct lines simultaneously:

  • A High Line: Based on the highest price reached during a period.
  • A Middle Line (Median): Based on the midpoint between the high and low prices.
  • A Low Line: Based on the lowest price reached during a period.

How the Calculation Works

The script processes market data through several specific logical layers to ensure the resulting lines are smooth yet responsive:

1. Price Comparison and Movement Detection The system looks back at a set number of past bars (defined by the CMO Period). It identifies how much the "median" price has moved up versus how much it has moved down during that time. By separating upward movements from downward movements, the script can determine the current strength of the trend.

2. Dynamic Momentum Weighting The core "intelligence" of the Vidya logic lies in its ability to change its own speed.

  • When the market is moving strongly and consistently in one direction, the indicator adjusts its calculation to follow that price action more closely.
  • When the market is choppy or moving sideways, the indicator slows down its reaction to prevent "whipsaws" (false signals caused by minor fluctuations).

3. Smoothing and Integration To ensure the lines appear fluid on a chart rather than jagged, the script applies a smoothing factor. It takes the difference between the current price and the previous calculated value, then weighs it against the momentum detected in step one. This ensures that the resulting lines represent a stabilized version of the market's true trajectory.

Visual Summary for Traders

By displaying these three lines (High, Middle, and Low), the tool provides a visual "channel."

  • The Middle Line acts as the primary trend indicator.
  • The High and Low Lines define the boundaries of the current volatility.

Because the logic is variable, these lines will expand during periods of high volatility and contract (tighten) during periods of low volatility, providing a real-time map of market sentiment and price behavior.

2 Views
0 Downloads
0 Favorites
Vidya_zone_2
//+------------------------------------------------------------------+
//|                                                        Vidya.mq4 |
//|                                                                  |
//| Vidya developed by Tushar Chande                                 |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link      "mladenfx@gmail.com"

#property  indicator_chart_window
#property  indicator_buffers 3
#property  indicator_color1  clrDeepSkyBlue
#property  indicator_color2  clrDimGray
#property  indicator_color3  clrDarkOrange
#property  indicator_width1  2
#property  indicator_width3  2
#property  indicator_style2  STYLE_DOT
#property  strict

//
//
//
//
//

extern int  CmoPeriod      = 10;    // CMO period
extern int  SmoothPeriod   =  9;    // Smoothing period
extern bool ShowHighLine   = true;  // Show high line?
extern bool ShowMiddleLine = true;  // Show middle line?
extern bool ShowLowLine    = true;  // Show low line?

double vidya1[],vidya2[],vidya3[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()
{
   SetIndexBuffer(0,vidya1);
   SetIndexBuffer(1,vidya2);
   SetIndexBuffer(2,vidya3);
   return(0);
}
int start()
{
   int counted_bars = IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = MathMin(Bars-counted_bars,Bars-1);
   
   for(int i=limit; i>=0; i--) 
   {
      double median = (High[i]+Low[i])/2;
      if (ShowHighLine)   vidya1[i] = iVidya(High[i],median,CmoPeriod,SmoothPeriod,i,0);
      if (ShowMiddleLine) vidya2[i] = iVidya(median ,median,CmoPeriod,SmoothPeriod,i,1);
      if (ShowLowLine)    vidya3[i] = iVidya(Low[i] ,median,CmoPeriod,SmoothPeriod,i,2);
   }
   return(0);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

#define _vidyaInstances     3
#define _vidyaInstancesSize 3
double  vidya_work[][_vidyaInstances*_vidyaInstancesSize];
#define vidya_price 0
#define vidya_pricc 1
#define vidya_value 2

double iVidya(double price, double pricc, int cmoPeriods, int smoothPeriod, int r, int instanceNo=0)
{
   if (ArrayRange(vidya_work,0)!=Bars) ArrayResize(vidya_work,Bars); r = Bars-r-1; int s = instanceNo*_vidyaInstancesSize;
   
   //
   //
   //    using two prices prevents errors when zone indicator is calculated
   //
   //
   
   vidya_work[r][s+vidya_price] = price;
   vidya_work[r][s+vidya_pricc] = pricc;
          double sumUp = 0, sumDo = 0;
          for (int k=0; k<cmoPeriods && (r-k-1)>=0; k++)
          {
               double diff = vidya_work[r-k][s+vidya_pricc]-vidya_work[r-k-1][s+vidya_pricc];
                  if (diff > 0)
                        sumUp += diff;
                  else  sumDo -= diff;
          }      
          vidya_work[r][s+vidya_value] = (r>0) ? vidya_work[r-1][s+vidya_value]+((((sumUp+sumDo)!=0)?MathAbs((sumUp-sumDo)/(sumUp+sumDo)):1)*2.00/(1.00+MathMax(smoothPeriod,1)))*(vidya_work[r][s+vidya_price]-vidya_work[r-1][s+vidya_value]) : price;
   return(vidya_work[r][s+vidya_value]);
}

Comments