Auto Trade (ALGO) in TOS

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

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 !!!
EXTREMELY good Idea keep us posted U just may have the work around .
 
@kilowatt39
Post what you've got and I'll take a look.
I changed from using the HullMA ,am now using the RSI with the center line also for entry,problem is when the price keep breaking below and above in a short time its giving me too much signals.Anyway see if you can fix it for me,thanks in advance, The script is a mess but i am using it

Code:
#rsi
input longEntries = yes;
input ShortEntries = yes;
input price = close;
input tradesize = 1;
input StartTrading = 930;
input StopTrading = 1600;
input ShowTodayOnly = {"No", default "Yes"};

def s=ShowTodayOnly;
def today=if s==0 OR getday()==getlastday() AND secondsfromtime(StartTrading)>=0 then 1 else 0;
def t2trade = today and secondsFromTime(StartTrading) > 0 and secondsFromTime(StopTrading)<0  ;


## ema stoploss ##############
input emaStopLoss = yes;
input emaStopLenght = 9;
input emaLongDisplace = 0;
input emaShortDisplace = 0;
def emaX = MovingAverage(AverageType.EXPONENTIAL, close, emaStopLenght);

input rsiStopLoss = yes;
input rsiEntryOffset = 0;
input rsiStopOffset = 0 ;

input length = 14;
input OB = 70;
input OS = 30;
input neutral= 50;
input rsiAverageType = AverageType.WILDERS;

def over_bought = OB;
def over_sold = OS ;
def rsi = reference RSI(price = price, length = length, averageType = rsiAverageType);


##### Stop Loss / Profit Target ####
input offsetType = {default VALUE,percent, tick};
input longTarget = 50;
input shortTarget = 50;
input longStop = 50;
input shortStop = 50;
def entryPrice = open;#EntryPrice();
def mult;
switch (offsetType) {
case percent:
    mult =entryPrice / 100;
case value:
    mult = 1;
case tick:
    mult = TickSize();
}

def longstopPrice;
def shortstopPrice;
def longTargetPrice;
def shortTargetPrice;

if high[1] >= shortStopPrice[1]{
    longstopPrice = Double.NaN;
    shortstopPrice = Double.NaN;
    longTargetPrice = Double.NaN;
    shortTargetPrice = Double.NaN;
}else if low[1] <= shortTargetPrice[1]{
    longstopPrice = Double.NaN;
    shortstopPrice = Double.NaN;
    longTargetPrice = Double.NaN;
    shortTargetPrice = Double.NaN;
}else if high[1] >= longTargetPrice[1]{
    longstopPrice = Double.NaN;
    shortstopPrice = Double.NaN;
    longTargetPrice = Double.NaN;
    shortTargetPrice = Double.NaN;
}else if low[1] <= longstopPrice[1]{
    longstopPrice = Double.NaN;
    shortstopPrice = Double.NaN;
    longTargetPrice = Double.NaN;
    shortTargetPrice = Double.NaN;
}else if rsi[1] crosses above over_bought[1] and IsNaN(longstopPrice[1]) {        
    longstopPrice = entryPrice - longstop * mult;
    shortstopPrice = Double.NaN;
    longTargetPrice = entryPrice + longtarget * mult;
    shortTargetPrice = Double.NaN;
}else if rsi[1] crosses below over_sold[1]and IsNaN(shortstopPrice[1]) {  
    longstopPrice = Double.NaN;
    shortstopPrice = entryPrice + shortstop * mult;
    longTargetPrice = Double.NaN;
    shortTargetPrice = entryPrice - shorttarget * mult;
}else{
    longstopPrice = longstopPrice[1];
    shortstopPrice = shortstopPrice[1];
    longTargetPrice = longTargetPrice[1];
    shortTargetPrice = shortTargetPrice[1];}

def long =  rsi[0] crosses above over_bought[0];
def long2 = rsi[0] crosses above neutral ;     
def longStopT = !isnan(longstopprice) and low <= longstopprice;
def longProfit = !isnan(longTargetPrice) and high >= longTargetPrice;

def short =  rsi[0] crosses below over_sold[0] ;
def short2 = rsi[0] crosses below neutral ;
def shortStopT = !isnan(shortstopprice) and high >= shortstopprice;
def shortProfit = !isnan(shortTargetprice) and low <= shortTargetprice;

def OpenOrders = GetQuantity();
def ordfill = OpenOrders > 0 ;
def ordempty = OpenOrders < 1 ;
def orderx; if ordfill {orderx = 1;} else if ordempty {orderx = 0;} else {orderx = orderx[1];}

## Ema Stoploss ######
def emaLongStopT = close crosses below emaX[emaLongDisplace] ;
def emaShortStopT = close crosses above emaX[emaShortDisplace] ;
def emaBelow = emaLongStopT;
def emaAbove = emaShortStopT;
def emaLongStopTrigger = if emaBelow[1] then 1 else 0;
def emaShortStopTrigger = if emaAbove[1] then 1 else 0;

## Rsi Stoploss #######
def rsiLongStopT = rsi crosses below over_bought[rsiStopOffset] ;
def rsiShortStopT = rsi crosses above over_sold[rsiStopOffset];
def rsiBelow = rsiLongStopT;
def rsiAbove = rsiShortStopT;
def rsiLongStopTrigger = if rsiBelow[1] then 1 else 0;
def rsiShortStopTrigger = if rsiAbove[1] then 1 else 0;



#### Orders ####
AddOrder(OrderType.BUY_AUTO, (longEntries) and t2trade and long[-1], price = open[-2], tickcolor = GetColor(6), arrowcolor = GetColor(6), name = "Long Entry", tradeSize= tradesize);
AddOrder(OrderType.BUY_AUTO, (longEntries) and t2trade and long2[-1] , price = open[-2], tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "nLong Entry", tradeSize= tradesize);
AddOrder(OrderType.SELL_TO_CLOSE, t2trade and longStopT[-1], price = longstopPrice[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "Long Stop", tradeSize= tradesize);
AddOrder(OrderType.SELL_TO_CLOSE, t2trade and longProfit[-1], price = longTargetPrice[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "Long Profit", tradeSize= tradesize);
AddOrder(OrderType.SELL_TO_CLOSE, (longEntries)  and t2trade and rsiLongStopT[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "rLong Stop", tradeSize= tradesize);
AddOrder(OrderType.SELL_TO_CLOSE, (longEntries) and (emaStopLoss) and t2trade  and emaLongStopT[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "eLong Stop", tradeSize= tradesize);


AddOrder(OrderType.SELL_AUTO,(ShortEntries) and t2trade and short[-1], price = open[-2], tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "Short Entry", tradeSize= tradesize);
AddOrder(OrderType.SELL_AUTO, (ShortEntries) and t2trade and short2[-1]   , price = open[-2], tickcolor = GetColor(2), arrowcolor = GetColor(2), name = "nShort Entry", tradeSize= tradesize);
AddOrder(OrderType.BUY_TO_CLOSE, t2trade and shortStopT[-1], price = shortstopPrice[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "Short Stop", tradeSize= tradesize);
AddOrder(OrderType.BUY_TO_CLOSE, t2trade and shortProfit[-1], price = shortTargetPrice[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "Short Profit", tradeSize= tradesize);
AddOrder(OrderType.BUY_TO_CLOSE,  (ShortEntries) and t2trade and rsiShortStopT[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "rShort Stop", tradeSize= tradesize);
AddOrder(OrderType.BUY_TO_CLOSE, (ShortEntries) and (emaStopLoss) and t2trade and emaShortStopT[-1], tickcolor = GetColor(9), arrowcolor = GetColor(9), name = "eShort Stop", tradeSize= tradesize);


def LongStopTrigger = t2trade and (!IsNaN(longStopPrice) and IsNaN(longStopPrice[-1]) and IsNaN(shortStopPrice[-1]) and low <= longStopPrice);
def LongTargetTrigger = t2trade and (!IsNaN(longStopPrice) and IsNaN(longStopPrice[-1]) and IsNaN(shortStopPrice[-1]) and high >= longTargetPrice);
def ShortStopTrigger = t2trade and (!IsNaN(shortStopPrice) and IsNaN(shortStopPrice[-1]) and IsNaN(longStopPrice[-1]) and high >= shortStopPrice);
def ShortTargetTrigger = t2trade and (!IsNaN(shortStopPrice) and IsNaN(shortStopPrice[-1]) and IsNaN(longStopPrice[-1]) and low <= shortTargetPrice);


#### Labels ####
AddLabel(yes, "        ", if (longEntries) and t2trade and long[1] or (longEntries) and t2trade and long2[1]  then CreateColor(153, 255, 153) else Color.GRAY);
AddLabel(yes, "        ", if (ShortEntries) and t2trade and short[1] or (ShortEntries) and t2trade and short2[1] then CreateColor(255, 102, 102) else Color.DARK_GRAY);
AddLabel(IsNaN(LongStopTrigger) and !ShortStopTrigger and !ShortTargetTrigger,"        ",Color.WHITE);
AddLabel(!LongStopTrigger and IsNaN(ShortStopTrigger) and !LongTargetTrigger, "        ",Color.WHITE);
AddLabel(IsNaN(LongStopTrigger) and IsNaN(ShortStopTrigger), "        ",Color.WHITE);
AddLabel(LongStopTrigger, "        ", Color.YELLOW);
AddLabel(LongTargetTrigger, "        ", Color.YELLOW);
AddLabel(ShortStopTrigger, "        ",Color.YELLOW);
AddLabel(ShortTargetTrigger, "        ",Color.YELLOW);

AddLabel(yes, "        ", if  emaLongStopTrigger ==1 or rsiLongStopTrigger == 1 then Color.PLUM else if emaShortStopTrigger ==1 or rsiShortStopTrigger == 1 then Color.DARK_ORANGE else Color.PINK);
AddLabel(yes, if orderx == 1 then "        " else "        ", if orderx == 1 then Color.Blue else Color.Magenta);
 
@kilowatt39
Been looking thorough this and it looks like you are basing some of your signals on current bar price movement instead of previous bar.
EX:
Ruby:
def long =  rsi[0] crosses above over_bought[0];
def long2 = rsi[0] crosses above neutral ;     

def short =  rsi[0] crosses below over_sold[0] ;
def short2 = rsi[0] crosses below neutral ;

The snippet above from your code is able to signal multiple times over the course of a bar.
I suggest going through and make sure you are referencing the previous bar when generating signals.
 
Hello @irishgold thank you for the encouragement. Sorry, it is a study from the premium indicator forum so I cannot share the code here. I veered off on a tangent in my previous post anyways. the script utility is AutoHotKey. It allows the ability to define certain parts of the screen to monitor and using a label to indicate buy or sell by color displayed means I only have to monitor a small static section instead of the entire screen. It also works with the computer monitor, mouse, and keyboard disconnected from the computer. It has not missed a single signal.

As far as repaint, the study I'm using does not repaint. Yes, back testing can be very misleading. Fortunately, with the modification to the study I'm using, I'm able to see the price at which to execute a trade at all times and will eventually move to running a buy stop limit order instead of buying at market. That with a standard trailing stop, makes plotting the buy and sell very easy. Market activity may change in the future and maybe not as many trade setups will present themselves or maybe more will. I keep my chart at 180 days as this is the longest amount of time that will still allow a 39 minute bar. As days pass and that May 25th live trade start date gets further away, the constant back testing of 180 days from present has matched exactly and the Win/Loss ratio has seen little change.

In regards to NT, part of this live run I started back in May, is to see if I can start with the bare minimum cost and investment, build capital, and eventually move up to /ES. Also, since not all trades are winning trades, the less it costs the less it concerns me to lose. Actually lost $180.00 dollars today, but it was money I didn't have a week ago. Low cost and a positive Win/Loss ratio allows me to worry about keeping the program running, and not what it is actually doing at the moment.


Hi, will you share the name of premium indicator forum so that others can go purchase should they desire?
 
Hello everyone,
Just curious if you found a way to automate your TOS trading?
Micro Recorder, AHK, python or other?
Are you paper trading or using solution to trade with real money (day- or swing-trading)?
Thank you
 
I'm using a tool called SAT-daddy. I've been doing both paper and live trading with it; but am currently concentrating on my ThinkScript strategy code to perfect the strategy.
 
Last edited by a moderator:
I'm using a tool called SAT-daddy. I've been doing both paper and live trading with it; but am currently concentrating on my ThinkScript strategy code to perfect the strategy.

Many thanks for your reply,

I went to SAT-daddy website, trying to learn more about that product.

The developer is asking for over $1200 for annual subscription, with listed comment:
Due to the nature of how we implement our proprietary system, there are no refunds or evaluation periods.

Also, what caught my eye, another comment :
By simply adding a few lines of ThinkScript code to your existing strategy, you can make it “SAT-daddy aware“.
We provide complete instructions and even include a sample strategy that is SAT-daddy compatible.


If it is not too much trouble, could you please share some light: :unsure:
  • is the SAT-daddy system monitors and trades only one instrument and/or strategy ?
  • how the SAT-daddy systems integrates with strategy, what script changes are required, given earlier comment?
  • if the SAT-daddy system supports Advanced Orders Trading templates (e.g., OCO, TRG w/bracket,etc)
( where the Advanced Orders are configured?)

Sorry for soo many questions, just trying to understand the SAT-daddy benefits.
Thanks
 
Best to contact the developer directly with these questions. I think there's a contact form on the web site.
 
Last edited:
Many thanks for your reply,

I went to SAT-daddy website, trying to learn more about that product.

The developer is asking for over $1200 for annual subscription, with listed comment:
Due to the nature of how we implement our proprietary system, there are no refunds or evaluation periods.

Also, what caught my eye, another comment :
By simply adding a few lines of ThinkScript code to your existing strategy, you can make it “SAT-daddy aware“.
We provide complete instructions and even include a sample strategy that is SAT-daddy compatible.


If it is not too much trouble, could you please share some light: :unsure:
  • is the SAT-daddy system monitors and trades only one instrument and/or strategy ?
  • how the SAT-daddy systems integrates with strategy, what script changes are required, given earlier comment?
  • if the SAT-daddy system supports Advanced Orders Trading templates (e.g., OCO, TRG w/bracket,etc)
( where the Advanced Orders are configured?)

Sorry for soo many questions, just trying to understand the SAT-daddy benefits.
Thanks
Because of proprietary rules. Really can't discuss this on this forum.

Also note: because it is not possible to "hide" or "lock" ThinkScript code; none of your research will find ToS Algo sites that can offer refunds or evaluation periods.

AND as you have seen the price is not small but not really expensive considering that algo sites assume that you will be making dozens of trades daily.

As long as you have a well-developed ThinkScript strategy code that is generating consistent profits; then which algo site, you end up with; doesn't matter as much.
 
Last edited:
Because of proprietary rules. Really can't discuss this on this forum.

Also note: because it is not possible to "hide" or "lock" ThinkScript code; none of your research will find ToS Algo sites that can offer refunds or evaluation periods.

AND as you have seen the price is not small but not really expensive considering that algo sites assume that you will be making dozens of trades daily.
Thank you very much for your comments. Frankly, we all know the lack of automation in TOS is not a dealbreaker. As long as you have a plan - what and when to trade.
Still, nice and long awaited feature.
 
Hi , I have gone through the thread but not sure if it is valid in 2025 and how to create and run the script? is it on Windows as task scheduler or batch script ... any inputs or technical steps are greatly appreciated
 
Hi , I have gone through the thread but not sure if it is valid in 2025 and how to create and run the script? is it on Windows as task scheduler or batch script ... any inputs or technical steps are greatly appreciated

What, specifically, are you referring to with your question...??? There are various mentions of methods of automated trading and semi-automatic trading mentioned throughout this topic...
 
I wanted to share my latest ahk algo script. To use this you will need to set all the coordinates and images files.

View attachment 17090

CSS:
; Created/Shared by Kevin N altered by SilverWolf
;https://usethinkscript.com/threads/auto-trade-algo-in-tos.7546/page-15#post-116225
; Version Beta .15 - Last Modified: 01-05-23
; streamlined cleaned up script
; INI settings added
; P/l grabbed by Vis2OCR
; Gui upgrades: mini buttons time and chart
; Added three indicator look and agreement to take position
; Single share assurance for futures
; Added TOS position checks
; Added GUI
; Added option to disable pre-buy/sell flatten for quicker entries.
; double tap the flatten button.
; last mod creates a delay after trade closes and new trade allowed
; .07 Added entryPause Added error clearing feature.
; ver .062 Added pause for x number of minutes features.
; Made some adjustments to the screen and added auto status.
; This version to be used with the algo version 5.5 or later.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance [Forced]

#include <Vis2>

CoordMode, ToolTip, Screen
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen

; User Defineable variables
; Use the following to set the vertical and horizontal coordinates for each.
buttonsHorizontal     = 1635    ; Horizontal Coordinates, this will be the same for buy, flat, sell.
buyCoord              = 155     ; Vertical Coordinates, middle of button
sellCoord             = 189    ; Vertical Coordinates, middle of button
flatCoord             = 222     ; Vertical Coordinates, middle of button
statusHorizontal      = 80     ; The horizontal setting for the status bar
statusCoord           = 783    ; The vertical setting for the status bar


tradeLimit             = 100      ; How many trades are allowed in clearCounterPeriod before sitting out resetPeriod
resetPeriod            = 900      ; In Seconds, if tradeLimit is reached in clearCounterPeriod, how long to wait before another trade
clearCounterPeriod     = 1800     ; In Seconds, if tradeLimit is reached in this amount of time, sit out resetPeriod
entryDelay             = 5        ; In Seconds, the amount of time that must pass before another entry is allowed
exitDelay              = 0        ; In Seconds, Time that must pass after a trade exits before its allowed to buy again.
delayTime              = 0        ; In Seconds, the amount of time to wait sleep after buy, short, or flat.
entryPause             = 0        ; In Seconds, the amount of seconds to pause before pressing the buy/sell button.
flatBeforeEntry        = 0        ; In Seconds, amount of time to wait after pre-buy/sell flatten, if 0 then no pre-buy/sell flatten.


; End user defineable
global status          = 0
global statusWord      = ???
trades                 = 0
stopTimer              = 0
tosErrors              = 0
Checkbox_1             = 1
GoLong                 = 0
GoShort                = 0

; Generated using SmartGUI Creator 4.0
Gui, Destroy
Gui -Caption +ToolWindow +Border +LastFound +AlwaysOnTop -Border +hWndhGUI
;Gui, Color, 313131
Gui, Color, 4b4b4b
;Gui, Font, S7 CDefault Bold, Verdana
Gui, Font, S8 , Verdana
Gui, Add, Button, x2 y0 w50 h24 , Start
Gui, Add, Button, x52 y0 w50 h24 , Pause
Gui, Add, Button, x102 y0 w50 h24 , Settings
Gui, Add, Button, x202 y0 w50 h24 , Trash
Gui, Add, Button, x152 y0 w50 h24 , Refresh
Gui, Add, Button, x252 y0 w50 h24 , Focus
Gui, Add, Button, x302 y0 w30 h24 , 1
Gui, Add, Button, x332 y0 w30 h24 , 2
Gui, Add, Button, x362 y0 w30 h24 , 3
Gui, Add, Button, x392 y0 w30 h24 , 4
Gui, Add, Button, x422 y0 w30 h24 , 5
Gui, Add, Checkbox, x463 y-4 w13 h30 Checked vCheckbox_1 gSubmit_All, OneC
Gui, Add, Button, x487 y0 w50 h24 , Exit
;Gui, Add, Text, x4 y30 w540 h30 cffffff,

Gui, Show, x780 y51 h25 w539, TOS Algo Trading System
Gui, Submit, NoHide
Return


Submit_All:
Gui, Submit, NoHide
Return

ButtonExit:
GuiClose:
ExitApp   2

ButtonPause:
Send Esc
Pause,, 1
tooltip [>    ~TOS Algo Trading System is PAUSED~    <], %statusCoord%, %statusHorizontal%
Return

ButtonSettings:
Run, notepad.exe "My TOS ALGO Settings.ini"
Return

ButtonRefresh:
Run, lib/TOS refresh chart
Return

ButtonTrash:
;Run, lib/TOS collect garbage
    MouseClick, Left, 720, 60, 1, 0
    Sleep 10
    MouseClick, Left, 316, 83, 1, 0
    Sleep 10
    MouseClick, Left, 1700, 120, 1, 0
    Sleep 10
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    MouseMove,  1080, 111, 100
Return

ButtonFocus:
;Run, lib/TOS focus
    MouseClick, Left, 70, 200, 1, 0
    Sleep 10
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    MouseMove,  1080, 111, 100
Return
Return

Button1:
if (Checkbox_1 = 1){
;Run, lib/TOS ActiveTrader
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    MouseMove,  1080, 111, 100

}Else{
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    Run, lib/TOS 4000t
    MouseMove,  1080, 111, 100
}
Return

Button2:
if (Checkbox_1 = 1){
;Run, lib/TOS ForexTrader
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 345, 85, 1, 0
    MouseMove,  1080, 111, 100
}Else{
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    Run, lib/TOS 2000t
    MouseMove,  1080, 111, 100
}
Return

Button3:
if (Checkbox_1 = 1){
;Run, lib/TOS FuturesTrader
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 465, 85, 1, 0
    MouseMove,  1080, 111, 100
}Else{
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    Run, lib/TOS 1000t
    MouseMove,  1080, 111, 100
}
Return

Button4:
if (Checkbox_1 = 1){
;Run, lib/TOS PairsTrader
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 715, 85, 1, 0
    MouseMove,  1080, 111, 100
}Else{
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    Run, lib/TOS 500t
    MouseMove,  1080, 111, 100
}
Return

Button5:
if (Checkbox_1 = 1){
;Run, lib/TOS Charts
    MouseClick, Left, 535, 62, 1, 0
    MouseMove,  1080, 111, 100
}Else{
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    Run, lib/TOS 64t
    MouseMove,  1080, 111, 100
}
Return



^B:: MouseClick, Left,  %buttonsHorizontal%, %buyCoord%, 1, 0
^F:: MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
^S:: MouseClick, Left, %buttonsHorizontal%, %sellCoord%, 1, 0
^ESC:: ExitApp
ESC:: Pause
^R:: trades = 0  ;Reset the trades
^T:: stopTimer = 0
^D:: delayFunction(86400,"Waiting") ; 86400 = 1 Day
^F1:: delayFunction(3600,"Pausing for 1 hour")
^F2:: delayFunction(7200,"Pausing for 2 hours")
^F4:: delayFunction(14400,"Pausing for 4 hours")
^0:: status = 0
^1:: status = 1
^2:: status = 2

ButtonStart:
;Main:
a := entryDelay
Toggle := !Toggle
While Toggle {
Sleep 10
    a++
    b++

    IniRead, HowManyIndicatorsVar, My TOS ALGO Settings.ini, Settings, HowManyIndicators, 3
    ;MsgBox, The value is %HowManyIndicatorsVar%.
    HowManyIndicators = %HowManyIndicatorsVar%
    IniRead, SingleShareVar, My TOS ALGO Settings.ini, Settings, SingleShare, 1
    ;MsgBox, The value is %SingleShareVar%.
    SingleShare = %SingleShareVar%


        if (SingleShare = 1){
            ;Maintain single share
            ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600, *20  *w70 *h26 Images\TwoBuy.tiff
                if (ErrorLevel = 0){
                status = 1
                    ;Correct and sell one back
                               MouseClick, Left, %buttonsHorizontal%, %sellCoord%, 1, 0
                    sleep 2000
                }
            ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600, *20  *w71 *h26 Images\TwoSell.tiff
                if (ErrorLevel = 0){
                status = 2
                    ;Correct and buy one back
                                MouseClick, Left, %buttonsHorizontal%, %buyCoord%,  1, 0
                    sleep 2000
                }
        }

        status = 1111 ;Reset for Loop
            ;Get status from TOS
            ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600, *20  *w71 *h26 Images\FlatPic.tiff
                if (ErrorLevel = 0){
                    status = 0
                    ;statusWord = Flat
                    Sleep 11
                }
            ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600, *20  *w59 *h26 Images\Positive.tiff
                if (ErrorLevel = 0){
                    status = 1
                    statusWord = Long
                    Sleep 11
                }
            ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600, *20  *w58 *h26 Images\Negative.tiff
                if (ErrorLevel = 0){
                    status = 2
                    statusWord = Short
                    Sleep 11
                }


        if (status = 0){ ;Flat! Look for indicators
                    sleep 11

            ;Three indicator and buy signal
            ImageSearch, FoundX, FoundY, 840, 180, 1111, 245, *20 *w20 *h20 images\BuyLabel.tiff
                if (ErrorLevel = 0){
                    UpBuySignal = 1
                }else{
                    UpBuySignal = 0
                }
                sleep 11

            ImageSearch, FoundX, FoundY, 0, 750, 400, 835, *20 *w15 *h15 images\LowerBuyLabel.tiff
                if (ErrorLevel = 0){
                    Lw1Bsignal = 1
                }else{
                    Lw1Bsignal = 0
                    }
                    sleep 11

            ImageSearch, FoundX, FoundY, 0, 835, 400, 920, *20 *w15 *h15 images\LowerBuyLabel.tiff
                if (ErrorLevel = 0){
                    Lw2Bsignal = 1
                }else{
                    Lw2Bsignal = 0
                    }
                    sleep 11

            ImageSearch, FoundX, FoundY, 0, 920, 400, 1000, *20 *w15 *h15 images\LowerBuyLabel.tiff
                if (ErrorLevel = 0){
                    Lw3Bsignal = 1
                }else{
                    Lw3Bsignal = 0
                }
                sleep 11


            if (HowManyIndicators == 3){
            BUYvalue := Lw1Bsignal+Lw2Bsignal+Lw3Bsignal
                ;MsgBox, % "Buy Total: " BUYvalue
            }
            if (HowManyIndicators == 2){
            BUYvalue := Lw2Bsignal+Lw3Bsignal
                ;MsgBox, % "Buy Total: " BUYvalue
            }
            if (HowManyIndicators == 1){
            BUYvalue := Lw3Bsignal
                ;MsgBox, % "Buy Total: " BUYvalue
            }
            if (HowManyIndicators == 0){
            BUYvalue := UpBuySignal
                ;MsgBox, % "Buy Total: " BUYvalue
            }

            GoLong = 0
            if (HowManyIndicators == 3 and BUYvalue == 3){
                GoLong = 1
            }
            if (HowManyIndicators == 2 and BUYvalue == 2){
                GoLong = 1
            }
            if (HowManyIndicators == 1 and BUYvalue == 1){
                GoLong = 1
            }
            if (HowManyIndicators == 0 and BUYvalue == 1){
                GoLong = 1
            }


            ;Three indicator and sell signal
            ImageSearch, FoundX, FoundY, 840, 180, 1111, 245, *20 *w20 *h20 images\SellLabel.tiff     
                if (ErrorLevel = 0){
                    UpSellSignal = 1
                }else{
                    UpSellSignal = 0
                }
                sleep 11

            ImageSearch, FoundX, FoundY, 0, 750, 400, 835, *20 *w15 *h15 images\LowerSellLabel.tiff
                if (ErrorLevel = 0){
                    Lw1Ssignal = 1
                }else{
                    Lw1Ssignal = 0
                }
                sleep 11

            ImageSearch, FoundX, FoundY, 0, 835, 400, 920, *20 *w15 *h15 images\LowerSellLabel.tiff
                if (ErrorLevel = 0){
                    Lw2Ssignal = 1
                }else{
                    Lw2Ssignal = 0
                }
                sleep 11

            ImageSearch, FoundX, FoundY, 0, 920, 400, 1000, *20 *w15 *h15 images\LowerSellLabel.tiff
                if (ErrorLevel = 0){
                    Lw3Ssignal = 1
                }else{
                    Lw3Ssignal = 0
                }
                sleep 11

            if (HowManyIndicators == 3){
            SELLvalue := Lw1Ssignal+Lw2Ssignal+Lw3Ssignal
                ;MsgBox, % "Sell Total: " SELLvalue
            }
            if (HowManyIndicators == 2){
            SELLvalue := Lw2Ssignal+Lw3Ssignal
                ;MsgBox, % "Sell Total: " SELLvalue
            }
            if (HowManyIndicators == 1){
            SELLvalue := Lw3Ssignal
                ;MsgBox, % "Sell Total: " SELLvalue
            }
            if (HowManyIndicators == 0){
            SELLvalue := UpSellSignal
                ;MsgBox, % "Sell Total: " SELLvalue
            }

            GoShort = 0
            if (HowManyIndicators == 3 and SELLvalue == 3){
                GoShort = 1
            }
            if (HowManyIndicators == 2 and SELLvalue == 2){
                GoShort = 1
            }
            if (HowManyIndicators == 1 and SELLvalue == 1){
                GoShort = 1
            }
            if (HowManyIndicators == 0 and SELLvalue == 1){
                GoShort = 1
            }

        
        
            statusWord = Flat (L%BUYvalue%|S%SELLvalue%)


            ;Evaluate and Go Long
            if (UpBuySignal == 1 and GoLong == 1 and a >= entryDelay) { ;goLong
                    if (entryPause > 0) {
                        k := entryPause
                        while (k > 0) {
                            ;tooltip Status: Delaying Entry: %k% Seconds, %statusCoord%, %buttonsHorizontal%
                            sleep 100
                            k--
                        }
                    }
                    ;Click Flatten Button
                    if (flatBeforeEntry > 0) {
                        MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
                    delayFunction(flatBeforeEntry, "Flat Before Next Entry")
                    }

                    ;Click Buy (Long)
                    MouseClick, Left, %buttonsHorizontal%, %buyCoord%,  1, 0
                
                    MouseMove,  1800, 175, 100

                    status = 1
                    statusWord = Long

                    a = 0
                    trades++
                    sleep delayTime * 100
            }

            ;Evaluate and Go Short
            if (UpSellSignal == 1 and GoShort == 1  and a >= entryDelay) { ;goShort
                    if (entryPause > 0) {
                        k := entryPause
                        while (k > 0) {
                            ;tooltip Status: Delaying Entry: %k% Seconds, %statusCoord%, %buttonsHorizontal%
                            sleep 100
                            k--
                        }
                    }
                    ;Click Flatten Button
                    if (flatBeforeEntry > 0) {
                        MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
                    delayFunction(flatBeforeEntry, "Flat Before Next Entry")
                    }
                
                    ;Click Sell (short)
                    MouseClick, Left, %buttonsHorizontal%, %sellCoord%,  1, 0
                
                    MouseMove,  1800, 175, 100

                    status = 2
                    statusWord = Short

                    a = 0
                    trades++
                    sleep delayTime * 100
            }
        }
    
        if (status = 1){ ;Long! Look for close
            ImageSearch, FoundX, FoundY, 840, 180, 1111, 245, *20 *w15 *h15 images\MagentaLabel.tiff
            if (ErrorLevel = 0){ ;Long Close     
                        ;Click Flatten Button
                        MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
                        MouseMove,  1800, 175, 100
                        status = 0
                    

                        sleep delayTime * 100
                        delayFunction(exitDelay, "Next Entry is Delayed")
            }
        }

        if (status = 2){ ;Short! Look for close
            ImageSearch, FoundX, FoundY, 840, 180, 1111, 245, *20 *w15 *h15 Images\LightGreenLabel.tiff
            if (ErrorLevel = 0){ ;Short Close
                        ;Click Flatten Button
                        MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
                        MouseMove,  1800, 175, 100
                        status = 0
                    

                        sleep delayTime * 100
                        delayFunction(exitDelay, "Next Entry is Delayed")
            }
        }

        if (status == 1111){ ;Cannot see TOS! Lost Connection?
            statusWord = !! No connection with TOS !!
            MsgBox, % "Cannot see TOS! Lost Connection? Status: " status
        }


    timeLeft := clearCounterPeriod - b
    entryTime := FormatSeconds(a)
    countdownTime := FormatSeconds(timeLeft)
    FormatTime, TimeString,, Time

    tooltip  Status: %status%-%statusWord% | Entry: %entryTime% | Trades: %trades% of %tradeLimit% | Count: %countDownTime% | Time: %TimeString%, %statusCoord%, %statusHorizontal%
     ;tooltip  Status: %statusWord%, %statusCoord%, %statusHorizontal%
    ;tooltip

    ;Gui, Font, S12, Verdana
    ;Gui, Add, Text, x4 y30 w599 h30 cffffff, Status: %statusWord% | Entry: %entryTime% | Trades: %trades% of %tradeLimit% | Count: %countDownTime% | Time: %TimeString%
    ;Gui, Add, Text, x5 y29 w500 h30 cffffff, Status: %statusWord%
    ;Gui, Add, Text, x175 y30 w499 h30 cffffff, Entry: %entryTime% | Trades: %trades% of %tradeLimit% | Count: %countDownTime% | Time: %TimeString%

    if (trades >= tradeLimit) {
        trades = 0
        ;Click Flatten Button
        MouseClick, Left, %buttonsHorizontal%, %flatCoord%, 1, 0
        sleep resetPeriod * 100
        j++

        if (j == 2 ) {
            tooltip Reset Count: %j% Time: %TimeString%, %statusCoord%, %statusHorizontal%
            exit
        }
    }
    if (b >= clearCounterPeriod) {
        b = 0
        trades = 0
    }

}
return



FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time := 19990101  ; *Midnight* of an arbitrary date.
    time += NumberOfSeconds, seconds
    FormatTime, mmss, %time%, mm:ss
    return NumberOfSeconds//3600 ":" mmss
    /*
    ; Unlike the method used above, this would not support more than 24 hours worth of seconds:
    FormatTime, hmmss, %time%, h:mm:ss
    return hmmss
    */
}

delayFunction(SecondsToWait, Message )
{
    k := SecondsToWait
    global stopTimer = 1
    global statusCoord
    global statusHorizontal
    while (k > 0)
    {
        if (stopTimer != 1) {
            break
        }
        timeLeft:= FormatSeconds(k)
        tooltip %Message%: %timeLeft%, %statusCoord%, %statusHorizontal%
        sleep 1000
        k--
    }
    stopTimer = 0
}

; CTRL - P to get PL popup
^p::
GetPL()
Return


GetPL()
{

;To setup uncomment the msg box. You only want the numbers no letters no symbols or the math wont work.

; P/L coordinates
x := 1705
y := 394
w := 40
h := 25
;MsgBox % OCR([x, y, w, h])

; B/S ? by ? coordinates
x1 := 1571
y1 := 365
w1 := 20
h1 := 30
;MsgBox % OCR([x1, y1, w1, h1])

        ;Get P/L Day
        PLDay := OCR([x, y, w, h])

        ;Get B/S for the day
        BSDay := OCR([x1, y1, w1, h1])

        StringTrimLeft, BSDay, BSDay, 2

        ;Fees
        CommissionsNFees = 6.2

        ;Math to get day Total of fees
        BSTotal := BSDay * CommissionsNFees

                ;msgbox, %BSTotal%

        ;Math to gey Net Profits
        PLTotal := PLDay - BSTotal

        ;Trim zeros
        StringTrimRight, PLTotal, PLTotal, 4

                    ;msgbox, %PLTotal%


MsgBox, 48, Net P/L Total:, Net Profit and Loss for the day: $%PLTotal%

}Return

Hi, thanks for generously sharing this AHK script. I have been reading back through the thread and wish to confirm this point:

in the original script by Kevin N, he was having TOS execute trades in paper mode and then copying those trades over to Tradovate.

In your version of the script, will it execute purely and directly with Tradovate as long as the below images and values are replaced with Tradovate equivalent screenshots and values?

[Images:]

TwoBuy.tiff,
TwoSell.tiff,
FlatPic.tiff,
Positive.tiff,
Negative.tiff

[Coordinates:]

P/L (x, y, w, h),
B/S (x1, y1, w1, h1),
buttonsHorizontal,
buyCoord,
sellCoord,
flatCoord,
statusHorizontal,
statusCoord

Or is simply replacing those images and values not going to make it execute with Tradovate unless this section is updated?

Code:
;Run, lib/TOS focus
    MouseClick, Left, 70, 200, 1, 0
    Sleep 10
    MouseClick, Left, 255, 62, 1, 0
    Sleep 10
    MouseClick, Left, 600, 85, 1, 0
    MouseMove,  1080, 111, 100

It's not clear to me what that is doing, i.e. if it's bringing the TOS window into focus, wouldn't that be redundant with the mouse clicks of the buy/sell/etc. buttons which bring it into focus anyway?

Whether or not that window focus code needs to be updated, is there anything else that has to be modified, other than what I have listed above, to make the script execute using Tradovate?

It would be a huge help if you can clarify these points. Thank you so much 🙏
 
Last edited:
Hi, thanks for generously sharing this AHK script.

It's not clear to me what that is doing, i.e. if it's bringing the TOS window into focus, wouldn't that be redundant with the mouse clicks of the buy/sell/etc. buttons which bring it into focus anyway?

Whether or not that window focus code needs to be updated, is there anything else that has to be modified, other than what I have listed above, to make the script execute using Tradovate?

It would be a huge help if you can clarify these points. Thank you so much 🙏

Sadly, @SilverWolf is no longer an active member of the forum
(to see who is active; click on their avatar)
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
466 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