Expected SPX Movement by timeframe For ThinkOrSwim

johnayw

New member
Please convert this tradingview script into Thinkorswim script. However please edit so that only two trendlines are formed. Showing upper trend line for weekly expected move if price is going up and one lower trend line showing weekly expected move if price is going down. I am hoping this script will Auto draw 2 lines every week that represent weekly expected move on chart. Line needs to act like trendline. One line for expected price if it is going up and one for bottom expected move for the week. The indicator needs to only show lines for the current week. I would really appreciate if anyone could create this custom script for me. Thank you

https://www.tradingview.com/script/t6D43IF3-Expected-SPX-Movement-by-timeframe/

THIS INDICATOR ONLY WORKS FOR SP:SPX CHART

This code will help you to measure the expected movement of SP:SPX in a previously selected timeframe based on the current value of VIX index

E.g. if the current value of VIX is 30 we calculate first the expected move of the next 12 months.
  • If you selected the Daily timeframe it will calculate the expected move of SPX in the next Day by dividing the current VIX Value by the squared root of 252
    (The 252 value corresponds to the approximate amount of trading sessions of the year)

    If you selected the Weekly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 52
    (The 52 value corresponds to the amount of weeks of the year)

    If you selected the Monthly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 12
    (The 12 value corresponds to the amount of months of the year)

    For lower timeframes you have to calculate the amount of ticks in each trading session of the year in order to get that specific range

Once you have that calculation it it'll provide the range expressed as percentage of the expected move for the following period.

This script will plot that information in a range of 2 lines which represents the expected move of the SPX for the next period

The red flag indicator tells if that period closed between the 2 previous values marked by the range
 
Last edited by a moderator:
Please convert this tradingview script into Thinkorswim script. However please edit so that only two trendlines are formed. Showing upper trend line for weekly expected move if price is going up and one lower trend line showing weekly expected move if price is going down. I am hoping this script will Auto draw 2 lines every week that represent weekly expected move on chart. Line needs to act like trendline. One line for expected price if it is going up and one for bottom expected move for the week. The indicator needs to only show lines for the current week. I would really appreciate if anyone could create this custom script for me. Thank you

https://www.tradingview.com/script/t6D43IF3-Expected-SPX-Movement-by-timeframe/

THIS INDICATOR ONLY WORKS FOR SP:SPX CHART

This code will help you to measure the expected movement of SP:SPX in a previously selected timeframe based on the current value of VIX index

E.g. if the current value of VIX is 30 we calculate first the expected move of the next 12 months.
  • If you selected the Daily timeframe it will calculate the expected move of SPX in the next Day by dividing the current VIX Value by the squared root of 252
    (The 252 value corresponds to the approximate amount of trading sessions of the year)

    If you selected the Weekly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 52
    (The 52 value corresponds to the amount of weeks of the year)

    If you selected the Monthly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 12
    (The 12 value corresponds to the amount of months of the year)

    For lower timeframes you have to calculate the amount of ticks in each trading session of the year in order to get that specific range

Once you have that calculation it it'll provide the range expressed as percentage of the expected move for the following period.

This script will plot that information in a range of 2 lines which represents the expected move of the SPX for the next period

The red flag indicator tells if that period closed between the 2 previous values marked by the range



// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rhvarelav

//THIS INDICATOR ONLY WORKS FOR SPX CHART

//This code will help you to measure the expected movement of SPX in a previous selected timeframe based on the current value of VIX index

//E.g. if the current value of VIX is 30 we calculate first the expected move of the Fwd TM.
// If you selected the Daily timeframe it will calculate the expected move of SPX in the next Day by dividing the current VIX Value by the squared root of 252
// (THe 252 value corresponds to the approximate amount of trading sessions of the year)

// If you selected the Weekly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 52
// (THe 52 value corresponds to the amount of weeks of the year)

// If you selected the Monthly timeframe it will calculate the expected move of SPX in the next Week by dividing the current VIX Value by the squared root of 12
// (THe 12 value corresponds to the amount of months of the year)

//// For lower timeframes you have to calculate the amount of ticks in each trading session of the year in order to get that specific range

//Once you have that calculation it it'll provide the range expressed as percentage of the expected move for the following period.

//This script will plot that information in a range of 2 lines which represents the expected move of the SPX for the next period

//The red flag indicator tells if that period closed between the 2 previous values marked by the range


//@version=5

indicator(title="Expected SPX Movement by timeframe", overlay=true)


print(txt) =>
// Create label on the first bar.
var lbl = label.new(bar_index, na, txt, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.large, text.align_left)
// On next bars, update the label's x and y position, and the text it displays.
label.set_xy(lbl, bar_index, ta.highest(10)[1])
label.set_text(lbl, txt)

//print("Period per timeframe: " +timeframe.period)
//print("Hello world!\n\n\n\n")

vixData = request.security("CBOE:VIX", timeframe.period, close)



scaleFreq = if timeframe.period == "D"
math.sqrt(252)
else if timeframe.period == "W"
math.sqrt(52)
else if timeframe.period == "M"
math.sqrt(12)
else if timeframe.period == "15"
math.sqrt(6552)
else if timeframe.period == "60"
math.sqrt(1638)
else if timeframe.period == "120"
math.sqrt(819)
else if timeframe.period == "240"
math.sqrt(409)
else
math.sqrt(252)



probPercMove = vixData / scaleFreq

changeUpper = close + (close * (probPercMove/100))
changeLower = close - (close * (probPercMove/100))


p1 = plot(changeUpper,'Probable Upper Level',#ffffff)
p2 = plot(changeLower,'Probable Lower Level',#ffffff)

fill(p1, p2, color=color.new(#ffffff, 90))

plotshape(not(close<= changeUpper[1] and close >= changeLower[1]), style=shape.flag, location=location.belowbar, color=color.rgb(188, 76, 76), size=size.small)
check the below.

CSS:
#// © rhvarelav
# indicator(title="Expected SPX Movement by timeframe", overlay=true)
# Converted by Sam4Cok@Samer - 01/2023

def vixData = Fundamental(FundamentalType.CLOSE, "VIX");
def agg = GetAggregationPeriod();

def na = Double.NaN;

def scaleFreq = if agg == AggregationPeriod.DAY then Sqrt(252) else
                if agg == AggregationPeriod.WEEK then Sqrt(52) else
                if agg == AggregationPeriod.MONTH then Sqrt(12) else
                if agg == AggregationPeriod.FIFTEEN_MIN then Sqrt(6552) else
                if agg == AggregationPeriod.HOUR then Sqrt(1638) else
                if agg == AggregationPeriod.TWO_HOURS then Sqrt(819) else
                if agg == AggregationPeriod.FOUR_HOURS then Sqrt(409) else Sqrt(252);

def probPercMove = vixData / scaleFreq;

def changeUpper = close + (close * (probPercMove/100));
def changeLower = close - (close * (probPercMove/100));


plot p1 = changeUpper;        # 'Probable Upper Level'
p1.SetDefaultColor(Color.WHITE);
plot p2 = changeLower;        # 'Probable Lower Level'
p2.SetDefaultColor(Color.WHITE);

#--- Cloud
AddCloud(p1, p2, Color.DARK_GRAY);

#--- Signals
def flag = close<= changeUpper[1] and close >= changeLower[1];
plot Sig = if !flag then changeLower else na;
Sig.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
Sig.SetLineWeight(3);
Sig.SetDefaultColor(Color.RED);

#--- END CODE
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
194 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top