#### stone

##### Member
Hi, I noticed in TOS studies that it buys or sells 100 shares. Is it possible to create a study to back test for selling verticle credit spreads? I've been researching code today. I'm not a coder but the easiest strategy is to sell a put credit spread using the 30 & 15 Delta, when price is above 30SMA, 50SMA, and 200 SMA. The expiration is monthly's 30-40 days. Sell a call credit spread with the opposite happens price below 30, 50, 200SMA. After watching youtube this is what I came up with but I'm stuck. Any help would be appreciated.

input shortMA length = 30;
input mediumMA length = 50;
input longMA length = 200;

def shortMA = SimpleMovingAvg(length = shortMAlength;
def mediumMA = SimpleMovingAvg(length = mediumMAlength;
def longMA = SimpleMovingAvg(length = longMAlength;

YIKES!

Last edited by a moderator:
Solution
@stone Have you ever played with Simulate Trades on the Trade tab before...??? That's the quickest and simplest way to test various Options Strategies... Thinkorswim just doesn't provide the resources needed to adequately backtest Option Strategies, even with complex code...
@stone Are you thinking of having a Study/Strategy select your credit spread automagically, because that would be a daunting task at best using Thinkscript... The conditional triggers can be done, it's the calculation of proper options that presents the problem... Can you provide more details on your desires please...???

@stone Are you thinking of having a Study/Strategy select your credit spread automagically, because that would be a daunting task at best using Thinkscript... The conditional triggers can be done, it's the calculation of proper options that presents the problem... Can you provide more details on your desires please...???
hi, thanks for the quick response. just curious how to back test a strategy selling credit spreads. Is there a way? maybe using demand and going through dates? wow that's daunting. I just thought there would be a way to back test maybe every 10 days if price is over the SMA's?
I was just looking at another simple command maybe would be 10 day expire, price above 200 and 30 sma, sell a put spread at -.15 delta. and the short leg just below that. Any thoughts would be great. Just wanting to back test that.

@stone Have you ever played with Simulate Trades on the Trade tab before...??? That's the quickest and simplest way to test various Options Strategies... Thinkorswim just doesn't provide the resources needed to adequately backtest Option Strategies, even with complex code...

Last edited by a moderator:
@stone Have you ever played with Simulate Trades on the Trade tab before...??? That's the quickest and simplest way to test various Options Strategies... Thinkorswim just doesn't provide the resources needed to adequately backtest Option Strategies, even with complex code...
Rad, I've never used that. So it is a little faster thank using on demand based on slow buffer (could be my laptop). Though it is time consuming. So another idea. I noticed on all strategies withing floating P/L; the code says.. Example at the end of the strategy. Is there a way to code buy a call or sell a call? The p/l is so different with options...hence maybe I can use an already coded strategy but dictate an option class of some sort? By the way thank you for all u do.
AddOrder(OrderType.BUY_AUTO, diff crosses above 0, tickColor = GetColor(0), arrowColor = GetColor(0), name = "MACDStratLE");
AddOrder(OrderType.SELL_AUTO, diff crosses below 0, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACDStratSE");

@stone We can only apply AddOrder() to the current chart symbol so, no, there is no way to tell Thinkscript we want to Buy or Sell an Option...

Last edited:

87k+ Posts
458 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?