In today’s post, I’ll walk through the process I used to create my own automated custom back test directly inside Thinkorswim. I’ll use the back test I created but this information can be adapted to use with any indicator, entry, or exit trigger you prefer.
Create an Automated Custom Back Test in Thinkorswim Step – by – Step
- Start by removing any indicators currently on the chart. Make sure the chart is 100% clear before beginning so the back test parameter’s aren’t impacted.
- Add the 9 period Exponential Moving Average to the chart.
- Click the Studies tab, then search for the “FloatingPL” indicator and add it to the chart.
- Click the Strategies tab, then search for the “ProfitTargetLX” indicator and add it to the chart.
- Write the code for the custom strategy you prefer. The code for the bullish strategy I use is just below.
input price = close;
input MAlength = 9;
input displace = 0;def MA = MovAvgExponential(length = MAlength);
def call = open[-displace] < MA and close[-displace] > MA;
AddOrder(OrderType.BUY_TO_OPEN, call, price[-displace], name = “Call”, tradesize = 100, tickcolor = Color.CYAN, arrowcolor = Color.LIGHT_GRAY);
Code Updated 3/18/23 to include; entry at closing price of signal bar instead of opening price.
- Click the Strategies tab, then click create.
- Name the new strategy whatever you prefer and add the code above. Be sure to remove any current parameters already listed. Click create.
- Setup the profit target, stop loss, and displace parameters. Adjust the stop loss and profit target to your choice but in this instance be sure to set displace to a value of 1.

Closing Thoughts
That’s all there is! You’ve now created an automated custom back test in Thinkorswim to easily identify assets that may be good trading candidates for the listed criteria.
The sky is the limit to the number of automated custom back test in Thinkorswim you could create but this get’s you well on your way. Additionally, Thinkorswim comes pre-loaded with several strategies right out of the box so I would encourage everyone interested to sift through those to find one that may look promising.
Should you want to continue learning about Thinkscript, here is a dive into the basics from AlgoTrading101.com and should I be capable of assisting please reach me in the comments below.
God bless,
Jeff
Hi, is it possible to substitute the Buy and Sell orders with Put Credit Spreads order? This of course entails adding deltas for both legs, expiration, TP and SL. I am happy to be referred to documentation/products that would help me with that. Thank you
I would be willing to bet that is possible but I’m not sure how. You may Google hahn-tech as he is very knowledgeable about thinkscript.
God bless,
Jeff