Custom script not executing intraday options trade

dgmtradelive

New member
for the last 2+ months custom scripts I had been using for 6+ months have suddenly stop working. With dozens triggers but no execution. The Scripts were used to set the conditions in the order rules to buy Spy option contracts from the option chain. I've talked with TOS/Schwab reps with no success despite them observing where my orders would have been true with no execution. they suggested a few things, but nothing has worked. below is a list of things I've tried.
  • Consolidated and reduced the number lines of code 28 lines
  • Reduce the number of “def” statements
  • Changed the name of the script multiple times
  • Rebuilt the script from scratch with a new name
  • Removed recursion from the script
  • Submitted the order before and after the bell
  • Created my order from scratch the morning of instead of using a saved template
  • Tried different condition statements
    • condition from 1 bar ago is true
    • condition from 1 bar ago is greater than 0
    • condition from 1 bar ago is equal to 1
    • if condition from 1 bar ago then 1 else 0
  • I always use Market orders
  • I’ve tried setting order rules with both the Condition Wizard and the ThinkScript Editor with code completely Written out
  • I haven’t gotten any script complexity warnings
see shared chart with custom study
http://tos.mx/!La3OYckl

my goal is to make this script/study the condition that will execute my option trade.
 
Schwab's TOS Support should have informed you that your plot needs to be:

PLOT trigger = if trigger1x then 1 else 0;

And you don't need to paint arrows...

Each spike in the lower section is a Buy signal... Arrows won't make the orders fire... I did not verify your overall logic, only the firing issue itself...

As an aside, whenever you have a question about code, post the code itself rather than a link... I could have resolved this issue right here in the forums without the need to further clutter my TOS install with yet another piece of code...

1723667486591.png
 
Last edited:

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

for the last 2+ months custom scripts I had been using for 6+ months have suddenly stop working. With dozens triggers but no execution. The Scripts were used to set the conditions in the order rules to buy Spy option contracts from the option chain. I've talked with TOS/Schwab reps with no success despite them observing where my orders would have been true with no execution. they suggested a few things, but nothing has worked. below is a list of things I've tried.
  • Consolidated and reduced the number lines of code 28 lines
  • Reduce the number of “def” statements
  • Changed the name of the script multiple times
  • Rebuilt the script from scratch with a new name
  • Removed recursion from the script
  • Submitted the order before and after the bell
  • Created my order from scratch the morning of instead of using a saved template
  • Tried different condition statements
    • condition from 1 bar ago is true
    • condition from 1 bar ago is greater than 0
    • condition from 1 bar ago is equal to 1
    • if condition from 1 bar ago then 1 else 0
  • I always use Market orders
  • I’ve tried setting order rules with both the Condition Wizard and the ThinkScript Editor with code completely Written out
  • I haven’t gotten any script complexity warnings
see shared chart with custom study
http://tos.mx/!La3OYckl

my goal is to make this script/study the condition that will execute my option trade.
some guesses,

maybe it was a problem with portfolio functions? they stopped working awhile ago.
https://usethinkscript.com/threads/...o-functions-in-thinkorswim.18808/#post-145019

maybe you are pulling the max data, after adding more watchlist studies or more option chain studies?
try to unload some studies.
https://usethinkscript.com/threads/...icator-for-thinkorswim.4218/page-2#post-80177
Unfortunately the max number applies to ALL open watchlists AND\OR Activity\Position screens - I use %change by 5m; day; week and month columns in both watchlists AND Monitor Tab- ACTIVITY\POSITION tab in 3 groups and run into the issue alot, the issue is worse in the Paper trading account.- just have to split BIG watchlists into smaller ones to get around it, or use less watchlists.

you are calling for external data, from a study, which calls data from a function. (RSI, average).
if you put the function code in your study, it may save a few computer cycles.
go look at the study code and copy the relevant code and put in your study.

you are using low, close, high, bodyheight(), low(symbol = "$ADSPD"), ... many, many times. each time, the study has to read external data.
it is good practice , if something is to be used 3+ times, assign it to a variable and reference the variable.



Code:
#shared_SPYSIGNAL_NOREC2

#https://usethinkscript.com/threads/custom-script-not-executing-intraday-options-trade.19319/

def bodyht = bodyheight();
def lo = low;
def hi = high;
def cls = close;
def lo2 = low(symbol = "$ADSPD");

def regularSession = SecondsFromTime(0935) > 0 && SecondsTillTime(1305) > 0 ;

# rsi -------------------
#def RSIVal = RSI("length" = 2)."RSI";
input rsi_length = 2;
#input rsi_over_Bought = 70;
#input rsi_over_Sold = 30;
input rsi_price = close;
input rsi_averageType = AverageType.WILDERS;
#input showBreakoutSignals = no;
def NetChgAvg = MovingAverage(rsi_averageType, rsi_price - rsi_price[1], rsi_length);
def TotChgAvg = MovingAverage(rsi_averageType, AbsValue(rsi_price - rsi_price[1]), rsi_length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSIval = 50 * (ChgRatio + 1);
#def OverSold = rsi_over_Sold;
#def OverBought = rsi_over_Bought;
#def UpSignal = if RSI crosses above OverSold then OverSold else Double.NaN;
#def DownSignal = if RSI crosses below OverBought then OverBought else Double.NaN;
#--------------------------

def ttm = TTM_Squeeze()."Histogram" > 0;
def ttmf = TTM_Squeeze()."SqueezeAlert" is false;

# average----------------
#def sma50 = SimpleMovingAvg("length" = 50)."SMA";
#def sma20 = SimpleMovingAvg("length" = 20)."SMA";
#input avg1_type = AverageType.exponential;
input avg1_type = AverageType.Simple;
input avg1_length = 20;
def sma20 = MovingAverage(avg1_type, cls, avg1_length );
input avg2_type = AverageType.Simple;
input avg2_length = 50;
def sma50 = MovingAverage(avg2_type, cls, avg2_length );
#---------------------

def trigger1 = (RSIVal != Lowest(RSIVal, 20) and cls == Lowest(cls, 20)) and ttm within 12 bars and RSIVal < 12 and hi < sma20;
def triggerRSI = (((trigger1 is true within 6 bars and RSIVal > 30 and RSIVal < 50  and hi[1] < sma20 and hi[1] < sma50 and (Highest(hi, 16) - cls) < 2.4) and Median(Bodyht, 4) > .08 and bodyht >.06)
or ((((sma20-sma50) > .35 and sma20 > sma50 and (lo < sma50) and absvalue(cls-sma50) < .10 and (cls > lo) and absValue(cls-lo) > .04) within 3 bars and (rsival < 10 or rsival > 25) 
or ((cls-lo) > (5*bodyht) and bodyht > .05) 
or (((highest(lo,3))-(lowest(lo,3))) < .04 and (highest(hi,6)-lo) > .6))and bodyht > .01)) and regularSession;

def lodHistory = if regularSession then CompoundValue(1, lo[1], Double.NaN) else Double.NaN;
def lod = if regularSession then
     if lo < lodHistory then lo
     else lodHistory
   else lo;
def lowAD = if regularSession then
     if (lo2< lowAD[1]) then lo2
     else lowAD[1]
   else lo2;
def currentLowAD = lo2;
def ADLongSignal = lo == lod && currentLowAD > lowAD and RSIVal < 20;
def divergence = ((sum((cls > sma20),15)>13 and cls < sma20 and RSIVal < 5 and (bodyht > .60 or bodyht < .30)) or (sum((cls > sma50),15) > 13 and cls < sma50 and Sum(ttmf,15) > 10)) and regularSession;
def divergece2 = Sum(ADLongSignal, 3) > 1 and hi > hi[1] and bodyht > .05  and rsival < 30;

def trigger1x = ((divergence or divergece2) or triggerRSI);
PLOT trigger = trigger1x; 

trigger.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
trigger.SetDefaultColor(Color.WHITE);
trigger.SetLineWeight(5);
#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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