• Get $40 off VIP by signing up for a free account! Sign Up

Conditional Order triggering regardless of script study

bnnnboy

New member
I am trying to create a study-based conditional order and am finding that ToS thinks the study meets the conditional requirements, regardless of what I enter as the trigger threshold. Here is the script I'm trying to use:

Code:
input dura = 10;
input agg = AggregationPeriod.MIN;
input PutStrike = 175;
input CallStrike = 214;
input underlyingEXP = ".IWM220318";
def na = double.nan;

input show_option_plots = yes;

def call_mark1 = close(Concat(underlyingEXP, Concat("C", CallStrike)), period = agg, priceType = PriceType.MARK);
def call_mark2 = if isnan(call_mark1) then call_mark2[1] else call_mark1;

def put_mark1 = close(Concat(underlyingEXP, Concat("P", PutStrike)), period = agg, priceType = PriceType.MARK);
def put_mark2 = if isnan(put_mark1) then put_mark2[1] else put_mark1;

plot avg = Average((call_mark2+put_mark2),dura);
avg.setdefaultcolor(color.magenta);

plot cmark =  if show_option_plots then call_mark2 else na;
cmark.setdefaultcolor(color.blue);

plot pmark = if show_option_plots then put_mark2 else na;
pmark.setdefaultcolor(color.red);

That study creates the following chart, so it looks like the script is working as it should:
UIWdHFK.png


My process for creating the conditional order is to create the order (in this case the 18Mar22 IWM 175/214 strangle), click on the gear icon next to the exchange selection, then under the Conditions section of the page I select IWM for the symbol and then select Edit Study for the method which brings me to the Study Order Condition window. I change the aggregation to 1-minute, add my study and verify the input are correct, fill out the trigger condition, and make sure the AlertValue looks reasonable:
QzGvylh.png

After I click OK I am back at the Order Rules window and it looks like this:
nHkNVqr.png


I click Save and then send the order. Within seconds the order is "WORKING" instead of "WAIT COND", despite the Alert value being ~1.88 and my trigger being "less than or equal to 1.30". I tried making it greater than just in case there some weird inverse comparison going on, but it still went to "WORKING" within seconds. What is going on here? Am I missing something? Is this an issue with my script, or the order, or ToS, or me?
 
Solution
I contacted ToS support a week or two ago about this and they were confused by the behavior as well. It seems ToS may not be handling the numeric output of the study correctly. They suggested two changes that seem to be working for now:
1) modify the script so the output is a boolean rather than a numeric value:
Code:
input dura = 10;
input agg = AggregationPeriod.MIN;
input PutStrike = 175;
input CallStrike = 214;
input underlyingEXP = ".IWM220318";
def na = double.nan;

input show_option_plots = yes;

def call_mark1 = close(Concat(underlyingEXP, Concat("C", CallStrike)), period = agg, priceType = PriceType.MARK);
def call_mark2 = if isnan(call_mark1) then call_mark2[1] else call_mark1;

def put_mark1 = close(Concat(underlyingEXP...
I contacted ToS support a week or two ago about this and they were confused by the behavior as well. It seems ToS may not be handling the numeric output of the study correctly. They suggested two changes that seem to be working for now:
1) modify the script so the output is a boolean rather than a numeric value:
Code:
input dura = 10;
input agg = AggregationPeriod.MIN;
input PutStrike = 175;
input CallStrike = 214;
input underlyingEXP = ".IWM220318";
def na = double.nan;

input show_option_plots = yes;

def call_mark1 = close(Concat(underlyingEXP, Concat("C", CallStrike)), period = agg, priceType = PriceType.MARK);
def call_mark2 = if isnan(call_mark1) then call_mark2[1] else call_mark1;

def put_mark1 = close(Concat(underlyingEXP, Concat("P", PutStrike)), period = agg, priceType = PriceType.MARK);
def put_mark2 = if isnan(put_mark1) then put_mark2[1] else put_mark1;

def avg = Average((call_mark2+put_mark2),dura);
plot avgBool = avg <= 1.38;
2) that rather than inserting a saved script through the inspector tool, paste the script text directly into the thinkScript editor window.
 
Last edited by a moderator:
Solution

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