Think or Swim's 10 and 30 Day Historical Volatility Comparison

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #112083 quote
    Bard
    Participant
    Master
    Hi, I’m in the process of converting a couple of Ameritrade’s “Think or Swim” options platform volatility indicators here for PRC users and just wondered what I’m missing code wise to get this particular indicator to also produce negative results instead of just positive results only. Thanks.

    “This indicator is similar to HVIV and plots the difference between two time periods of Historical Volatility.  For example, we can plot the difference between 10 day and 30 day HV.  When the value is positive, it means the market has been more volatile over the past 10 days than the past 30.  When the value is negative, the market has been calmer than the previous 30 days.  The slope of the indicator also helps you understand how quickly the relationship is changing. Note the significant divergence between the August 2015 and January 2016 sell-off’s.” http://www.thetatrend.com/4-volatility-indicators-for-options-trading-with-thinkorswim-thinkscript-code/

    Here’s the PRC code and chart image:
    //HV 10 and 30 Difference
    //Provides difference between 2 Historical Volatility periods (10 and 30 day)
    
    //Period Inputs
    period = 252
    shortLength = 10
    longLength = 30
    
    Price = Log(close / close[1])
    
    //Calculate Values
    HVShort = std(Price)[shortLength] * Sqrt(shortLength * period) / (shortLength - 1)
    HVLong = std(Price)[longLength] * Sqrt(longLength * period) / (period - 1)
    
    HVdifference = HVShort-HVLong
    
    Return 0 as "0", HVdifference as "Historic Volatility 10-30 Day"
    
    Here’s the original code and image:
     #HVdifference
     #Provides difference between 2 HV periods (10 and 30 day)
     #Feel free to share the code with a link back to thetatrend.com
     declare lower;
     declare hide_on_intraday;
     #Period Inputs
     input longLength = 252;
     input shortLength = 10;
     input shortLengthb = 30;
     def clLog = Log(close / close[1]);
     #Calculate Values
     def HV = stdev(clLog, shortLength) * Sqrt(shortLength * longLength / (
     shortLength - 1));
     def HV2 = stdev(clLog, shortLengthb) * Sqrt(shortLengthb * longLength
     / (shortLengthb - 1));
     #Plot
     plot diff = HV-HV2;
     diff.SetDefaultColor(GetColor(0));
     plot zero = 0;
     zero.SetDefaultColor(Color.Black);
    HV-10-and-30-Difference.png HV-10-and-30-Difference.png Ameritrade-HV-10-and-30.png Ameritrade-HV-10-and-30.png
    #112114 quote
    Vonasi
    Moderator
    Master
    Bard – You double posted topics. I deleted the other one. Please try to be more careful when posting.
    #112141 quote
    Bard
    Participant
    Master
    I haven’t double posted. If you read the post/look at the images you can see that. It was my first post for a different Think or Swim indicator. It just had a similar intro but it’s for a 20 and 60 day Historic Volatility with a 20 Implied Vol line too. Can you please put it back up, thanks.
    #112157 quote
    Vonasi
    Moderator
    Master
    Can you please put it back up, thanks.
    Not possible I’m afraid. Deleted is deleted. Can I suggest that in the future to avoid confusion you do not post two topics at the same time with similar titles (if not identical titles if I recall) and very similar content about virtually identical subjects and with identical introductions! If I hadn’t deleted one of them then it would just end up in complete confusion for those trying to answer one or both of the posts anyway. Why not ask one question at a time and then move on to the alternative indicator version as the the topic progresses?
    #112163 quote
    Nicolas
    Keymaster
    Master
    The syntax for the STD instruction is not right. Period is before applied price: There is also difference in what should be square rooted, I fixed it. (not tested!)
    //HV 10 and 30 Difference
    //Provides difference between 2 Historical Volatility periods (10 and 30 day)
    
    //Period Inputs
    period = 252
    shortLength = 10
    longLength = 30
    
    Price = Log(close / close[1])
    
    //Calculate Values
    HVShort = std[shortLength](Price) * Sqrt(shortLength * period / (shortLength - 1))
    HVLong = std[longLength](Price)* Sqrt(longLength * period / (period - 1))
    
    HVdifference = HVShort-HVLong
    
    Return 0 as "0", HVdifference as "Historic Volatility 10-30 Day"
    Bard thanked this post
    #112181 quote
    Bard
    Participant
    Master
    Phew, good job I didn’t have time to post the other ones! I would have described them all with the same intro because they are all from Ameritrade’s Think or Swim platform but I understand the possible confusion to someone who doesn’t read the title or description of what these distinct indicators do — they have diferent titles and functions giving you different insights and ways to monitor (future) option premium pricing. Btw, why put two, (three or four) indicators all into one thread, that sounds more confusing to me and would make them harder to find? I really would prefer to share them as separate posts if it’s ok with you because I think possible different technical questions about the different indicators would result in a confusing and disjointed thread, no?
    #112184 quote
    Bard
    Participant
    Master
    Cheers, the correct way is actually how I had written it.. until the moment right before I posted it and re-read the original code! Why does the short length period code come before the price code in the PRT version? I mean are we not taking the std of price movements? Also it should also give negative values and look like the Think or Swim (white) image’s indicator scale? (Note my unused green zero line – in my PRT black image).
    #112192 quote
    Nicolas
    Keymaster
    Master
    Why does the short length period code come before the price code in the PRT version? I mean are we not taking the std of price movements?
    ?! Why are you asking this question. This is just how the syntax of any instruction is made: keyword[period](appliedprice) Because you changed the variables names, the code is all scrambled, anyway I took the time to recoded it from scratch: (now give negative values)
    //#Period Inputs
    longLength = 252
    shortLength = 10
    shortLengthb = 30
    clLog = Log(close / close[1])
    //#Calculate Values
    HV = std[shortLength](clLog) * Sqrt(shortLength * longLength / (shortLength - 1))
    HV2 = std[shortLengthb](clLog) * Sqrt(shortLengthb * longLength/ (shortLengthb - 1))
    //Plot
    diff = HV-HV2
    return diff,0
    #112259 quote
    Bard
    Participant
    Master
    Because the PRT syntax is illogical in it’s order! Right, using “price” and not another expression to describe the log of closing prices…  Thanks Nicolas.
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Think or Swim's 10 and 30 Day Historical Volatility Comparison


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Bard @brad Participant
Summary

This topic contains 8 replies,
has 3 voices, and was last updated by Bard
6 years, 3 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/04/2019
Status: Active
Attachments: 2 files
Logo Logo
Loading...