Help with Backtest Strategy Code - "STC order with Stop/Exit trade in "X" number of days"

C4rnif3X

New member
6yHWI0G.png


Hello, so i'm at a complete standstill right now. I'm writting a seperate strategy (still a newbie with TS), and I want to be able to set a STC order with a Stop/Exit in "X" number of days upon Entry Price. Instead of including all the other code from the other strat, I wrote a simple example to make things easier.

I've tried all I could think of, and embarrassingly enough the code is probably really simple haha. I've looked everywhere I could online to no avail.

The only thing i've got to work/something to happen is by turning the "Count_Days" highlighted off code, on - and the "Day_Stop" number would actually count the bars and sell out within a semi-right time frame.

The "Count_Days" code below that one does nothing when combined with the Day Stop.

Any help would be appreciated greatly! Thanks.
 
@C4rnif3X Do you have the video? I want to take a look at it.

At about 2:20 is when he adjusts the stop. If you compare the results from the Show Report from when it isn't applied to being applied - it looks like it's definitely doing something. There's no way to tell for certain without seeing the code.

From everywhere i've looked I haven't seen any stop out code similar to what is shown in that video. I'm sure there's some way to do it, I just haven't seen it, but very odd that it's so hard to figure out.
 

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

like you said, unless you pay for his code then you have no idea what his rules/codes are. You will have to pay for his rules/codes/strategy or you can come up with your own rules and strategy and get help coding it.

https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/OrderType/OrderType-SELL-TO-CLOSE
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/AddOrder
Mhmm. I'm not paying for it, just looking to see if there was some universal way to apply this "stop out" method for my own stuff. Nothing seems to work yet, but i'll figure it out eventually. I definitely reference those TOS docs, this was just a problem I was getting hung up on.
 
Mhmm. I'm not paying for it, just looking to see if there was some universal way to apply this "stop out" method for my own stuff. Nothing seems to work yet, but i'll figure it out eventually. I definitely reference those TOS docs, this was just a problem I was getting hung up on.
stop out is closing the position, i just sent you the tos reference on the syntaxes to use in post #22. The rest of the code is what your rules for "stopping" out would be.
 
stop out is closing the position, i just sent you the tos reference on the syntaxes to use in post #22. The rest of the code is what your rules for "stopping" out would be.
Yep, I have the code written out up to the point we left off. Doesn't seem to work, but i'll figure it out. Thanks.
 
@C4rnif3X Honestly, I doubt his code is anything special. It probably has more to do with the fact that his strategy has way fewer buy signals than close crossing sma. I'm pretty confident that it's impossible to code each entry as an "unique" entry but who knows.
 
@C4rnif3X Honestly, I doubt his code is anything special. It probably has more to do with the fact that his strategy has way fewer buy signals than close crossing sma. I'm pretty confident that it's impossible to code each entry as an "unique" entry but who knows.
That's what i'm thinking, doesn't seem possible to get unique entries. I'm pretty sure they base it off the 9D vix 3M vix cross entry.. But still exiting trade within a certain amount of days seems possible - which is what i'm trying to figure out. Not unique entries.

The video piqued my interest because I follow the vix market and trade credit spreads regularly - so exiting trade within "X" number of days fits in with my current strategy and would be super helpful to implement into a backtest.. Once I figure it out lol.
 
@C4rnif3X Are you referring to coding a backtesting Strategy using AddOrder() or coding a Conditional Order...??? For both, accurately calculating reliable stoploss code and complex exit strategies is somewhat problematic... Easily calculated exits, on the other hand, are far easier and more reliable... The more complex you make your exits, the more likely Thinkorswim will blow right past them... Trust me, if it was easy enough that's all I'd use but I've exhausted my efforts, as well as those of TOS Tech. Support... Simpler is better...

I have found that the easiest way to test complex entry and exit strategies is to do them manually and document them in a spreadsheet... I monitor the historical chart data, or watch active trading throughout the day, and document my entries and exits based on my indicators... In the long run it's far easier than trying to bend code to do what I can see with my eyes. and sometimes a bit of fuzzy logic that code can't perform...

Food for thought...
 
@C4rnif3X Are you referring to coding a backtesting Strategy using AddOrder() or coding a Conditional Order...??? For both, accurately calculating reliable stoploss code and complex exit strategies is somewhat problematic... Easily calculated exits, on the other hand, are far easier and more reliable... The more complex you make your exits, the more likely Thinkorswim will blow right past them... Trust me, if it was easy enough that's all I'd use but I've exhausted my efforts, as well as those of TOS Tech. Support... Simpler is better...

I have found that the easiest way to test complex entry and exit strategies is to do them manually and document them in a spreadsheet... I monitor the historical chart data, or watch active trading throughout the day, and document my entries and exits based on my indicators... In the long run it's far easier than trying to bend code to do what I can see with my eyes. and sometimes a bit of fuzzy logic that code can't perform...

Food for thought...
Just a backtesting strategy using AddOrder.

I already spreadsheet everything I do - i've been trading for 5+ years. I just never dabbled in the backtesting section with TOS. Being able to just pull results right into a spreadsheet would make ideas so much easier to test and less time consuming. Judging from everything i've seen in learning the coding process, i've never seen this type of exit brought up. So i'm thinking it's either not possible, or beyond effort i'm willing to put in for a simple thing like you said. Since i'm not the most experienced with TOS code, I was thinking it was just something a little more advanced than I know how to do - but simple for more experienced users.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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