Incompatible parameter

TickTockTony

New member
VIP
Would anyone be kind enought to point out whats gong wrong with this code. I get a red box on the def statment and "Incompatible parameter: "RSI" at 17:5".

I have been screwing with it all day now.


#My Backtesting code Tony Baker 9-22-2023
#for MarketForecast and RSI
#


#marketForcaster definitions
input OverBought = 80;
input OverSold = 20;
input Show_Labels = yes;
input Show_Clusters = yes;
input price = close;
input length = 14;


def MF_Cluster = MarketForecast()."intermediate" < 20 and
MarketForecast()."Momentum" < 20 and
MarketForecast()."NearTerm" < 20 ;

#plot data = RSI()."RSI" crosses above 50 and MF_cluster is true within 10 bars;


AddOrder(OrderType.BUY_AUTO, MF_Cluster) ;

#AddOrder(OrderType.BUY_AUTO, RSI > 50 and RSI[1] < 50 and MF_Cluster == 1 within 10 bars) ;

AddOrder(OrderType.BUY_AUTO , "RSI"> 50 and "RSI[1]" < 50 and MF_cluster is true within 10 bars) ;
 
Solution
change:
AddOrder(OrderType.BUY_AUTO , "RSI"> 50 and "RSI[1]" < 50 and MF_cluster is true within 10 bars) ;
to:
def yRSI = RSI();
AddOrder(OrderType.BUY_AUTO , yRSI> 50 and yRSI[1] < 50 and MF_cluster is true within 10 bars) ;
The above will get rid of the error that you mentioned in your post.

I didn't play with the rest of your script but noticed:
1. you have a bunch of inputs which are not being used.
2. you do not have a sell order.
change:
AddOrder(OrderType.BUY_AUTO , "RSI"> 50 and "RSI[1]" < 50 and MF_cluster is true within 10 bars) ;
to:
def yRSI = RSI();
AddOrder(OrderType.BUY_AUTO , yRSI> 50 and yRSI[1] < 50 and MF_cluster is true within 10 bars) ;
The above will get rid of the error that you mentioned in your post.

I didn't play with the rest of your script but noticed:
1. you have a bunch of inputs which are not being used.
2. you do not have a sell order.
 
Solution
Thanks V much for fixing my problem.
Yes I know about the unused inputs, the code is a work in progress.
Yes the code is the buy side ,in order for me to evaluate sell stratagies using "Floating P/L"
I have tried to reserch but can not find any reference to "def yRSI = RSI();". What does it do?
 
Thanks V much for fixing my problem.
Yes I know about the unused inputs, the code is a work in progress.
Yes the code is the buy side ,in order for me to evaluate sell stratagies using "Floating P/L"
I have tried to reserch but can not find any reference to "def yRSI = RSI();". What does it do?

You had a syntax error every time you referenced the RSI()
If referencing a ToS study multiple times; generally accepted coding practices suggest that you store it as a variable in a def statement so to minimize the number of calls.
def yRSI = RSI();
This will keep your script as efficient as possible.

But technically, you could have just fixed your syntax errors.
You originally coded:
AddOrder(OrderType.BUY_AUTO , "RSI"> 50 and "RSI[1]" < 50 and MF_cluster is true within 10 bars) ;
but ToS requires you to have () parentheses when referencing ToS studies.
The correct syntax:
AddOrder(OrderType.BUY_AUTO , reference RSI()."RSI" > 50 and reference RSI()."RSI"[1] < 50 and MF_cluster is true within 10 bars) ;

FYI:
Nobody writes all that out. ToS knows that it is a reference, so everybody leaves the reference word out.
AND the RSI is the 1st plot in the study so, it is the default. So everybody leaves off the
."RSI"
Shortcut correct syntax:
AddOrder(OrderType.BUY_AUTO , RSI() > 50 and RSI()[1] < 50 and MF_cluster is true within 10 bars) ;
 
Last edited:
@TickTockTony
also remember that parentheses are your friend:

this:
(RSI() > 50 and RSI()[1] < 50 and MF_cluster is true) within 10 bars
is very different from:
RSI() > 50 and RSI()[1] < 50 and (MF_cluster is true within 10 bars)

Not sure which you are looking for because you didn't use any parentheses to explain what you want occurring within 10 bars.

The most correct syntax:
(RSI() > 50 within 10 bars) and
(RSI()[1] < 50 within 10 bars) and
(MF_cluster is true within 10 bars)
IF that is what you are looking for.
It should be noted that running this iteration through the 10 past bars will start to make this script resource-intensive.

While it will work for creating AddOrder plots on a chart.
Depending on how much more you add on to this strategy; it may get too complex for conditional orders, watchlists, scans, or any other ToS widget.

hope this helps.
 
Last edited:
Whats the best way for me to lean thinkscript? as an hardware engineer I always picked up coding from looking at examples of how others performed a task and built my code like lego bricks from bits I know.
 
Whats the best way for me to lean thinkscript? as an hardware engineer I always picked up coding from looking at examples of how others performed a task and built my code like lego bricks from bits I know.

Learning ThinkScript:
https://usethinkscript.com/p/learn-thinkorswim-coding-language/
https://tlc.thinkorswim.com/center/reference/thinkScript/tutorials

ThinkScript started as a simple plot scripting code. What traders have managed to make it do, is mostly undocumented and amazing.
So you are correct, the best way is looking at examples.
useThinkScript is the largest repository of ToS code on the web.

For instance, if you are feeling your way around the RSI, this one thread has a dozens and dozens of examples:
https://usethinkscript.com/threads/rsi-format-label-watchlist-scan-for-thinkorswim.798/ which will prevent future syntax errors.

Also consider collinearity, timeframes and these other factors when building a good basic strategy:
https://usethinkscript.com/threads/best-time-frame-for-trading-for-thinkorswim.12209/
 
Last edited:

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