Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
TOS Automating AddOrder, Auto OCO bracket how to write? Repeatable?
How would I create a code to automatically purchase and sell stock? I have already created a strategy. However, the strategy only communicates for me to be able to do backtesting with a floatingPL. I don’t think I am even close to making it automated yet. I am tempted to look into 3rd party software that automates the trading. I like to buy with one strategy. Then, I am interested in exiting the trade with an OCO bracket. A TOS manual I found references 1st Triggers OCO. I already do this manually. I found another comment that says 1st Triggers 3 OCO. First, I need to master 1 OCO. Also, I am not clear how an AutoOrder knows the timeframe that I am purchasing on. If it can be automated, can I place the order to repeat on the same stock? Run on a scanner and buy results that meet the criteria?
Also, I am wondering if there is code that I can use to sell based upon the current price instead of waiting for the close of a bar. If not, can I express the code of the exit to be based on a fraction of time… like 10 seconds… Again, I am unclear how auto order works. Thanks for any help you can give me.
I wrote some basic code below to test with to show that the software is working. When I run the code below, the sell doesn’t function right… I don’t think the or code is the right word for either or…
I think this is the wrong word…
def sell = close is less than or equal to EntryPrice()-0.20 ****¬OR**** close is greater than or equal to EntryPrice()*1.03;
I know that I have a zillion questions here. Any help will be appreciated. Thanks! EK
input price = FundamentalType.CLOSE;
def buy = PPS()."BuySignal" is true and close is greater than or equal to MovAvgExponentional(“length” = 200).”AvgExp”;
def sell = close is less than or equal to EntryPrice()-0.20 ¬OR close is greater than or equal to EntryPrice()*1.03;
AddOrder(OrderType.BUY_TO_OPEN, buy, name = “EK_Buy”);
AddOrder(OrderType.SELL_TO_CLOSE, sell, name = “EK_Exit”);
Can you help answer these questions from other members on NexusFi?
TOS doesn't support real automated trading, only the backtesting simulations. If you want to build real automated strategies you'll need to use a different platform. I personally haven't done this yet, so cannot make any recommendations. However, there are many folks on here that do use automated trading, so perhaps they can point you in the correct direction.
Thanks for the feedback. Pretty lousy backtesting if you have multiple exit strategies. For example: If I want to sell when I lose one unit ***OR*** sell when I make two units, it sounds like there is not a way to backtest that.
When I contacted TOS the other day, they indicated that these 3rd parties can send automated orders to TOS. I am considering doing that so the learning curve might be easier. The majority of my code would still be accurate. For all I know, I will be starting all over again.
I'll post the 3rd party companies for other people to reference that find this thread: