Auto Trade (ALGO) in TOS

I wanted to share my latest ahk algo script. To use this you will need to set all the coordinates and images files.

iQ0MvZR.png


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
 
@SilverWolf thanks for sharing the script is there any way you can just give me the entry time as a script
That code is remnant of @Kevin N script. He would have a much better grasp on how to make that a standalone script..

I have an idea though.. do you just want a log of when trades were taken? AHK has all kinds of ways to accomplish something like that. In your loop in the buy or sell statement you could have it write to a file with FileAppend.
CSS:
 FileAppend, Went long at %A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec%.`n, TradeLog.txt
 
Hey @NellyN , glad to help.. The Status Bar is the tooltip that shows the status, time, entry time, etc.. you can see it in the image there. Yes, it is very important that you use WindowSpy to modify coordinates of everything. That being said, if the script cannot see the "Pos Flat" or "Pos Short" or "Pos Long" the script doesnt know what TOS is doing. I use that to alert if the script can not see one of them. The msgbox is not necessary you can comment it out if you like or at least until you get the script seeing TOS. You can see in the status bar if the script is seeing it while you setup. You want to test each image to confirm good "connection" between the programs. I will attach examples of what I use. I suggest that you use Windows snipping tool and create your own as the color size and tint most likely is different on my computer.
xWInMys.png
9wEzAgS.png
ACW2d4o.png


The vis2ocr script is only used to get the profit and trades.. put that on a back burner until you get the buttons, connection images, and indicator locations set. Locating those numbers is a long process of trial and error.

The coordinates are in a set.. To help you visualize heres an Example: (ImageSearch, FoundX, FoundY, 1300, 125, 1900, 600,) the first two "1300, 125," are the top left corner of the rectangle that ahk will screenshot to look for your image. The "1900, 600," is the bottom right corner.

In the folder where the script is located an images folder is what its looking for. You can change that of course. The buy sell flat coordinates should be easy to set but you should organize your active trader to look like this:
9YXsvuB.png


You could always pin point their location if you dont want to rearrange your Active Trader.

I hope this helps :)
 

Attachments

  • xWInMys.png
    xWInMys.png
    810 bytes · Views: 586
  • 9wEzAgS.png
    9wEzAgS.png
    672 bytes · Views: 588
@SilverWolf are you lookingat 2 lower indicators with this one?
what do you mean by
twobuy.tiff,twosell.tiff
LowerBuyLabel.tiff LowerSellLabel.tiff
@Goingdark365 yes it can look at three lower indicators if you setup the coordinates.

The twobuy.tiff is this
tgx4Nij.png


In the settings you will see "singleShare" this is to ensure that i dont hold more than 1 share or contract. the script looks for that at the start of the loop and if it see two it will sell one back
 
Oh if you click the settings button it will ask to make a settings file in the script directory. This is to allow me to make a couple changes and not have to reload the script. after the ini file is created it should look like:

CSS:
[Settings]
HowManyIndicators = 3
SingleShare = 1

if there is no file or contents it will default to those values. You can see that in the loop where it says "IniRead"
 
Hallo Algo Traders, inspired by @dap711 I made my first simple auto trader with Macro Recorder. I found it easier since the script watches for specific color in order to activate itself. Here I attach my file with the Macro Recorder script. When the script sees lebel Buy it clicks Buy MKT button, lebel Sell - Sell MKT and Close-Flatten. I have one problem, the scripts clicks numerous time Buy or Sell when there is a signal. Please, help how to enter 1 time per direction. If you improve it, please share it here. The strategy may be any, it reads the colour of the labels. More useful info with label codes and nice made video explanation you may see here: https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/
P.S. I really like the last script written by @SilverWolf , but it is too complicated for an absolute beginner like me. May be he can make a video with very brief explanations of his code, logic and mainly chart positions of the labels, libraries, numbers in his GUI toolbar, etc.
Code:
"Mouse left click";"857, 17";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Go to label";"Buy";
"Mouse left click";"100, 167";
"Key Down";"Alt";
"Key press";"F";
"Key press";"B";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Sell";
"Mouse left click";"285, 167";
"Key Down";"Alt";
"Key press";"F";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Close";
"Mouse left click";"193, 167";
"Key Down";"Alt";
"Key press";"S";
"Wait";"5000 ms";
Does your strategy keep the label color the whole time or only on one bar?
 
There is only one label that we see at a time. Buy, Sell or Close. It distinguishes the color and clicks the Buttons. Very easy and simple, even for an absolute novice like me. For an experienced person like you it will be really easy and fast to make a clicker. To be honest one active bar per time looks for me more logical, we can not buy, sell or close simultaneously. This is my draft clicker as a file, a lot must be improved of course. https://drive.google.com/file/d/15TuKY7B_nbd0LRDuZgkA4Pm5ESFMhoRe/view?usp=sharing
Code:
# These are the orders and Labels from the strategy (I plan to use a different strategy, but keep the logic for the labels - one for an action)

input ShowAutoKeyLabels = yes; #(I use Macro Recorder to auto trade. Ask me about the setup at [email protected])

#Open the orders on the chart for back testing and optimizing the settings

AddOrder(OrderType.BUY_TO_OPEN, diff > diff[1] and low > MA and (if UseVolumeAsFilter then VolStrength>0 else yes) and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, "");
AddOrder(OrderType.SELL_TO_CLOSE, ( diff < diff[1] or close < MA ) and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN,Color.CYAN, "");
AddOrder(OrderType.SELL_TO_OPEN, diff < diff[1] and high < MA and (if UseVolumeAsFilter then VolStrength>0 else yes) and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,"");
AddOrder(OrderType.BUY_TO_CLOSE, ( diff > diff[1] or close > MA )  and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,"");

#Add the signal labels (use with Macro Recorder or not)
def OpenOrders = GetQuantity();
AddLabel(ShowAutoKeyLabels and diff[1] > diff[2] and low > MA and OpenOrders < 1 and (if UseVolumeAsFilter then VolStrength>0 else yes),  "     BUY      ", CreateColor(153, 255, 153));
AddLabel(ShowAutoKeyLabels and ( diff[1] < diff[2] or close < MA ) and OpenOrders > 0, "     CLOSE     ", CreateColor(102, 0, 0));
AddLabel(ShowAutoKeyLabels and diff[1] < diff[2] and high < MA and OpenOrders > -1 and (if UseVolumeAsFilter then VolStrength>0 else yes), "     SELL     ", CreateColor(255, 102, 102));
AddLabel(ShowAutoKeyLabels and ( diff[1] > diff[2] or close > MA ) and OpenOrders < 0 , "     CLOSE     ", CreateColor(102, 0, 0));
Hi All,

I've been giving it some thought (Lord help us!) .. and believe the labels should be static because they always remain in the foreground. I'm going to change my code to display the label in white until it receives a signal.
 
Hallo Algo Traders, inspired by @dap711 I made my first simple auto trader with Macro Recorder. I found it easier since the script watches for specific color in order to activate itself. Here I attach my file with the Macro Recorder script. When the script sees lebel Buy it clicks Buy MKT button, lebel Sell - Sell MKT and Close-Flatten. I have one problem, the scripts clicks numerous time Buy or Sell when there is a signal. Please, help how to enter 1 time per direction. If you improve it, please share it here. The strategy may be any, it reads the colour of the labels. More useful info with label codes and nice made video explanation you may see here: https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/
P.S. I really like the last script written by @SilverWolf , but it is too complicated for an absolute beginner like me. May be he can make a video with very brief explanations of his code, logic and mainly chart positions of the labels, libraries, numbers in his GUI toolbar, etc.
Code:
"Mouse left click";"857, 17";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Go to label";"Buy";
"Mouse left click";"100, 167";
"Key Down";"Alt";
"Key press";"F";
"Key press";"B";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Sell";
"Mouse left click";"285, 167";
"Key Down";"Alt";
"Key press";"F";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Close";
"Mouse left click";"193, 167";
"Key Down";"Alt";
"Key press";"S";
"Wait";"5000 ms";

@NellyN .. This is because you are trading paper. This won't happen when trading real money. My latest code in the ASAP strategy has a fix with a "Trading Paper" switch.
 
Hallo Algo Traders, inspired by @dap711 I made my first simple auto trader with Macro Recorder. I found it easier since the script watches for specific color in order to activate itself. Here I attach my file with the Macro Recorder script. When the script sees lebel Buy it clicks Buy MKT button, lebel Sell - Sell MKT and Close-Flatten. I have one problem, the scripts clicks numerous time Buy or Sell when there is a signal. Please, help how to enter 1 time per direction. If you improve it, please share it here. The strategy may be any, it reads the colour of the labels. More useful info with label codes and nice made video explanation you may see here: https://usethinkscript.com/threads/moving-average-master-strategy-for-thinkorswim.13975/
P.S. I really like the last script written by @SilverWolf , but it is too complicated for an absolute beginner like me. May be he can make a video with very brief explanations of his code, logic and mainly chart positions of the labels, libraries, numbers in his GUI toolbar, etc.
Code:
"Mouse left click";"857, 17";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Wait for pixel color";"29, 235";
"Go to label";"Buy";
"Mouse left click";"100, 167";
"Key Down";"Alt";
"Key press";"F";
"Key press";"B";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Sell";
"Mouse left click";"285, 167";
"Key Down";"Alt";
"Key press";"F";
"Key Up";"Alt";
"Wait";"5000 ms";
"Go to label";"Close";
"Mouse left click";"193, 167";
"Key Down";"Alt";
"Key press";"S";
"Wait";"5000 ms";

@NellyN .. I see an issue with your srcipt.

Key presses are not needed if you chose to mouse click on the Buy and Sell buttons. I have active trader hot keys turned on and like using them instead of mouse clicks. The key presses I have setup is to flatten "ALT-F" the trades before issuing a buy or sell. That way, I know that order is the only thing being traded.
 
Thanks a lot for your time helping me. Your idea with the Macro Recorder is wonderful. Here is the image of my last settings. The script works with mouse click, because I activated the Hot keys, but on simulation mode they did not work. The logic is simple, the script see the color of the label and clicks Buy, Sell or Flatten. After that the mouse moves back on top to wait for the next color(of the chart label). .


Looks much better! One thing .. it's not hurting anything, but you don't need to set focus to the app window after clicking the buttons. A mouse click on the buttons will do that for you. I set focus to the window in my script because I'm sending keystrokes.
 
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
Hi Gilgameash,

Do you happen to have any instructions on how to build bot like yours?
 
I was able to convert this code into python auto trading strategy over the weekend. I will test this week and will report back how good the results are. Even if they are half of what they are on TOS should be a profitable stragety.
Can you share any additional information How to do auto trading with TOS API and python,as it's not possible in TOS?.
 
Hi Gilgameash,

Do you happen to have any instructions on how to build bot like yours?
I might just post it here out of boredom... original post explained basic everything. And @NellyN is on the right track (though I'm not sure if the "flatten" option works on 'paper money' or 'OnDemand' for testing)

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




pointless update, running the bot on live account for this year trading 500 shares or AAPL with a 80% win rate (100k starting balance) and (116k this weeks closing balance with a Short position open),
might be posing strategy used in correct Forum later.
 
I might just post it here out of boredom... original post explained basic everything. And @NellyN is on the right track (though I'm not sure if the "flatten" option works on 'paper money' or 'OnDemand' for testing)






pointless update, running the bot on live account for this year trading 500 shares or AAPL with a 80% win rate (100k starting balance) and (116k this weeks closing balance with a Short position open),
might be posing strategy used in correct Forum later.

@Gilgameash I can see how you can help community by sharing your bot.
You would get help with testing and further feedback for making improvements.
It is your chance before someone else will come through.
I checked the pyautogui library. There is also a post on YouTube by some who had created similar bot.
Good luck. And thank you for sharing.
 

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
199 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