Vortex Indicator

Download script
Vortex Indicator

Understanding the Vortex Indicator

The Vortex Indicator is a technical analysis tool designed to help traders identify the prevailing trend and momentum in a financial market. It works by measuring the "strength" of upward price movement against downward price movement over a specific period.

By comparing these two opposing forces, the indicator provides a visual representation of whether buyers or sellers are currently dominating the market.

How the Logic Works

The indicator follows a systematic three-step calculation to derive its values:

1. Measuring Movement Intensity The script first looks at the price action over recent bars. It calculates two distinct types of movement:

  • Positive Movement: It measures the distance from today's high to yesterday's low. This represents the "reach" of upward momentum.
  • Negative Movement: It measures the distance from today's low to yesterday's high. This represents the "reach" of downward momentum.

2. Aggregating Data Over Time Instead of looking at just a single price tick, the indicator looks at a set window of time (the "Length," which defaults to 14 periods). It calculates the sum of all positive movements and all negative movements within that window. Simultaneously, it calculates the "True Range"—a measure of total market volatility—for that same period.

3. Calculating the Final Scores To produce the final lines you see on your chart, the script divides the sum of positive movements by the total volatility, and does the same for the negative movements.

  • The result is a Plus Vortex (+VI) line, which tracks bullish strength.
  • The result is a Minus Vortex (-VI) line, which tracks bearish strength.

How to Read the Results

The indicator operates in a separate window below your main price chart:

  • Trend Strength: When the Plus Vortex line is significantly higher than the Minus Vortex line, it suggests that the market is trending upward (bullish). Conversely, when the Minus Vortex is significantly higher, it suggests a downward trend (bearish).
  • Crossovers: Traders often watch for "crossovers." When the Plus Vortex crosses above the Minus Vortex, it can be interpreted as a signal that momentum is shifting from sellers to buyers. When it crosses below, it may indicate that momentum is shifting from buyers to sellers.
Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Vortex Indicator
//+------------------------------------------------------------------+
//|Vortex Indicator.mq4                                              |
//|From the January 2010 issue of Technical Analysis of Stocks &     |
//|Commodities                                                       |
//+------------------------------------------------------------------+
#property  copyright "Copyright 2009 under Creative Commons BY-SA License by Neil D. Rosenthal"
#property  link      "http://creativecommons.org/licenses/by-sa/3.0/"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

//---- Input parameters
extern int VI_Length=14;

//---- Buffers
double PlusVI[];        //VI+ : + Vortex Indicator buffer
double MinusVI[];       //VI- : - Vortex Indicator buffer
double PlusVM[];        //VM+ : + Vortex Movement buffer
double MinusVM[];       //VM- : - Vorext Movement buffer
double SumPlusVM[];     //Sum of VI_Length PlusVM values
double SumMinusVM[];    //Sum of VI_Length MinusVM values
double SumTR[];         //True Range buffer
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//----
    IndicatorBuffers(7);
    IndicatorDigits(Digits);
//---- Set visible buffer properties    
    SetIndexBuffer(0,PlusVI);
    SetIndexBuffer(1,MinusVI);
    SetIndexStyle(0,DRAW_LINE);    
    SetIndexStyle(1,DRAW_LINE);
    SetIndexLabel(0,"PlusVI(" + VI_Length + ")");
    SetIndexLabel(1,"MinusVI(" + VI_Length + ")");
    SetIndexDrawBegin(0,VI_Length);
    SetIndexDrawBegin(1,VI_Length);
//---- Set indices of caching buffers
    SetIndexBuffer(2,PlusVM);
    SetIndexBuffer(3,MinusVM);
    SetIndexBuffer(4,SumPlusVM);
    SetIndexBuffer(5,SumMinusVM);
    SetIndexBuffer(6,SumTR);
//----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
    return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
    int Limit;
    int CountedBars = IndicatorCounted();
//---- Check for possible errors
    if(CountedBars < 0) return(-1);
//---- Last counted bar will be recounted
    if(CountedBars > 0) CountedBars--;
    Limit = Bars - CountedBars;
//---- Clear caching buffers
    for(int i = 0; i < Limit; i++)
    {
      SumPlusVM[i] = 0;
      SumMinusVM[i] = 0;
      SumTR[i]= 0;  
    }
//---- Store the values of PlusVM and MinusVM
    for(i = 0; i < Limit; i++)
    {
        //PlusVM = |Today's High - Yesterday's Low|
        PlusVM[i] = MathAbs(High[i] - Low[i + 1]);
        //MinusVM = |Today's Low - Yesterday's High|
        MinusVM[i] = MathAbs(Low[i] - High[i +1]);  
    }
//---- Sum VI_Length values of PlusVM, MinusVM and the True Range
    for(i = 0; i < Limit; i++)
    {
        for(int j = 0; j <= VI_Length - 1; j++)
        {
           SumPlusVM[i] += PlusVM[i + j];
           SumMinusVM[i] += MinusVM[i + j];
           SumTR[i] += iATR(NULL,0,1,i + j); //Sum VI_Length values of the True Range by using a 1-period ATR
        }
    }
//---- Draw the indicator
    for(i = 0; i < Limit; i++)
    {
        PlusVI[i] = SumPlusVM[i] / SumTR[i];
        MinusVI[i] = SumMinusVM[i] / SumTR[i];
    }
//----
    return(0);
}
//+------------------------------------------------------------------+

Comments