How to import existing thinkScript code on ThinkorSwim

That image appears to be in TradingView, not Thinkorswim by the looks of the left hand side of that image... Any conversions need to be done in TOS, not TV, or you will get errors from TV just like you would with a direct Copy and Paste of TV code into the TOS code editor panel...
 
I get an error cutting and pasting:
https://usethinkscript.com/threads/auto-avwap-anchored-vwap-for-thinkorswim.20659/

No such variable: hiAVWAP_s1 at 104:5
No such variable: hiAVWAP_v1 at 105:5
No such variable: hiAVWAP_s1 at 108:5
No such variable: hiAVWAP_v1 at 109:5
No such variable: state at 112:5
No such variable: state at 114:5
No such variable: loAVWAP_s at 119:5
No such variable: loAVWAP_v at 120:5
No such variable: loAVWAP_s at 123:5
No such variable: loAVWAP_v at 124:5
Expected double
Expected double at 108:5
Expected double at 109:5
Expected double at 114:5
Expected double at 123:5
Expected double at 124:5
No such variable: dphi1 at 93:5
No such variable: lowhi1 at 102:20
No such variable: hiAVWAP_s at 108:18
No such variable: hiAVWAP_v at 109:18
 
Last edited by a moderator:
I get an error cutting and pasting:
https://usethinkscript.com/threads/auto-avwap-anchored-vwap-for-thinkorswim.20659/

No such variable: hiAVWAP_s1 at 104:5
No such variable: hiAVWAP_v1 at 105:5
No such variable: hiAVWAP_s1 at 108:5
No such variable: hiAVWAP_v1 at 109:5
No such variable: state at 112:5
No such variable: state at 114:5
No such variable: loAVWAP_s at 119:5
No such variable: loAVWAP_v at 120:5
No such variable: loAVWAP_s at 123:5
No such variable: loAVWAP_v at 124:5
Expected double
Expected double at 108:5
Expected double at 109:5
Expected double at 114:5
Expected double at 123:5
Expected double at 124:5
No such variable: dphi1 at 93:5
No such variable: lowhi1 at 102:20
No such variable: hiAVWAP_s at 108:18
No such variable: hiAVWAP_v at 109:18

Your error is caused by not copying the complete script and ONLY the script.

When copied correctly, you should not see any errors and the OK button should be green.
3XklNKl.png
 
Y’all seen the new add-on?
gmXsuGp.png


Copying those massive code blocks is now a breeze!
1. scroll down to the code block
2. click on the Copy to clipboard button at the top of the code block
3. the code can now be pasted into your study tab!

Perfect for testing out the indicators highlighted in this week's newsletter!


FYI:
If you are not receiving the newsletter,
1. check your preferences in your useThinkScript account settings (click on your avatar)
z7w0WSO.png


2. check your email spam folder
Want to read previous newsletters? Jump over to the newsletter archive forum:
https://usethinkscript.com/forums/newsletter-archive.81/
 
Hi, I am new here and have several questions. I think posting them separately is considered best practice. Thanks in advance for any assistance.

1. How do I use custom indicators in a strategy? I have some indicators from scripts, (mostly found here). But when I try to use them when building a strategy they do not appear under studies in the "inspector". So I do not know how get them into a strategy script. Can any one tell me.

For reference I am going to post the code for one of the indicators I am trying to use. It might mean something.
I did not write any of this.

A) code for an LSMA averge or predictor
Code:
#LeastSquares created by tradescripter
#Dec. 24, 2010 Merry Christmas
#It uses the Least-Squares Method to forecast a new price
#For an explanation of Least-Squares method see:
#http://en.wikiversity.org/wiki/Least-Squares_Method


#Hint PriceColorOn: Affect the color of the Price bars according to the signals of this indicator\n<b>Default is Yes
#Hint ArrowsOn: Plot Arrows at signal changes \n<b>Default is Yes
#Hint PredictionLineOn: Plot the indicator \n<b>Default is Yes
#Hint ShowTodayOnly: Plot only the most recent arrows in order not to clutter the Price history\nMakes it easier to see prior prices \n<b>Default is no
#Hint ShowExtraDays: Further adjustment to Show Only Today \n<b>Default is 0
#Hint space: Allows you to move the arrows, and avoid stepping on other arrows when multiple studies are shown \n<b>Default is 0.333
#Hint length: Touch this only if you are an expert! Just kidding. \n<b>Default is 9
#Hint price: For the experimenter \n<b>Default is HL2


#FuturePredictor

input price = close;
input length = 9;
input PredictionLineOn = Yes;
# Input BubblesOn = No;
input ShowTodayOnly = no;
input ShowExtraDays = 0;
input space = 0.333;


def Today = if !ShowTodayOnly then 1 else if GetDay() + ShowExtraDays >= GetLastDay() then 1 else 0;

def AvgPrice = Average(price, length);
def SumTime = fold i = 1 to length + 1 with x = 0 do x + i;
def AvgTime = SumTime / length;
#sx is the sum of all the deviations from time for the last x bars
def sx = fold j = 1 to length + 1 with y = 0 do y + ((j - AvgTime) * (GetValue(price, length - j, length + 1) - AvgPrice));
#sy is the sum of all the deviations from price for the last x bars
def sy = fold k = 1 to length + 1 with z = 0 do z + (Power(k - AvgTime, 2));
#m is the slope of the line, b is the slope intercept of the line in the equation y = mx + b
def m = sx / sy;
def b = AvgPrice - m * AvgTime;
def Prediction = (m * (length + 1)) + b;
plot FuturePrediction = if !PredictionLineOn then Double.NaN else Prediction;
FuturePrediction.AssignValueColor(if FuturePrediction > FuturePrediction[1] then Color.GREEN else Color.RED);
FuturePrediction.SetLineWeight(3);
FuturePrediction.HideBubble();

I have indicators I have added manually. I can not see them when trying to develop strategies. As in for example

def buy = myindicatator says bullish. My indicator is not listed in inspector. Even though I use it on charts.

Any information appreciated. Thank you
 
Last edited by a moderator:
Hi, I am new here and have several questions. I think posting them separately is considered best practice. Thanks in advance for any assistance.

1. How do I use custom indicators in a strategy? I have some indicators from scripts, (mostly found here). But when I try to use them when building a strategy they do not appear under studies in the "inspector". So I do not know how get them into a strategy script. Can any one tell me.

If your question is:
How to import a forum study into your ThinkOrSwim chart?

Answer:
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/

If your question is:
How to reference your custom study?
Sadly no, while you can reference ToS built-in studies; it is not possible to reference custom studies
You must cut and paste them into your strategy

FYI: how to share code in a forum post:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58016
 
Last edited by a moderator:
If your question is:
How to import a forum study into your ThinkOrSwim chart?

Answer:
https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/

If your question is:
How to reference your custom study?
Sadly no, while you can reference ToS built-in studies; it is not possible to reference custom studies
You must cut and paste them into your strategy

FYI: how to share code in a forum post:
https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/#post-58016
Oh okay. So you're saying I have to paste the entire indicator code into the strategy code.
That could get a little complicated as I may use more than one indicator in the strategy.
But I will try it. Thanks for your help
 
Oh okay. So you're saying I have to paste the entire indicator code into the strategy code.
That could get a little complicated as I may use more than one indicator in the strategy.
But I will try it. Thanks for your help

Depending on what data you need from other indicators you can reference that data, as long as it is Plot data, but only from licensed indicators... You cannot reference Def data... User-Defined indicators must be incorporated into your Strategy code... To clarify, we can reference ANY indicator that comes default within Thinkorswim whether classified as licensed or not...

And example of referencing licensed indicator data would be:

Ruby:
. . . .
def rsi = reference RSI(length=14)."RSI";
def ema20 = reference MovingAvgExponential(price=close, length=20)."AvgExp";
def upperband = reference BollingerBands()."UpperBand";
. . . .

In the example above the Plot names are in quotation marks...

Hope this helps...
 
Last edited:
Depending on what data you need from other indicators you can reference that data, as long as it is Plot data, but only from licensed indicators... You cannot reference Def data... User-Defined indicators must be incorporated into your Strategy code... To clarify, we can reference ANY indicator that comes default within Thinkorswim whether classified as licensed or not...

And example of referencing licensed indicator data would be:

Ruby:
. . . .
def rsi = reference RSI(length=14)."RSI";
def ema20 = reference MovingAvgExponential(price=close, length=20)."AvgExp";
def upperband = reference BollingerBands()."UpperBand";
. . . .

In the example above the Plot names are in quotation marks...

Hope this helps...
Thank you. I doubt these are licensed. But it may give another idea.
 

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
453 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