We cover 8 different trade scenarios in this tutorial. Here are video timestamps that might come in handy: 0:01 - Automated Trading Intro 1:25 - Who We Are 3:54 - What Will We Discuss in this Tutorial 5:42 - Why Automated Trading? 8:57 - What is the Automated Trading Triggers Window? 10:55 - 8 Trigger Scenarios That We Will Build 15:05 - Scenario 1: Nightly Trending List 18:47 - Scenario 2: Iron Condor When in Consolidation 23:56 - Scenario 3: Automatic Covered Call for Income at Fib Extensions 27:40 - Scenario 4: Buy Put When RSI Shows Bearish Breakout Signals 32:01 - Scenario 5: Buy Stock on Pullbackto 34 EMA 36:34 - Scenario 6: Sell Position When Squeeze Loses Momentum 39:37 - Scenario 7: Layering on Multiple Indicators 44:55 - Scenario 8a: Buy on Implied Volatility Pullbacks (Entry) 47:01 - Scenario 8b: Sell When Trend Breaks 53:04 - What Else Can I Do? Hope you enjoy this tutorial!
Thank you for the amazing content. I have a question about tying your limit order to the ask/bid. Can you explain how thats different from a market order?
Thanks for the great video! One point I noticed at 22:18 - the Ask/Bid, according to the manual is "... either the bid or the ask price plus the offset specified as an absolute value. The system automatically chooses the ask price for Buy orders and the bid price for Sell orders." I believe you want to select MARK which is the mid-point and you can modify the offset amount.
Great content !! Thanks for sharing such a great tutorial and for explaining in simple terms how everything works. We need more traders and contributors like you ! I will look at the rest of the content in your channel, it looks fantastic.
Thanks you, Loved it, Have a scenario & wanted to know if I can manage by scripting. I've two OCO orders one for long & the other is for Short on the same stock & both have entry/exit & stop. Is there was I can connect both where if the long one is executed, short will be cancelled and vice-versa. Incase you have a script available already appreciate if you can share pls. Thanks in advance.
You could use boolean arrows to change the plot. Documentation here: tlc.thinkorswim.com/center/reference/thinkScript/Constants/PaintingStrategy/PaintingStrategy-BOOLEAN-ARROW-UP
@@TOSIndicators Thanks I've tried that already, but it can draw a long continuous row of arrows when the signal is true for several bars in a row. I want to just have only 1 arrow drawn when the 1st signal is true and if the next several bars are also true not to continue drawing the arrows until the signal ends.
I have figure out how to create a custom BUY/SELL using the MACD-Histogram CrossOver Study. I would like to be able to do the same with the HA CrossOver Study. There doesn't seem to be any such study. Can you be of any assistance in creating a HeikenAshi -CrossOver Study ?
You can backtest in ThinkOrSwim using the "Strategies" functionality, and write your own thinkScript to give you some basic reporting. An additional benefit with that is you can leverage the same backtest thinkScript code in the Automated Triggers tab (assuming it passes the complex equation test).
OnDemand is not the same as PaperMoney. You'd need to log into to the PaperMoney account in order to run the studies since OnDemand doesn't support ThinkScript.
Is there anyway to automate the share size or number of contracts? For example, if I can write a script to determine my stop and base my number of shares to purchase off of that can that be incorporated? What about "looping" the order to hit some total dollar amount? Really just trying to automate number of shares based on using a def and simple math, but first glance it doesn't look possible
TOS Indicators Thanks! So there is no easy build in was to get strategies running / demo backtested using TOS? E.g. macd strategy on SPY Without me defending it after every trade? Much appreciated your work!
Hello I have a study but it is not working. It's much less simple than this, but it doesn't work. The algorithms don't seem to work well and don't take commands seriously. can I communicate with you
Yet another GREAT video!! Perhaps you can help me. I’m trying to automate a bullish and bearish entries/exits signal for the same stock. But I am confused about how the platform recognizes the exit bullish signal from the bearish entry signals. Also, I am not sure how to enter them in the Trade tool, should they be added separate, in order words the bullish entry/exit from the bearish entry/exits? Thanks again!!
Hi Fabian - based on your strategy and the code, the bullish and bearish signals would be "plot" variables, which you could then reference via exampleFunction().bullishSignal. Depending on the complexity of your code, TOS may give you a "complex error" if you try to combine too many variables/calculation (with both bullish and bearish). If you face that error, then you can trim down your code... as necessary :-).
Great Video. is it possible to create a custom template with a condition so that my sell orders will cancel automatically 5 mins before market close. Right now, i can only specify a date and time and that date becomes past if i use the template for a new order in the future.
You might be able to get away with using the "SecondsTillTime" function to link it to 5 mins before the market closes, instead of specifying a date/time. However, once the order gets triggered for the first time, you will need to re-submit for future orders.
As usual, amazing informative clip. 1. I think for the first scenario, the main order should be submitted as a “STOPLIMIT” order. Otherwise, if the order is submitted the way it is, it will get an immediate fill since the LIMIT price is over “ASK” price. I guess the whole intention here is buying the stock if it is building up momentum and shooting past a higher price.
is it possible to trade continuously. For example if fast Average line cross above (below) the slow average line, thinkscript can do automatically and continuously? Or u have some alternative ways. Thanks in advance.
Where do you recommend back testing your trading strategies and running them live? TOS does not seem to have very comprehensive back test reports and the automated trading is limited
If you're familiar with Python, Quantopian offers a fairly robust platform that is powerful enough to backtest with nuances that you'd need to truly replicate an automated-trading bot (i.e. drawdown, account ratios). The downside is their platform integrates with Robinhood, but you may consider using it purely to backtest your strategies as well.
@@TOSIndicators, unfortunately, Quantopian has pivoted away from the crowdsourced hedgefund model. they no longer offer the tools to public as they once did
I believe so, but I would test thoroughly in paper-trading esp. with futures. The benefit of stocks is being able to trade with as little as 1 share in live money, vs. your lowest risk form to test in futures would be the micros.
You can download our code directly from our website, and compare against your own code to see where you may be facing issues: tosindicators.com/indicators/automated-trading
Awesome! Any way we can use custom thinkscript code that’s not based on an indicator for placing orders? Like the ATR Trailing stop? That’s built into charts but not the order entry script selection, May need to define signal? Thoughts?
Hi Robert - I think you could use the "ATRTrailingStop()" study, which is built inside of ThinkOrSwim, and use that to link (and test) to a trigger condition. Not sure if it would work, but it's a good starting spot, and use that code to test / tweak. You also have access to the source code inside of TOS, if you'd like to define the signal yourself.
Thank you! I had never seen the “define signal” before. That’s huge if I can get it to work. This would mean every study, both default and customized is fair game for an entrance or exit. Very impressive!
Hi, I tend to trade using range bars. Is there any way to automate trades on thinkorswim using range bars instead of time-based aggregation? When setting up the order condition, it seems like only time-based is available (ie. day, min, month etc..). Thanks!
ibridgepy can now be used to automate TD accounts. Also (I haven't watched this entire video, but perhaps this was mentioned), you can't use reversion programming to trigger automated events. This prevents most complex trading concepts. For instance, you can't use VWAP to trigger trades (please correct me if that has been fixed)! When you attempt to calculate things like VWAP it errors.
Do you see it as a possibility to have an algorithm that swings for you depending on SMA's? Ex: Purchase when the price opens above the 50SMA and sell when the price closes below the 50SMA.
Thank you so much for the detailed and beautiful video, I wanted to ask , Sample buying conditions , buy only once, and the condition ends, Can a condition be repeated over and over again, For example: if the price went up in cents, buy , And then every cent that costs the system will automatically buy again and again?
Hello, is there a way to sell a indicator if one comes before the other such as: Sell if 50 SMA < 200 SMA or RSI > 70 (which ever comes first)? Or would you just make 2 sell orders?
Hi Ryan - Not sure what you mean by this, but if you are missing the screen altogether, that would be a question for TDA to help you debug your instance of the platform.
I tried to input my code and saved it as a custom order but upon opening the saved order again, the code is cut and not showing all of the codes. Can this be fixed?
I'm not aware of a way to save an order template to keep re-using the same piece of code. The alternative that I've found to be more reliable is save the code as a separate .txt file locally, to copy/paste in any time the same order condition code is needed.
2. For the second scenario, the order time frame cannot be DAY. Obviously, the last day closing price did not meet the criteria, otherwise, there was no need for deploying any code and one could sell the CONDOR on the get-go. This code cannot be triggered with today’s closing price because by definition when we learn today’s closing price, the market is already closed and our order is expired. In conclusion, either we have to change the order to GTC or GTD. Question: “if I want to run this code on a daily chart but if I intend to trigger the order soon after the ticker price comes within that range, what variable should I be using instead of CLOSE? so it would be reflective of instant stock price, not daily closing price.”
The Scenario 1 is wrong. Your condition should be to buy MSFT if the price is cross over $179.18 in first 15 mins. But you submit the OCO at buy MSFT at $179.18 and the last price is $178.6 which is lower than $179.18. So when you submit the OCO order for Scenario 1, it will execute at $178.6 or lower price and it is possible that the price will not cross over $179.18 in first 15 mins. Could you make a correction for the scenario 1?
Hi Liu - Scenario 1 is correct, along with the code. The conditional order for entry (not the OCO) is at whatever price the VB levels suggest (using a STOP, not a LIMIT order). The order will only trigger if our conditions are met, after which the OCO orders are automatically in place. If the order does not trigger by 6:45 am PT, the order automatically cancels using the time based triggers.
Scenario 1 uses a hard-coded VB Level via a stop limit order (stop if you don't care about gaps), with a time-based order expiration. Feel free to email us at contact@tosindicators.com if you need any further clarification.
@@TOSIndicators Yeah, this is confusing to me, too. Your buy order is a limit order higher than present price... Why wouldn't this immediately execute?
We cover 8 different trade scenarios in this tutorial.
Here are video timestamps that might come in handy:
0:01 - Automated Trading Intro
1:25 - Who We Are
3:54 - What Will We Discuss in this Tutorial
5:42 - Why Automated Trading?
8:57 - What is the Automated Trading Triggers Window?
10:55 - 8 Trigger Scenarios That We Will Build
15:05 - Scenario 1: Nightly Trending List
18:47 - Scenario 2: Iron Condor When in Consolidation
23:56 - Scenario 3: Automatic Covered Call for Income at Fib Extensions
27:40 - Scenario 4: Buy Put When RSI Shows Bearish Breakout Signals
32:01 - Scenario 5: Buy Stock on Pullbackto 34 EMA
36:34 - Scenario 6: Sell Position When Squeeze Loses Momentum
39:37 - Scenario 7: Layering on Multiple Indicators
44:55 - Scenario 8a: Buy on Implied Volatility Pullbacks (Entry)
47:01 - Scenario 8b: Sell When Trend Breaks
53:04 - What Else Can I Do?
Hope you enjoy this tutorial!
Thank you for the amazing content. I have a question about tying your limit order to the ask/bid. Can you explain how thats different from a market order?
Thanks for the great video! One point I noticed at 22:18 - the Ask/Bid, according to the manual is "... either the bid or the ask price plus the offset specified as an absolute value. The system automatically chooses the ask price for Buy orders and the bid price for Sell orders." I believe you want to select MARK which is the mid-point and you can modify the offset amount.
Thanks for the tip! Appreciate it.
Great content !! Thanks for sharing such a great tutorial and for explaining in simple terms how everything works. We need more traders and contributors like you ! I will look at the rest of the content in your channel, it looks fantastic.
Thanks you, Loved it, Have a scenario & wanted to know if I can manage by scripting. I've two OCO orders one for long & the other is for Short on the same stock & both have entry/exit & stop. Is there was I can connect both where if the long one is executed, short will be cancelled and vice-versa. Incase you have a script available already appreciate if you can share pls. Thanks in advance.
Great video on Advanced scripting on ThinkOrSwim
WOW. Great vid. Those ideas for triggers really make you think about finding and or setting up positions in a truly customized fashion.
Agreed!
This is awesome exactly what I was looking for, very detail work and explanations
Glad you liked it!
TOS Indicators Instead of having a line that moves up when the signal occurs, how would I change it to show just 1 arrow when the signal occurs?
You could use boolean arrows to change the plot. Documentation here: tlc.thinkorswim.com/center/reference/thinkScript/Constants/PaintingStrategy/PaintingStrategy-BOOLEAN-ARROW-UP
@@TOSIndicators Thanks I've tried that already, but it can draw a long continuous row of arrows when the signal is true for several bars in a row. I want to just have only 1 arrow drawn when the 1st signal is true and if the next several bars are also true not to continue drawing the arrows until the signal ends.
Right. You'll need to factor that into your boolean condition, checking if the signal was true on the current bar, and not the previous bar.
Really nice tutorial!
can you automate TTM Squeeze Histogram Backtester
Is there a way to input a repeat everytime those conditions happen and run it on the on-demand for backtesting?
Outstanding; thank you!
Thanks Randall! Appreciate it.
How about triggers based off premarket levels on options with different strike alerts triggered off the pre market levels
I have figure out how to create a custom BUY/SELL using the MACD-Histogram CrossOver Study. I would like to be able to do the same with the HA CrossOver Study. There doesn't seem to be any such study. Can you be of any assistance in creating a HeikenAshi
-CrossOver Study ?
But how to do risk management ? E.g. The alog should calculate quantity based on risk $$$. So how to do that ?
Code for TTM losing momentum does not seem to work. Is there any update?
Pretty well articulated.
Thanks Anil!
I do not have the ability to have a study trigger an action on the on demand side of TOS? That kinda sucks how do you back test?
You can backtest in ThinkOrSwim using the "Strategies" functionality, and write your own thinkScript to give you some basic reporting.
An additional benefit with that is you can leverage the same backtest thinkScript code in the Automated Triggers tab (assuming it passes the complex equation test).
OnDemand is not the same as PaperMoney. You'd need to log into to the PaperMoney account in order to run the studies since OnDemand doesn't support ThinkScript.
Is there anyway to automate the share size or number of contracts? For example, if I can write a script to determine my stop and base my number of shares to purchase off of that can that be incorporated? What about "looping" the order to hit some total dollar amount? Really just trying to automate number of shares based on using a def and simple math, but first glance it doesn't look possible
Excellent video. It's a shame there is no option for 'tick' timeframe so I could use this for my scalping strategy. The minimum is 1 min.
is it possible to set a percentage in between the moving average? Let say all three must be within 0.01% to 5% so it really makes it stacked
Hi there - yes, that should be possible, though would need to be a custom script.
This is awesome... so it automatically executes the buy and sell orders? So you can just run one of these and go AFK?
In theory, yes... but does require you to re-submit the order every time (incl. the sell-side scripts).
TOS Indicators
Thanks!
So there is no easy build in was to get strategies running / demo backtested using TOS?
E.g. macd strategy on SPY
Without me defending it after every trade?
Much appreciated your work!
thanks! Very valuable.
Thanks Stephen! Glad you found the tutorial useful.
can you save these and attach them to hotkeys?
Hello I have a study but it is not working. It's much less simple than this, but it doesn't work. The algorithms don't seem to work well and don't take commands seriously. can I communicate with you
This is fantastic. Thank you.
Thanks Kasu! Appreciate it.
Yet another GREAT video!!
Perhaps you can help me. I’m trying to automate a bullish and bearish entries/exits signal for the same stock. But I am confused about how the platform recognizes the exit bullish signal from the bearish entry signals. Also, I am not sure how to enter them in the Trade tool, should they be added separate, in order words the bullish entry/exit from the bearish entry/exits?
Thanks again!!
Hi Fabian - based on your strategy and the code, the bullish and bearish signals would be "plot" variables, which you could then reference via exampleFunction().bullishSignal. Depending on the complexity of your code, TOS may give you a "complex error" if you try to combine too many variables/calculation (with both bullish and bearish). If you face that error, then you can trim down your code... as necessary :-).
awesome post! Thanks
Thanks David - glad you liked it!
Great Video. is it possible to create a custom template with a condition so that my sell orders will cancel automatically 5 mins before market close. Right now, i can only specify a date and time and that date becomes past if i use the template for a new order in the future.
You might be able to get away with using the "SecondsTillTime" function to link it to 5 mins before the market closes, instead of specifying a date/time. However, once the order gets triggered for the first time, you will need to re-submit for future orders.
As usual, amazing informative clip.
1. I think for the first scenario, the main order should be submitted as a “STOPLIMIT” order. Otherwise, if the order is submitted the way it is, it will get an immediate fill since the LIMIT price is over “ASK” price. I guess the whole intention here is buying the stock if it is building up momentum and shooting past a higher price.
in the code cross above set it already.
How can we paper trade options on TOS?
Just need a TOS account switched to Paper Trading mode and you should be able to trade via the options chain on the Trade tab.
is it possible to trade continuously. For example if fast Average line cross above (below) the slow average line, thinkscript can do automatically and continuously? Or u have some alternative ways. Thanks in advance.
Not that I'm aware of - each new entry and exit order needs to be re-submitted in TOS.
You can do up to 8 legs for continuous buying and selling which would be 4 buys and 4 sales on the same trade.
Where do you recommend back testing your trading strategies and running them live? TOS does not seem to have very comprehensive back test reports and the automated trading is limited
If you're familiar with Python, Quantopian offers a fairly robust platform that is powerful enough to backtest with nuances that you'd need to truly replicate an automated-trading bot (i.e. drawdown, account ratios). The downside is their platform integrates with Robinhood, but you may consider using it purely to backtest your strategies as well.
You can put on floating pnl with strategies on your chart go to studies and put on a strategy
@@TOSIndicators, unfortunately, Quantopian has pivoted away from the crowdsourced hedgefund model. they no longer offer the tools to public as they once did
Amazing video thank you 👍
Thanks Naweed! Glad you liked it.
Can you semi-automate Futures trade? Thanks
I believe so, but I would test thoroughly in paper-trading esp. with futures. The benefit of stocks is being able to trade with as little as 1 share in live money, vs. your lowest risk form to test in futures would be the micros.
yes, if you need help, call their support line.
Are secondary aggregations allowed for the buy/sell conditions?
I don't believe so.
Scenario 7 giving error at volume line, is it possible to correct?
You can download our code directly from our website, and compare against your own code to see where you may be facing issues: tosindicators.com/indicators/automated-trading
Awesome! Any way we can use custom thinkscript code that’s not based on an indicator for placing orders? Like the ATR Trailing stop? That’s built into charts but not the order entry script selection, May need to define signal? Thoughts?
Hi Robert - I think you could use the "ATRTrailingStop()" study, which is built inside of ThinkOrSwim, and use that to link (and test) to a trigger condition. Not sure if it would work, but it's a good starting spot, and use that code to test / tweak. You also have access to the source code inside of TOS, if you'd like to define the signal yourself.
Thank you! I had never seen the “define signal” before. That’s huge if I can get it to work. This would mean every study, both default and customized is fair game for an entrance or exit. Very impressive!
Hi, I tend to trade using range bars. Is there any way to automate trades on thinkorswim using range bars instead of time-based aggregation? When setting up the order condition, it seems like only time-based is available (ie. day, min, month etc..). Thanks!
Hi there - I'm not aware of a way to go from time-based bars to range-based ones, for the scripting conditions. Sorry!
Do you know if it’s possible to use other time frames that aren’t given for the order conditions?
Hi Teddy - I don't believe that's possible.
Have you have a trial, or we tried it lose or win. ?
Can it be applied in option trading.
The tutorial covers a few different scenarios that you can try to apply, including options trading.
ibridgepy can now be used to automate TD accounts. Also (I haven't watched this entire video, but perhaps this was mentioned), you can't use reversion programming to trigger automated events. This prevents most complex trading concepts. For instance, you can't use VWAP to trigger trades (please correct me if that has been fixed)! When you attempt to calculate things like VWAP it errors.
Do you see it as a possibility to have an algorithm that swings for you depending on SMA's? Ex: Purchase when the price opens above the 50SMA and sell when the price closes below the 50SMA.
That should be possible - the 50 SMA should most likely not trigger the Complex Exception error.
would have how to make a grid with leverage
Thank you so much for the detailed and beautiful video,
I wanted to ask ,
Sample buying conditions , buy only once, and the condition ends,
Can a condition be repeated over and over again,
For example: if the price went up in cents, buy ,
And then every cent that costs the system will automatically buy again and again?
Not that I'm aware of - the thinkScript needs to be copy/pasted each time, and the trigger condition "re-submitted."
Hello, is there a way to sell a indicator if one comes before the other such as: Sell if 50 SMA < 200 SMA or RSI > 70 (which ever comes first)? Or would you just make 2 sell orders?
You could use the "or" condition, with each indicator set in its own boolean condition. I would thoroughly test this in Paper Money, though.
Hello. My order condition screen doesn't display the AlertValue bar at the bottom. How do I add it?
Hi Ryan - Not sure what you mean by this, but if you are missing the screen altogether, that would be a question for TDA to help you debug your instance of the platform.
for scenario 5, will the buy order still be submitted if my thinkorswim platform isnt open?
As long as the submitted order is still an active order, it should be submitted if the conditions are met.
perfect!!
The cost?
Great video. Thank you. But your right, there are some real limitations. No conditional orders during extended hours?!? WTF?!?
I tried to input my code and saved it as a custom order but upon opening the saved order again, the code is cut and not showing all of the codes. Can this be fixed?
I'm not aware of a way to save an order template to keep re-using the same piece of code. The alternative that I've found to be more reliable is save the code as a separate .txt file locally, to copy/paste in any time the same order condition code is needed.
@@TOSIndicators thank you very much! I am doing that right now
2. For the second scenario, the order time frame cannot be DAY. Obviously, the last day closing price did not meet the criteria, otherwise, there was no need for deploying any code and one could sell the CONDOR on the get-go. This code cannot be triggered with today’s closing price because by definition when we learn today’s closing price, the market is already closed and our order is expired. In conclusion, either we have to change the order to GTC or GTD. Question: “if I want to run this code on a daily chart but if I intend to trigger the order soon after the ticker price comes within that range, what variable should I be using instead of CLOSE? so it would be reflective of instant stock price, not daily closing price.”
The Scenario 1 is wrong. Your condition should be to buy MSFT if the price is cross over $179.18 in first 15 mins. But you submit the OCO at buy MSFT at $179.18 and the last price is $178.6 which is lower than $179.18. So when you submit the OCO order for Scenario 1, it will execute at $178.6 or lower price and it is possible that the price will not cross over $179.18 in first 15 mins. Could you make a correction for the scenario 1?
Hi Liu - Scenario 1 is correct, along with the code. The conditional order for entry (not the OCO) is at whatever price the VB levels suggest (using a STOP, not a LIMIT order). The order will only trigger if our conditions are met, after which the OCO orders are automatically in place. If the order does not trigger by 6:45 am PT, the order automatically cancels using the time based triggers.
Scenario 1 uses a hard-coded VB Level via a stop limit order (stop if you don't care about gaps), with a time-based order expiration. Feel free to email us at contact@tosindicators.com if you need any further clarification.
@@TOSIndicators Yeah, this is confusing to me, too. Your buy order is a limit order higher than present price... Why wouldn't this immediately execute?
You’d have to go to Alpaca Trading and use Python to have fully automated trading.
looks like I need to use the python API to get fully-automated.