ThinkOrSwim Auto Trading Bot

Y

yunier2002

New member
Hi @Alex , I have not provided any implementation details in this that's why it looks vague. This is just a demo of how it works. I am working on another demo which will give you more details. It uses thinkorswim APIs for placing orders and few other technical stuffs for fetching tos strategy results. I'm looking for non-repainting strategy with good backtesting result for bot testing. Thanks.

Can you provide more details on the extra technical stuff you mentioned for fetching TOS strategies, I know it can't be done through API. Do you have to keep TOS open for this to work, export strategies, or how do you get the Strategy alerts? Will appreciate any insights into this
 
T

trader54

New member
Here is a link to a non-repainting strategy of mine. I originally wanted to move this on to Ninja Trader since they actually support auto trading but since you can make it work on TOS here it is: https://usethinkscript.com/threads/super-trend-to-ninja-trader.2962/. I look forward to working with you

Hi @adii800 ,
I have checked your strategy but it is not accurate. You have to try backtesting and generating report by considering order price as below.
Code:
def orderPrice = (open[-1]+close[-1])/2;

Or atleast
Code:
def orderPrice = open[-1];

In your strategy you are considering order price as current bar's close price that is not possible in real live trading. Also you have not removed some plots from your strategy. I have updated it. Please find below your updated strategy (removed plots and updated order price).

Code:
# SuperTrend
input AtrMult = 1.0;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
def ATR = MovingAverage(AvgType, TrueRange(high, close, low), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1] then UP else DN;
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST

                 then Color.RED

                 else if PaintBars and close > ST

                      then Color.GREEN

                      else Color.CURRENT);

# End Code SuperTrend

#MACD

#
# TD Ameritrade IP Company, Inc. (c) 2007-2020
#

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

def Diff = Value - Avg;

#ORDERS

def orderPrice = (open[-1]+close[-1])/2;

AddOrder(type = OrderType.BUY_TO_OPEN, ST < close and Diff > 0, tradeSize = 1, tickColor = Color.GREEN, arrowColor = Color.GREEN, name = "Long", price = orderPrice);
AddOrder(type = OrderType.SELL_TO_CLOSE, ST > close or Diff < 0, tradeSize = 1, name = "Close", tickColor = Color.GRAY, arrowColor = Color.GRAY, price = orderPrice);

AddOrder(type = OrderType.SELL_TO_OPEN, ST > close and Diff < 0, tradeSize = 1, name = "Short", tickColor = Color.LIGHT_RED, arrowColor = Color.LIGHT_RED, price = orderPrice);
AddOrder(type = OrderType.BUY_TO_CLOSE, ST < close or Diff > 0, tradeSize = 1, tickColor = Color.GRAY, arrowColor = Color.GRAY, name = "Close", price = orderPrice);

Try to backtest this and let me know your thoughts.

I know most of the people are very excited to have auto trading by just only seeing the strategy backtesting reports thinkorswim is generating. But before testing any strategy you have to make sure to have correct order price as above.

Thanks.
 
T

trader54

New member
@trader54 How accurate is this Bot, and does it tie into ThinkorSwim directly. Do you have a timeline as to when it will be available?

One other question, I have a very long strategy. What are the signals required to make this work?

Hi @StockT8er ,
Can you please share your strategy backtesting results? Please make sure to have order price as below before generating reports.

Code:
def orderPrice = (open[-1]+close[-1])/2;

If you see positive results (>3%) after considering above order price then your strategy would be really good.
 
T

trader54

New member
@trader54 How accurate is this Bot, and does it tie into ThinkorSwim directly. Do you have a timeline as to when it will be available?

One other question, I have a very long strategy. What are the signals required to make this work?

Trading bot is just an interface to execute TOS strategies. So accurracy dependends on how accute
I think everyone is interested in that but OP doesn't seems to share those details

I know. But without any accurate non-repainting strategy this won't work. And this requires a lot for pre-requisite setups like some python libraries, windows services, sql database running on local etc.. I didn't get a chance to work on TOS thinkscript strategies. Will share the updates soon once i have some live trading results. Sharing the details before that would create some noise nothing else.

Thanks.
 
T

trader54

New member
Can you provide more details on the extra technical stuff you mentioned for fetching TOS strategies, I know it can't be done through API. Do you have to keep TOS open for this to work, export strategies, or how do you get the Strategy alerts? Will appreciate any insights into this

Hi @yunier2002 ,
This is not easy and straightforward. For this to work, complex tech stuffs are setup. You can think of TOS strategies signals as data stream from TOS servers and i tweaked this to intercept those data streams with low level system programming. and yes we have to keep thinkorswim running for this just to intercept strategies results. But we can execute orders in any thinkorswim accounts remotely. I hope this helps. Thanks.
 
rad14733

rad14733

Well-known member
VIP
Can you provide more details on the extra technical stuff you mentioned for fetching TOS strategies, I know it can't be done through API. Do you have to keep TOS open for this to work, export strategies, or how do you get the Strategy alerts? Will appreciate any insights into this
As I had suspected, the alerts are in the script code in the initial post of this topic, and most likely in other posts, but they are commented out... I un-commented them in my copy and added in code so the can be turned off or on in the scripts settings panel rather than having to search for and un-comment them...
 
G

Ginu09

Member
I have a repainting strategy that I’d like to test on your platform. DM me
 
G

Ginu09

Member
I just confirmed with TD that there is no fees or minimum balance requirement for using APIs. However to make more than 3 trades per week you should maintain minimum of 25K portfolio value. Thanks.
I’m in Canada and don’t have this restriction as we don’t have PDT. Would be interesting to see how this works
 
Adeodatus

Adeodatus

New member
Post #50, auto-trade into profits? Even my multi-billion broker can't do that! (starts with an C, end with a B) I don't auto-trade and the pro-bot trading offered C-B hasn't recovered from March 16 yet, but it keeps trying (what a laff)!

I placed in RT's strategy, and watch closely as it spits out suggested buys, it will not auto trade, but I like the idea. Maybe in a few months I'll splash some cash into TOS and let this Strat run. Not yet...
 
Last edited:
C

codydog

Active member
@StockT8er - are those actual trading results (eg, reportable to irs as income) or running tos' strategy, eg, a simulation?
 
rad14733

rad14733

Well-known member
VIP
No that is a strategy report from my strategy. I sorta can keep up with it. Have done 60% of what it says, trading with paper money. Do not have funds to trade it live. That's why would be nice to see how a auto bot would do
If you don't have the money to potentially lose, you surely don't want to entrust it to an auto-trading bot... That's a good way to go broke in a hurry...!!! Remember, real life NEVER trades out like a back-tested strategy... NEVER...!!! You'll never buy or sell where the strategy shows because it just picks a price that indicates a trade whereas you have to get into and out of your trades wherever the market lets you... Most of the low profit strategy trades would be losers in real life...

In volatile markets it can be even worse because I've seen Thinkorswim execute Buy and Sell trades well above and below the market... I've clicked the Flatten Now button in Active Trader and watched my Buys placed well above other orders and Sells executed well below other orders... The market makers are sharks, just waiting to nibble away at your trade account funds...
 
C

codydog

Active member
@StockT8er - can you add a parameters so the bot closes out the trade at b/e or when you think it should as well? I guess eliminating the loser trades would be helpful to your p/l.

when i looked at this years ago, I found tos executes at levels that haven't traded and tos always gives you your amount, which isnt my experience in real trading. My testing was always in /nq, but if you want to see wild stuff, try /rb or /ho

Thanks for sharing your work and thoughts
 
rad14733

rad14733

Well-known member
VIP
FIRST OFF YOU HAVE NOT IDEA. I HAVE LOST OVER $45,000 IN STRATEGIES THAT DO NOT WORK. I wrote this strategy to hopefully prevent that from happening again, at the point I am willing to go back into Day Trading again. This strategy was written to work best in volatile markets, it earns the most money on a strong heartbeat. Enough said. Good Bye
Well, then you know what I was talking about... I got beat up when the market plummeted earlier in the year myself... And made then lost money this morning, so I took the rest of the day off from trading... Sometimes its best to watch from the sidelines for a bit...
 

Similar threads

Top