Auto Trade (ALGO) in TOS

@chotamatar either IB or TDA could do this via their respective api, check out tda-api from alex golec they have a discord channel just look up Interactive Broker api for ideas on that
 
@Svanoy wondering about TOS screen flicker with your autohotkey. last night running a similar type program the screen goes into a jitter mode. I have seen this before and I have to close the chart and reopen. it really messes up a screen monitoring program. Has this occurred for you?
 
@irishgold
Everyday after the futures market restarts at 6 p.m. the screen will flicker every few seconds.
It has never caused any issue with my program though.

All I have to do is pause my program, go to the "Edit Studies" window and click apply to stop it, and then unpause my program. Never had to close the chart.
Sometimes I forget what time it is and it has gone for hours doing that flicker, never caused any issues.
 
Last edited:
This is a pretty simple "dumb" smart bot its a python based program.
the "bot" works perfectly as i envisioned it.

the only variable is the strategy being used to generate the signals(if you have a good strategy script that doesn't repaint, help a brother out).

how it works is pretty simple, see image on basics works and proof that it does.

daOZ7Zj.png


dNFMCk3.jpg
 
Last edited by a moderator:
the only variable is the strategy being used to generate the signals(if you have a good strategy script that doesn't repaint, help a brother out).

how it works is pretty simple, see image on basics works and proof that it does.

I tried this approach a while ago, simulated trading works fine, but realtime trading based on strategy alerts that too on a 1m timeframe will make you plenty of losses. You can try it for yourself, try trading with your bot with 1 AAPL share for a day and let us know the result, assuming you are a PDT. All the best!
 
Last edited by a moderator:
I'm taking a different approach but its a work in progress. I'm using the real time account to monitor the strategy. The main issue with TOS is now you see it now you don't until it goes to a solid visual signal. Using higher timeframes help. Using only the "AddOrder" arrows not "buy" signals or other painted arrows helps, I am using an image recognition python app just on the arrows. Friday there wasn't a lot of trades on the 15 min NQ but it did fairly good. I'm also sending the trades to Ninjatrader, they have what is called OIF Order Instruction File that as the trade activates it sends a txt file to a certain folder. NT is watching that folder and activates your order. It all happens in milliseconds. Since using python I could also send the order to TDA-api but the api only allows real trading. Also you can use Interactive Broker TWS api they do allow paper trading. So there are a bunch of ways to do this.
@Gilgameash nice setup, it's some what similar to what @Svanoy is doing with his autohotkey, still it requires a lot of setup on the TOS screen to isolate the text. On my app I need to have TOS visually present but don't need to configure the screen other than in the strategy, to set the arrow colors of the buy and sell and close orders.
Kudos to the auto-traders !!!
 
@irishgold
Would you mind letting me see your strategy? I may be able to help you with the repainting you are experiencing and get it to match your "AddOrder". This may provide you with a better visual of what is going on.
 
I tried this approach a while ago, simulated trading works fine, but realtime trading based on strategy alerts that too on a 1m timeframe will make you plenty of losses. You can try it for yourself, try trading with your bot with 1 AAPL share for a day and let us know the result, assuming you are a PDT. All the best!
Will it all depends on the strategy and how it's written, the one I'm using/working on doesn't take alot of trades, it has a 70% win rate on any time frame less than 30m, I run it on 1m to test accuracy of bot, so far it 100% accurate,
I did run it on a 1d 1m time frame on 1/28/22 see the second image for trade that were placed and what strategy predicted and time bot clicked the buttons. Also account balance on 1st image.
All my orders will go in for market price on the open of current bar if there is a signal so their will always be a discrepancy between gain/loss on strategy report and actual price(see 2nd image).
 
Last edited:
I'm taking a different approach but its a work in progress. I'm using the real time account to monitor the strategy. The main issue with TOS is now you see it now you don't until it goes to a solid visual signal. Using higher timeframes help. Using only the "AddOrder" arrows not "buy" signals or other painted arrows helps, I am using an image recognition python app just on the arrows. Friday there wasn't a lot of trades on the 15 min NQ but it did fairly good. I'm also sending the trades to Ninjatrader, they have what is called OIF Order Instruction File that as the trade activates it sends a txt file to a certain folder. NT is watching that folder and activates your order. It all happens in milliseconds. Since using python I could also send the order to TDA-api but the api only allows real trading. Also you can use Interactive Broker TWS api they do allow paper trading. So there are a bunch of ways to do this.
@Gilgameash nice setup, it's some what similar to what @Svanoy is doing with his autohotkey, still it requires a lot of setup on the TOS screen to isolate the text. On my app I need to have TOS visually present but don't need to configure the screen other than in the strategy, to set the arrow colors of the buy and sell and close orders.
Kudos to the auto-traders !!!

When approaching "auto trading" I too thought of using the api and a third party to place the orders, but then i thought why over complicate things.
My setup isn't complicated, I have a cheap laptop used only to run TOS and the bot, layout of TOS screen can be permanently saved within the platform (save workspace). All I have to do is have TOS open and click run on the bot and it works just fine, I go about my day
 
I think that a more advance suit of automation features would be a great selling feature of the 40 dollar Book Map sub.

They could also offer a interface like the following for think script beginners. Even I sometimes self-face palm. For the longest time I thought that "value @ low" meant the lowest candle price/value.

https://en.wikipedia.org/wiki/Scratch_(programming_language)

Comparison_of_Scratch_1.4_and_Scratch_2.png
 
Last edited by a moderator:
Turning a scan into a method for triggering a trade
I have a scan that uses two time frames.

There probably isn't a way to turn it into a trade..? I'm just making sure.

Is there another way to do it via API or something?

TIA
 
Last edited by a moderator:
Turning a scan into a method for triggering a trade
I have a scan that uses two time frames.

There probably isn't a way to turn it into a trade..? I'm just making sure.

Is there another way to do it via API or something?

TIA
No scans cannot be turned into trades. But the same script that generated the scan can be used to create conditional order. Conditional orders are placed against a specific equity on a specific timeframe and only fire once.

I moved your question to this thread. It contains everything known about API on this forum.
 
@Jonessw1 I have been running AHK very successfully since January. My setup uses many of the ideas from @Svanoy with the AHK and TOS. I have spent numerous hours coding my strategies, but finally have a solid system that has been averaging over 100% gains per month using a MACD strategy on a 5 min chart from Jan - Mar. This is using live paper trades (not backtesting results). I finally went live with it this month, using real money. Much of the concepts have already been discussed, but some things I like to mention are;

1. I use two Virtual Machines running windows server 2019 Trial. Both are running on a cheap Beelink box I got from Amazon. It has an intel i5 Processor, 16GB of ram. This allows me to run my tests and real trades on two instruments at a time (eg: MES and MNQ). It was a little over $400 when I bought it, and since it's dedicated to my algo, I don't have to worry about accidental interruptions because I'm using it for other work. Also, before using a dedicated PC, I was getting resource errors, etc.... now nothing.

2. @Svanoy mentioned in an earlier response to me, recognizing the labels can be tricky for AHK, so see our discussion above on how to properly crop the images, or it will drive you mad :)

3. Build in safety measures. Use TRG/W bracket order to set an automatic stop when taking a trade, this should be set far enough away to never trigger, unless there's an error and your trade goes against you without stopping out. Additionally, I had some issues in the beginning where some trades got caught in a loop so I built into AHK where it will not take more than 4 trades in x number of minutes, or it will pause for an hour.

4. If you trade this live, and you're away from home, make sure you have a way to stop your algo. I have an app on my phone that allows me to connect to my home VPN, then to the machine running my algo.

That's all I can think of at the moment, but if you have any questions, I'm happy to answer them ;)
 
@irishgold @Svanoy @tradecombine
Just checking back in, how have your individual programs been running?
Have you switched over to the API or continued with AHK?

I am not running a program to automatically trade yet. I pardon if I misled in anyway to insinuate that.

When I want to day-trade I tend to use the built-in features: conditional order templates, or first triggers sequence, but that's about it.

I do WANT to auto-trade, but not there yet.

I have tested enough with the API to submit orders (based on PartTimeLarry tutorials on Youtube), but the lack of paper-trading (and the fact that I get new ideas all the time that I want to test) has me cooling off wanting to go too far with the API.

If I did something via GUI, it would probably be via PyAutoGUI, so I could use something that I'm familiar with while also using a language (Python) I can use within my career field.
 
@Jonessw1 I have been running AHK very successfully since January. My setup uses many of the ideas from @Svanoy with the AHK and TOS. I have spent numerous hours coding my strategies, but finally have a solid system that has been averaging over 100% gains per month using a MACD strategy on a 5 min chart from Jan - Mar. This is using live paper trades (not backtesting results). I finally went live with it this month, using real money. Much of the concepts have already been discussed, but some things I like to mention are;

1. I use two Virtual Machines running windows server 2019 Trial. Both are running on a cheap Beelink box I got from Amazon. It has an intel i5 Processor, 16GB of ram. This allows me to run my tests and real trades on two instruments at a time (eg: MES and MNQ). It was a little over $400 when I bought it, and since it's dedicated to my algo, I don't have to worry about accidental interruptions because I'm using it for other work. Also, before using a dedicated PC, I was getting resource errors, etc.... now nothing.

2. @Svanoy mentioned in an earlier response to me, recognizing the labels can be tricky for AHK, so see our discussion above on how to properly crop the images, or it will drive you mad :)

3. Build in safety measures. Use TRG/W bracket order to set an automatic stop when taking a trade, this should be set far enough away to never trigger, unless there's an error and your trade goes against you without stopping out. Additionally, I had some issues in the beginning where some trades got caught in a loop so I built into AHK where it will not take more than 4 trades in x number of minutes, or it will pause for an hour.

4. If you trade this live, and you're away from home, make sure you have a way to stop your algo. I have an app on my phone that allows me to connect to my home VPN, then to the machine running my algo.

That's all I can think of at the moment, but if you have any questions, I'm happy to answer them ;)

Thanks for taking the time.

I too have been running live with AHK -- hundreds of hours spent tinkering.
All of your tips are spot-on. By using Google Remote Desktop I have been able to get around buying a dedicated computer for the program. Its free and allows me to monitor/halt trading. As always, it boils down to strategy. I stick to a simple moving average crossover and shut it off when I reach my predetermined daily goal as I am susceptible to giving back gains. Automatically shutting off my program when a daily P/L is reached has actually been my latest project and I have hit a wall, so ideas would be appreciated. I have found OCR to be unreliable, and I can't create a 'Day P/L Label' on a chart less than 1D. Any insight?
 
Thanks for taking the time.

I too have been running live with AHK -- hundreds of hours spent tinkering.
All of your tips are spot-on. By using Google Remote Desktop I have been able to get around buying a dedicated computer for the program. Its free and allows me to monitor/halt trading. As always, it boils down to strategy. I stick to a simple moving average crossover and shut it off when I reach my predetermined daily goal as I am susceptible to giving back gains. Automatically shutting off my program when a daily P/L is reached has actually been my latest project and I have hit a wall, so ideas would be appreciated. I have found OCR to be unreliable, and I can't create a 'Day P/L Label' on a chart less than 1D. Any insight?

I have thought about a daily profit as well, but haven't done it yet. My thoughts on how to do this in thinkscript would be to use one of the functions like SecondsTillTime() or SecondsFromTime() to set or clear a variable at midnight each night, then use GetOpenPL() function to keep track of profit and loss, once a target is reached, then go flat. That's just a general concept, my code now allows me to pick times of the day to not trade and also has times it goes flat, eg: no new trades between 9A and 10A, and go flat if I'm in a trade at 9:15AM so I can avoid the wild ride at open. BUT, like anything I've done with thinkscript, simple things always seem to require hacks, work-arounds, and lots of frustration, LOL.
 
@Jonessw1 Late to answer, but I've been running a few different strategies live over the past year mainly to confirm back testing results.
As far as the auto trade setup I am using with AHK, it has worked flawlessly.
As far as profit goes, it has been moderate. I did expect this though as I trade futures and purposely start each run with as little as possible in micro markets, this leads to the commission cost of the trades eating up much of the profit.
I can say I make enough to keep the account I use funded.
As I identify strong strategies, I will eventually move into larger markets where commissions won't be an issue.

I have recently moved up to larger time frames to offset the commission costs.

The only real issue I have had is the PC I was using as a dedicated autotrader crapped out, so I'm using my main PC for right now which has led to me not being as active on this forum.

In order to track total profit, you have to track it in your study. Here is mine as example, I use it to calculate how many contracts to run, it should help you get started.


J8lRYFs.png

Ruby:
input tolerance = 0;
def PL;
def PLT;
def profit;
def size;

if TradeCount <= 0
then {
    PL = -2.52;
    PLT = 0;
    profit = startamt + PL;
    size = if RoundDown(profit / contractprice, 0) - 1 <= 0 then 1 else RoundDown(profit / contractprice, 0) - 1;

} else if State[1] == 0 and State == 1 {
    PL = (RoundDown(((((TP[1] - tolerance) - (TP[0] + tolerance)) / TickSize()) * TickValue()) * size[1], 2)) - (5.45 * size[1]);
    PLT = (RoundDown(((((TP[1] - tolerance) - (TP[0] + tolerance)) / TickSize()) * TickValue()) * size[1], 2));
    profit = profit[1] + PL;
    size = if RoundDown(profit / contractprice, 0) - 1 <= 0 then 1 else RoundDown(profit / contractprice, 0) - 1;
   
} else if State[1] == 1 and State == 0 {
    PL = (RoundDown(((((TP[0] + tolerance) - (TP[1] - tolerance)) / TickSize()) * TickValue()) * size[1], 2)) - (5.45 * size[1]);
    PLT = (RoundDown(((((TP[0] + tolerance) - (TP[1] - tolerance)) / TickSize()) * TickValue()) * size[1], 2));
    profit = profit[1] + PL;
    size = if RoundDown(profit / contractprice, 0) - 1 <= 0 then 1 else RoundDown(profit / contractprice, 0) - 1;
   
} else {
    PL = PL[1];
    PLT = PLT[1];
    profit = profit[1];
    size = if RoundDown(profit / contractprice, 0) - 1 <= 0 then 1 else RoundDown(profit / contractprice, 0) - 1;
   
}
def TotalGain = if TradeCount < 0 then 0 else if PL[1] != PL and PL >= 0 then TotalGain[1] + PL else TotalGain[1];
def TotalLoss = if TradeCount < 0 then 0 else if PL[1] != PL and PL <= 0 then TotalLoss[1] + PL else TotalLoss[1];

def WinCount = if TradeCount <= 0 then 0
else if (TradeCount[1] + 1) == TradeCount and PL >= 0 then WinCount[1] + 1
else WinCount[1];

def LossCount = if TradeCount <= 0 then 0
else if (TradeCount[1] + 1) == TradeCount and PL <= 0 then LossCount[1] + 1
else LossCount[1];

AddChartBubble(show_bubbles and !IsNaN(GU[0]) and IsNaN(GU[1]) and State == 1 and TradeCount >=0, if PL>=0 then high else low, "#"+TradeCount+" Buy:" + size[1] + "| P/L:" + profit + " |Buy:" + size, If TradeCount==0 then Color.GRAY else If PL>0 then Color.LIGHT_GREEN else If PL<0 then Color.PINK else Color.LIGHT_GRAY, no);

AddChartBubble(show_bubbles and IsNaN(GX[1]) and !IsNaN(GX[0]) and State == 0 and TradeCount >=0, if PL<0 then low else high, "#"+TradeCount+" Sell:" + size[1] + "| P/L:" + profit + " |Sell:" + size, If Tradecount==0 then Color.GRAY else If PL>0 then Color.LIGHT_GREEN else If PL<0 then Color.PINK else Color.LIGHT_GRAY, yes);
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
472 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top