• Get $40 off VIP by signing up for a free account! Sign Up

TradingView VWAP ATR script to TOS?


Well-known member
Can this script be converted to TOS?

TOS doesn't let you re-use variables, or assign more than once, and my attempts to convert this always hit one error or another.

The other issue seems to also be using "stop" on line 23, when it is set again on line 25. I think Pine Script has the := to set immediately, but I think TOS works differently...

Anyone care to tackle this one, or have ideas how to work around this code construct in TOS?
@korygill The only way I know how to get around "re-using" variables is via a switch statement or an if-then-else construct such as the following. Otherwise it's not possible to re-use variables as you've noted

def variable1;
def variable2;

if close > open
then {
    variable1 = 1;
    variable2 = 2;
} else if close < open
then {
    variable1 = 2;
    variable2 = 1;
} else {
    variable1 = variable1[1];
    variable2 = variable2[1];
Last edited:
Thanks @tomsk. The issue I have is

hi:= hi[1]? high[1]>=stop[1] ? false : true : low[1]<=stop[1] ? true : false
stop:=hi ? max : min
stop:= hi ? hi[1]==false ? stop : stop>stop[1] ? stop[1] : stop : hi[1] ? stop : stop<stop[1] ? stop[1] : stop

Line 3, stop used before declared or assigned (by TOS)
Line 4 assignment
Line 5, TOS does not like stop = stop

I've even tried

if BarNumber() == 1
init vars
other logic

But no matter what, TOS throws a fit on one line or another. I've even tried creating intermediate vars, etc.

I've studied that indicator, and not sure how else to express it.

TOS is great for the most part, but TradingView and Sierra are light years ahead of thinkscript.
@RobertPayne, do you have any guidance here for this type of code and thinkscript?

The CompoundValue() function allows you to set an initial value then change that value based on whatever criteria you set. I am not familiar with Pine script, but I believe this snippet can be translated in the following manner.


def hi = CompoundValue(true, if hi[1] then (if high[1] >= stop[1] then false else true) else (if low[1] <= stop[1] then true else false), 1);

I haven't loaded this into TOS and am just throwing out an idea. You'll have to play around and test it yourself.

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