NexusFi: Find Your Edge


Home Menu

 





TOS Automating AddOrder, Auto OCO bracket how to write? Repeatable?


Discussion in ThinkOrSwim

Updated
    1. trending_up 1,909 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 1 attachments




 
Search this Thread

TOS Automating AddOrder, Auto OCO bracket how to write? Repeatable?

  #1 (permalink)
EKTrade
SANTA CLARITA
 
Posts: 8 since Mar 2021
Thanks Given: 2
Thanks Received: 0

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”);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Strategy stop orders partially filled
EasyLanguage Programming
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
Quantum physics & Trading dynamics
The Elite Circle
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
26 thanks
What is Markets Chat (markets.chat) real-time trading ro …
15 thanks
GFIs1 1 DAX trade per day journal
13 thanks
ApexTraderFunding.com experience and review
13 thanks
EG Indicators
11 thanks
  #2 (permalink)
 JayC 
San Diego, CA
 
Experience: Beginner
Platform: TOS, Sierra
Trading: Emini ES, Crude CL
Posts: 55 since Mar 2019
Thanks Given: 9
Thanks Received: 43

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.

Jay

Reply With Quote
  #3 (permalink)
EKTrade
SANTA CLARITA
 
Posts: 8 since Mar 2021
Thanks Given: 2
Thanks Received: 0


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:

ninja trader
medved trader
motivewave
dastrader

Thanks!

Attached Images
 
Reply With Quote




Last Updated on March 10, 2021


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts