Schwager Volatility Ratio Amibroker AFL code and Analysis

What is Volatility ratio?

The Term Volatility ratio is coined by Jack D. Schwager to identify trading range and potential trend reversal. The values of the volatility ratio range from 0.01-1.00 and typically traders predicts the reversal points if the value shows above 0.5. However marketcalls recommend to look for reversal above 0.6.

Volatility ratio formula

Volatility Ratio (VR) = Today’s True Range/True Range over N number of days

To calculate the volatility ratio, the true range is calculated using the following formula:

Today’s True Range = MAX (today’s high, yesterday’s close) – MIN (today’s low, yesterday’s close)
and

True Range over N number of days= MAX (Day1 High, Day 2 High, …Day N High, Day 0 Close) minus MIN(Day1 Low, Day 2 Low, …Day N Low, Day 0 Close)

Volatility ratio – Amibroker AFL code

_SECTION_BEGIN("Volatility Ratio");
//{Volatility Ratio - Schwager}
//Coded By Rajandran R  - www.marketcalls.in
//Date - 18 Feb 2012

n=Param("Periods",13,1,300,1);
VRT=Param("VRthreshold",0.6,0.5,1,0.1);
Dday =Param("Decision Day Based on Prev day returns",4,3,5,1);
zero=10^-10;

r1=H-L;
r2=abs(H-Ref(C,-1));
r3=abs(Ref(C,-1)-L);


TrueRange=Max(Max(r1,r2),r3);

TrueHighPds=Max(HHV(H,n),Ref(C,-n));
TrueLowPds=Min(LLV(L,n),Ref(C,-n));
TrueRangePds=TrueHighPds-TrueLowPds;

VolatilityRatio=TrueRange/Max(TrueRangePds,zero);

SetPositionSize(1,spsShares);

decisionSell=HHV(C,5)-C;
decisionBuy=C-LLV(C,5);

Buy =decisionBuy>0 AND Cross(VolatilityRatio,VRT);
Sell =0;
Short=decisionSell>0 AND Cross(VolatilityRatio,VRT);
Cover=0;

Plot(VolatilityRatio,"Volatility Ratio - Schwager",colorRed);

_SECTION_END();

The above code has been derived from the following metastock code as shown below

{Volatility Ratio - Schwager}

n:=Input("Periods",1,253,14);
zero:=Power(10,-10);

r1:=H-L;
r2:=Abs(H-Ref(C,-1));
r3:=Abs(Ref(C,-1)-L);

TrueRange:=Max(Max(r1,r2),r3);

TrueHighPds:=Max(HHV(H,n),Ref(C,-n));
TrueLowPds:=Min(LLV(L,n),Ref(C,-n));
TrueRangePds:=TrueHighPds-TrueLowPds;

VolatilityRatio:=TrueRange/Max(TrueRangePds,zero);

{plot VR}
VolatilityRatio;

Builing a Trading System using Volatility Ratio

Now to understand the predictive nature of Volaitity Ratio in idenfitying price reversal we built a simple trading system

The concept is to Buy when Volatility ratio is greater than 0.6 and the past 5 days returns are negative and on the reverse short if the Volatility ratio is greater than 0.6 and the past 5 days returns are positive. And now exit after 10 days of holding the instrument.

We tested the trading system with our benchmark index Nifty on the Daily timeframe. Here is the results about the predictive nature of the indicator followed by snapshots of the signals when volatility ratio crosses 0.6 with period =13

Parameters
Results
Tested SymbolNSENIFTY
Total Number of Trades52
Holding Period10 Days
Winning Trades32
Winning Ratio 61.54%
Points Earned2000 Nifty points
Testing Period1991-2012 (23 years)

Charts below the buy and sell indications for the past 5 years when the volatility ratio shoots above 0.6

Nifty Daily Chart – 2007
Nifty 2007

Nifty Daily Chart – 2008
Nifty 2008

Nifty Daily Chart – 2009
Nifty 2009

Nifty Daily Chart – 2010
Nifty 2010

Nifty Daily Chart – 2011
Nifty 2011

Nifty Daily Chart – 2012
No signals during the year 2012 and 2013

Hope the above article gives your more understanding about the nature of volatility ratio. Test the indicator and provide your feedback here. Your feedback is much are appreciated

Related Readings and Observations

  • How to Plot Bid Vs Ask Dashboard in Amibroker Here is a little Bid Vs Ask Dashboard for Amibroker users which helps to monitor the Bid-Ask Spread during live trading. In a highly liquid market the Bid Ask spread difference will be […]
  • Simple Smoothed RSI Crossover Strategy Here is the simple smoothed RSI crossover strategy can be practiced on higher timeframes especially with daily timeframes with controlled risk. It catches the big trends and gets little […]
  • Intraday Gap Up and Gap Down – Amibroker Strategy Strategy is very simple. when the market open with gap up and at the same time ,it crossed the previous day high then it should be considered as strong buy. When the market open with gap […]
  • ATR Volatility Long Only Trading System Yet another ATR Volatility based Long only Trading System. ATR Volatility system a mechanical strategy for higher time-frames Written by Tudor Marcelin - Art Invest. Just modified the […]

Comments

  1. Dick says

    I found this RSI most interesting but noted no Buy/Sell arrows so added (see below). They should work but don’t so any help will be appreciated.
    Dick
    Note: send correction to me @ areehoi@yahoo.com
    Thanks

    SECTION_BEGIN(“Volatility”);
    //{Volatility Ratio -- Schwager}
    //Coded By Rajandran R -- http://www.marketcalls.in
    //Date -- 18 Feb 2012
    /*The concept is to Buy when Volatility ratio is greater than 0.6 and the past 5 days returns are negative and on the reverse short if the Volatility
    ratio is greater than 0.6 and the past 5 days returns are positive. And now exit after 10 days of holding the instrument.*/

    n=Param(“Periods”,13,1,300,1);
    VRT=Param(“VRthreshold”,0.6,0.5,1,0.1);
    Dday =Param(“Decision Day Based on Prev day returns”,4,3,5,1);
    zero=10^-10;

    r1=H-L;
    r2=abs(H-Ref(C,-1));
    r3=abs(Ref(C,-1)-L);

    TrueRange=Max(Max(r1,r2),r3);

    TrueHighPds=Max(HHV(H,n),Ref(C,-n));
    TrueLowPds=Min(LLV(L,n),Ref(C,-n));
    TrueRangePds=TrueHighPds-TrueLowPds;

    VolatilityRatio=TrueRange/Max(TrueRangePds,zero);

    SetPositionSize(1,spsShares);

    decisionSell=HHV(C,5)-C;
    decisionBuy=C-LLV(C,5);

    Buy =decisionBuy>0 AND Cross(VolatilityRatio,VRT);
    //Sell =0;
    Sell =decisionSell>0 AND Cross(VolatilityRatio,VRT);
    Cover=0;
    //Plot( Buy, “Buy”, colorBlack, styleLine );

    HLine = Param( “Upper Line” ,0.6, 60,95, 5);
    LLine = Param( “Lower Line”,0.2, 5, 40, 5);
    Plot( Lline, “0.6”, colorBrown,styleLine|styleDashed );
    Plot( Hline, “0.2”, colorBrown,styleLine|styleDashed );

    Plot(VolatilityRatio,”Volatility Ratio -- Schwager”,colorRed,styleThick);
    shape = Buy * shapeHollowUpArrow + Sell * shapeHollowDownArrow;
    PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
    PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorBrightGreen,0,L,-15);

    PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15);
    PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorRed,0,H,-15);

    _SECTION_END ();

    • Kannan says

      I tested this strategy using MetaStock. While this strategy performance is good post 2007, the period between 2000 to 2007 it actually lost money (almost all of it). How can the draw down could be reduced. Also wondering how Nifty data in Amibroker is available from 1991 when NSE started it from 1994.

  2. Karuna says

    Hello Sir, I want to know if you have a candlestick AFL. I want to scan for candlestick patterns. Is there a possibility to get realtime alerts? For example if a morning star pattern has occurred in SBIN, then it must alert me that SBIN has a morning star pattern.

    I want to congratulate you on all the new things that you bring on your website. Thanks for everything.

    Karuna

Leave a Reply

Your email address will not be published. Required fields are marked *