Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

Schwager Volatility Ratio Amibroker AFL code and Analysis

1 min read

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.

[wp_ad_camp_5]

 
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

ParametersResults
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

Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in)

[Live Coding Webinar] Build Your First Trading Bridge for…

In this course, you will be learning to build your own trading bridge using Python. This 60-minute session is perfect for traders, Python enthusiasts,...
Rajandran R
1 min read

[Webinar] Understanding and Mitigating Curve Fitting in System Trading

"Understanding and Mitigating Curve Fitting in System Trading"! This dynamic session aims to equip novice to intermediate traders, quantitative analysts, and financial engineers with...
Rajandran R
1 min read

P-Signal Strategy Long Only Strategy – Amibroker AFL Code

This tutorial provides an overview of the P-Signal reversal strategy, a quantitative trading strategy that utilizes statistical parameters and error functions to generate probabilistic...
Rajandran R
2 min read

8 Replies to “Schwager Volatility Ratio Amibroker AFL code and Analysis”

  1. 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 @ [email protected]
    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 ();

  2. thanks for ur valuable effort ,plse guide me how to copy into ami charts the above afl code

    1. 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.

  3. 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

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More