Options: Intraday moving average for option spread

bnnnboy

New member
I am trying to put together a script for a conditional order that will route an order when an option spread (in this case a strangle) marks at a certain price, but compute a moving average of he price for the last X minutes to eliminate random bad marks that will sometimes trigger alerts.

I put together a script (see below) and it works well when I set the Condition Setup at the top of the window to 1 day, but if I set it to 1 minute it doesn't return any results and won't trigger. My guess is it has something to do with me using "close" instead of something to see the mark of the options, but I don't know how to pull the mark of a specific option.

Can someone help me pull the mark of a specific option? Is there a better way to accomplish what I'm trying to do?

Code:
def period = AggregationPeriod.MIN;
def dura = 10;
input PutStrike = 220;
input CallStrike = 230;
input underlyingEXP = ".IWM211015";

plot avg = Average(close(concat(underlyingEXP, concat("C", concat(CallStrike, ""))))+close(concat(underlyingEXP, concat("P", concat(PutStrike, "")))),dura);

1Day settings: https://www.dropbox.com/s/aobgx5n15uph2k9/1day_condition_data.png?dl=0
1Min settings: https://www.dropbox.com/s/5by2bpv6yngecdk/1min_condition_nodata.png?dl=0

Thanks!
 
Solution
I think I've figured it out. I just had to add a PriceType.Mark in the close command. Modified code:

Code:
def period = AggregationPeriod.MIN;
def dura = 10;
input PutStrike = 220;
input CallStrike = 230;
input underlyingEXP = ".IWM211015";

plot avg = Average(close(concat(underlyingEXP, concat("C", concat(CallStrike, ""))), priceType = PriceType.MARK)+close(concat(underlyingEXP, concat("P", concat(PutStrike, ""))), priceType = PriceType.MARK),dura);
I think I've figured it out. I just had to add a PriceType.Mark in the close command. Modified code:

Code:
def period = AggregationPeriod.MIN;
def dura = 10;
input PutStrike = 220;
input CallStrike = 230;
input underlyingEXP = ".IWM211015";

plot avg = Average(close(concat(underlyingEXP, concat("C", concat(CallStrike, ""))), priceType = PriceType.MARK)+close(concat(underlyingEXP, concat("P", concat(PutStrike, ""))), priceType = PriceType.MARK),dura);
 
Solution
So I've noticed this study isn't working lately and I can't figure out why. For example, if I look at a 1m chart of GLD and add the study, I can select the call and put strikes as inputs (say 176 and 161 respectively) and enter the "underlying exp" input as .GLD220218 in the study settings, but when I apply the study the output on the chart shows the avg as N/A. I only modified the inputs in the "Edit Studies and Strategies" window, though I even tried changing the strikes and underlying info in the study itself with no luck. Any idea what's happening that's causing the study to fail?
 

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