As Close As We Can Get To Auto-Trading on Thinkorswim
In this video we show how to build your own code using a point and click condition wizard. The condition wizard
makes it very simple to build your own set of rules for trade execution. However you may not realize the code generated by the condition wizard can be very easily inserted into a template to form a Strategy and/or Custom Chart Study. We supply the templates, and show you how to put it all together. You will learn how to build your code using the condition wizard and you will learn how to convert that into a Strategy file. And Using tools we provided in previous videos you will then be able to analyze the performance of those Strategies.
We also show you how to use the condition wizard to generate orders that will execute in the same way as those theoretical orders generated by the custom Strategies.
AutoTrades are not fully supported on Thinkorswim as on other platforms. However if you learn how to connect the pieces you can place conditional orders that await the signal created by a set of defined rules. Once the conditions are satisfied, the order is released from hold and becomes a live order.
DISCLAIMER: I AM NOT A CERTIFIED FINANCIAL ADVISOR AND NOTHING IN THIS VIDEO OR TEXT IS AN ADVERTISEMENT OR RECOMMENDATION TO BUY OR SELL ANY FINANCIAL INSTRUMENT. NOR IS THIS VIDEO OR TEXT INTENDED TO INSTRUCT YOU ON HOW TO MAKE BUY OR SELL DECISIONS USING ANY OF THESE INDICATORS.
*Thinkorswim is a chart analysis platform offered by TD Ameritrade: www.tdameritrade.com
TD Ameritrade provides financial services including the trading of Stocks, Futures, Options and Forex.
Please be sure to share this page with your friends and colleagues. Leaving comments below is the best way to help make the content of this site even better.
Watch the video, Thinkorswim AutoTrade Almost below:
This is the code for the Strategy Template:
input tradeSize = 100;
def signal = 0;
addOrder(OrderType.BUY_TO_OPEN, signal, open[-1], tradeSize, Color.CYAN, Color.CYAN);
def exit = 0;
addOrder(OrderType.SELL_TO_CLOSE, exit, open[-1], tradeSize, Color.MAGENTA, Color.MAGENTA);
This is the code for the Study Template:
declare lower;
plot signal = 0;
plot exit = 0;
This is the code for the revised SLM Ribbons study:
input price = close;
input superfast_length = 8;
input fast_length = 13;
input slow_length = 21;
input displace = 0;
def mov_avg8 = ExpAverage(price[-displace], superfast_length);
def mov_avg13 = ExpAverage(price[-displace], fast_length);
def mov_avg21 = ExpAverage(price[-displace], slow_length);
#moving averages
Plot Superfast = mov_avg8;
plot Fast = mov_avg13;
plot Slow = mov_avg21;
def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;
def stopbuy = mov_avg8 <= mov_avg13;
def buynow = !buy[1] and buy;
plot Buy_Signal = buynow and !stopBuy;
Buy_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_signal.setdefaultColor(color.dark_GREEN);
Buy_signal.hidetitle();
def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;
def stopsell = mov_avg8 >= mov_avg13;
def sellnow = !sell[1] and sell;
Plot Sell_Signal = sellNow and !stopSell;
Sell_signal.setpaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
sell_signal.setDefaultColor(color.red);
Sell_signal.hidetitle();
Hello Pete,
Your videos are awesome. I just started with Tos Script, and have a simple question: How can I make sure that my strategy (which i am backtesting) will always start with a buy order? I have both buy and sell definitions, but on the graph the first order shown is always a sell order. When I inactivate sell (#), then a buy order will be shown, otherwise not. What am doing wrong?
Thank you!
Joy
This would be the code:
input priceClose = close;
Input priceOpen = open;
input fastSMALength = 20;
input fastEMALength = 9;
input slowSMALength = 200;
input averageType1 = AverageType.SIMPLE;
input averageType2 = AverageType.EXPONENTIAL;
def FastSMA = MovingAverage(averageType1, priceClose, fastSMALength);
def SlowSMA = MovingAverage(averageType1, priceClose, slowSMALength);
def FastEMA = MovingAverage(averageType2, priceClose, fastEMALength);
Def Buy = FastSMA > SlowSMA and FastSMA[1] < SlowSMA [1];
Def Sell = FastSMA SlowSMA[1];
AddOrder(OrderType.BUY_TO_OPEN, Buy, close, tickColor = GetColor(4), arrowColor = GetColor(4), name = “ENTRY”);
AddOrder(OrderType.SELL_TO_OPEN, Sell, tickColor = GetColor(6), arrowColor = GetColor(6), name = “EXIT”);
Sorry, not sure what happened when I pasted the code here.
….
def Buy = FastSMA > SlowSMA and FastSMA[1] < SlowSMA [1];
def Sell = FastSMA SlowSMA[1];
…..
It’s not pasting my full code, not sure why. Trying this one more time.
My “def” is never capitalized, but when I paste it here, the browser seems to turn it into “Def”, and it also doesn’t paste the full line, omitting the “<" in the def Sell….
My def Sell says: Sell when the FastSMA is below the SlowSMA and when the FastSMA[1] was above the SlowSMA[1] before.
I am hoping once I hit Post Comment some characters above won't disappear. Thank you!
Much easier if you post this question in our Q&A forum. The comments section of a video is not the place to try and paste code. However I can tell you that the order type for your sell order should be changed to this:
AddOrder(OrderType.SELL_TO_CLOSE, Sell, tickColor = GetColor(6), arrowColor = GetColor(6), name = “EXIT”);
Pete, thanks for your quick reply. OK, noted, next time it will be in the Q&A section.
Hi Pete,
I’ve only been using the TOS platform for a couple months. So my solution may be something obvious.
I have a pretty good order system using Conditions to drive my Buy, which triggers my OCO sell orders.
One being a trailing stop loss, and the second is the one I’m having issues with.
My sell is also conditional , but I I’d like to delay any sale until after my order has reached a 2% gain.
Originally, I tried a Limit order with conditions, the conditions worked great, letting the price rise past the limit when the stock was running. However, when the conditions tripped, the Limit order would be submitted at the original limit price where it executes. Sometimes the current price would be 5-6% past the original Limit price, but the sale goes through at the limit price, vs. the current market price.
My next attempt was to use a trailing stop, or market order which gets submitted when the Sell Conditions are met. This worked okay, but would often trip before my 2% gain. I could setup a condition that would allow me to drive it with 2% from the DailyLow or 2% from the DailyOpen, but I couldn’t figure out a way to get 2% from my Buy.
Is there a solution that allows me to hook my Buy price in to a condition?
Or is there another solution, that would allow me to Buy, then wait 2%, then check that the other sell conditions are met before Selling?
any help would be appreciated, thanks
This is lightyears beyond the level of complexity we can properly address in the comment section of the video. This question is best posted to our Q&A forum. But before posting a new question in the forum you need to boil this down to a short bullet-point list of specifications. There is no way to create compound conditional orders. So if you are trying to apply conditions to any OCO branch of the original order… you can’t get there from here.
possibly what you may be satisfied with is a limit sell that triggers conditionally but the limit price is changed from “MAN” to “MARK” and set it to +- a small percent or a few cents. this will be the MARK of the equity (or option) at the time the condition triggers plus or minus what you specify.
Is there a way to have the custom conditional orders remain active or re-activate to become “working orders” again so that subsequent trades can be executed according to the “signal” without having to re-enter the conditional orders each time? Perhaps this can be done through a bracket or multi-leg/First-Triggers order? Or perhaps through a third-party platform? if not, what would be the simplest way to save custom conditional orders for quick re-entry ?
Thank you!!
This has already been asked and answered in the Q&A forum. It is not possible to have conditional orders regenerate. The order itself can be saved as a template order. However your conditional order must contain the full code and not just a reference to other study(s).
Hi Im curious if you can auto trade almost from a custom candlestick pattern/ strategy?
“custom candlestick pattern”. What exactly did you have in mind?
I would like to auto trade from just candlestick patterns but im not sure how to go about doing this. no bollanger bands or anything just simple candlestick patterns. take a HighPriceGappingPlay pattern and set an auto trade based off it, with a 1R stop loss and a 2R profit?
Ok, that is a service we offer. You can get all the details including our rates and how the process works here on this page. Just fill out the contact form at the bottom when you are ready to submit your project request.
https://www.hahn-tech.com/about/
OK Pete thanks I didnt realize you offered a service like that. Would you work with me in so that I can learn thinkscript?
I do not have a formal curriculum at this time. However those wanting to learn the basics of thinkscript have been posting in the Q&A forum when they get stuck. With over 1,000 posts in the Q&A forum, it has become a vast and searchable knowledge-base of custom thinkorswim solutions.
Pete thanks for the video. I had to watch @ minute 25:17 several times. I was a bit confused when you pasted the exit strategy where the signal should go and the signal where the exit should go..
Pete, thanks so much for the strategy details & your video was extremely helpful. Do you ever notice conditional orders not always firing off when a buy or sell signal appears?
I do not use conditional orders on a regular basis so I have not experienced any of these issues. Make sure all your order are set to Market or Stop. Any order set to Limit are very likely to fail because by the time the signal triggers the order the price has moved away from that limit price.
Or set to limit order with the mark plus 10 cents as the price, right?
No. A limit order of any kind does not ensure execution. Limit orders on ensure an execution price. However they can never ensure an execution will occur. Because the price of the limit order must be reachable within the bid/ask spread at the time the order is sent to the market.
Pete thank you for taking time to do these videos! Is there a way to build a buy order to buy when the low is above the middle VWAP?
You can build a Chart Strategy based on VWAP but the Conditional Order will not accept the VWAP indicator.
Hi Pete, thanks for the great video. Is there a work-around for the conditional order not accepting VWAP? Thanks
Not at this time. The VWAP study that comes with Thinkorswim uses two functions that are not supported in Study Alerts or Conditional Orders.
Hi Pete, thanks for the feedback. Does that mean that using TOS, there is no way I can have TOS alert me every time that the price crosses the lower VWAP bound? I’d be interested in hiring you for 30 minutes of your time to walk me through some of this, if there is a way to do it (via paypal). Thanks
You can hire me for custom solutions. However the minimum charge is 2 hours. Details here: https://www.hahn-tech.com/about/
The only solution is to build your alert as a custom scan. Then use that saved custom scan to create a dynamic alert. I demonstrate how to build dynamic alerts towards the end following video: https://www.hahn-tech.com/thinkorswim-overnight-range-scan-alert/
Thanks Pete – I may do that, but the time minimum may make that not possible (I’d have to save up alot of ideas or something)… To clarify your comment though, does that mean that I can’t back test a strategy in ToS that uses VWAP? thanks again…!
No this has nothing whatsoever to do with back testing.
hi pete. can i get the code for ichimoku please?
Was that provided with this video or another?
for the ichimoku scan i tried to download but when i get to tos i cant see the the code. i use the same process for the ichimoku strategie. sorry my English is not enough. im from montreal. and thanks for what u are doing.
This video does not provide any code for an Ichimoku scan. This video only provides code for the strategy and scan templates, along with code for the SLM Ribbon.
i know i came here because i can not post in the video of ichimoku scan the platform dont allow me ,so i came here. sorry for this.For the ichimoku study i was able to download on tos. but for the scan i cant. i can see he download on my computer but if i go to import i can not