Complete Noob - Need Script for Trading Strategy

Afterwork

New member
I am trying to create a script that uses Wilders RSI set at 10,40,30,Close and SMA of 200. I want to buy when RSI is below 30 and sell when it is above 40 or ten trading days. How would I do this?
 

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

If price is above the 200 SMA and Under 30 RSI Buy - (Buy Conditions)
If RSI is over 40 or after 10 Trading days Sell -(Sell Conditions)
I spent 2 Weeks back testing took forever - And if I want to change one small thing I would be back to 2 weeks back testing. I also plan on setting up a bearish market version. Just new to scripting the whole thing. Once I can see how the above script would work then I should have no issues.
 
If price is above the 200 SMA and Under 30 RSI Buy - (Buy Conditions)
If RSI is over 40 or after 10 Trading days Sell -(Sell Conditions)

Have you put forth any effort into creating a Strategy as yet, or just want someone to create one for you...??? We don't generally just bang out code upon request but we're willing to help you along... It would start with converting existing Studies into Strategies and then merging the RSI with the SMA... When I started using Thinkorswim I had to learn how to work with Thinkscript just as everyone else had to... My suggestion would be to start out by converting the RSI Study to a Strategy - essentially copying the code over, and then adding AddOrder() functions using your logic... If you put forth the effort I'll help you along but I'm no longer going to just code for others... I have found that members won't learn anything if they don't try - just like everything else in life... Take that how you like, but that's where I'm at... I'm always willing to help others who are willing to help themselves...
 
Have been trying to code this for a scan Buy conditions stock greater than 50 sma and Stochastic Full %k less than 40 also if 20 sma greater than 50 sma to make the setup stronger. Please give input
 
Last edited:
@Afterwork
I am not sure your filter of selling after 10 trading days can be implemented on the TOS platform. Defined variables related to portfolio management that can be used in scripts are limited. If someone knows a P&L field available to scripts the following logic would work
Ruby:
input HowManyDays = 10;
def CountDays = if variable_name != 0 then 1 else 0;

plot TriggerMaxDays = if sum(CountDays, HowManyDays) == HowManyDays then 1 else 0 ;

As for the rest of your request
  • buy criteria = RSI under 30 and price over EMA200
  • sell criteria = RSI over 40
Ruby:
input rsi_length    = 10 ;
def rsi = reference RSI("length" = rsi_length)."RSI" ;

# ########################################################
def BuyCriteria =
#If price is above the 200 SMA
close > MovAvgExponential("length" = 200)."AvgExp" and
#WHILE the RSI is under 30.
rsi is less than 30 ;

def SellCriteria =
#If RSI is over 40
rsi is greater than 40 ;

# ########################################################
#Order Management
AddOrder(OrderType.BUY_AUTO, BuyCriteria, tickcolor = Color.YELLOW, arrowcolor = Color.BLACK, name = "Buy", tradeSize = 100);
AddOrder(OrderType.SELL_TO_CLOSE, SellCriteria, tickcolor = Color.PINK, arrowcolor = Color.RED, name = "sell", tradeSize = 100);
# ########################################################

I provide this script per a poster's request. I personally would not trade this strategy. There are many better RSI strategies on this forum that can be found using the search function.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
618 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