; Version Beta .07 - Last Modified: 11-14-22 09:18 - 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]
CoordMode, ToolTip, Screen
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
; CheapWindowsVPS_10
; User Defineable variables
; Use the following to set the vertical and horizontal coordinates for each.
buttonsHorizontal = 130 ; Horizontal Coordinates, this will be the same for buy, flat, sell.
buyCoord = 75 ; Vertical Coordinates, middle of button
flatCoord = 150 ; Vertical Coordinates, middle of button
sellCoord = 240 ; Vertical Coordinates, middle of button
statusHorizontal = 125 ; The horizontal setting for the status bar
statusCoord = 320 ; The vertical setting for the status bar
labelSearchX = 275 ; How far to the right to search for the buy/sell label
labelSearchY = 275 ; How far down to search for the buy/sell label
tradeLimit = 5 ; 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 = 0 ; 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.
; - this is used to make sure we're flat before hitting the buy or sell entries buttons.
useTradovate = 0 ; default is 1 (on), off is 0 (zero)
tradoBuyCoord = 900 ; Vertical Coordinates, middle of button
tradoFlatCoord = 1010 ; Vertical Coordinates, middle of button
tradoSellCoord = 1135 ; Vertical Coordinates, middle of button
tradoAlignH = 233 ; Alignment tool, this will be your horizontal setting for buy/Exit/Sell buttons.
tradoAlginV = 1140 ; Alignment tool, this should align to the right of all your buttons.
tradoAlignT = 0 ; 1 - yes, 0 - no, Use/display Align Tool
; End user defineable
status = 0
trades = 0
stopTimer = 0
tosErrors = 0
^B:: MouseClick, Left, %buyCoord%, %buttonsHorizontal%, 1, 0
^F:: MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
^S:: MouseClick, Left, %sellCoord%, %buttonsHorizontal%, 1, 0
^P:: Pause
^E:: checkForErrors()
^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 ; use this and the next two below to adjust trade status, 0 = Flat
^1:: status = 1 ; 1 = We are long
^2:: status = 2 ; 2 = We are short;
esc::
Main:
sleep 1000
a := entryDelay
;checkForErrors()
loop {
sleep 1000
a++
b++
if (status != 1 and a >= entryDelay or status == 2 and a >= entryDelay) {
ImageSearch, FoundX, FoundY, 0, 0, %labelSearchX%, %labelSearchY%, *w50 *h15 *10 images\white.png
if (ErrorLevel = 0) {
if (entryPause > 0) {
k := entryPause
while (k > 0) {
tooltip Status: Delaying Entry: %k% Seconds, %statusCoord%, %buttonsHorizontal%
sleep 1000
k--
}
}
;Click Flatten Button
if (flatBeforeEntry > 0) {
MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
;TradoVate ------------
if (useTradovate == 1) {
MouseClick, Left, %tradoFlatCoord%, %tradoAlignH%, 1, 0
}
delayFunction(flatBeforeEntry, "Flat Before Next Entry")
}
;Click Buy Button if green status and we're not already in a trade
MouseClick, Left, %buyCoord%, %buttonsHorizontal%, 1, 0
;TradoVate ------------
if (useTradovate == 1) {
MouseClick, Left, %tradoBuyCoord%, %tradoAlignH%, 1, 0
}
status = 1
a = 0
trades++
tooltip Status: Buy Image Cords: %FoundX% x %FoundY%, %statusCoord%, %buttonsHorizontal%
sleep delayTime * 1000
;checkForErrors()
}
}
if (status != 0) {
ImageSearch, FoundX, FoundY, 0, 0, %labelSearchX%, %labelSearchY%, *w50 *h15 *10 images\blue.png
if (ErrorLevel = 0) {
;Click Flatten Button
MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
;TradoVate ------------
if (useTradovate == 1) {
MouseClick, Left, %tradoFlatCoord%, %tradoAlignH%, 1, 0
}
delayFunction(15, "Waiting to hit the flat button again")
; Lets hit the flat button again, to be sure after delay above
if (useTradovate == 1) {
MouseClick, Left, %tradoFlatCoord%, %tradoAlignH%, 1, 0
}
;Click Flatten Button
; Let's hit TOS flat once more
MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
status = 0
tooltip Status: Flat Image Cords: %FoundX% x %FoundY%, %statusCoord%, %statusHorizontal%
sleep delayTime * 1000
;checkForErrors()
delayFunction(exitDelay, "Next Entry is Delayed")
}
}
if (status != 2 and a >= entryDelay or status == 1 and a >= entryDelay) {
ImageSearch, FoundX, FoundY, 0, 0, %labelSearchX%, %labelSearchY%, *w50 *h15 *10 images\dark_orange.png
if (ErrorLevel = 0) {
if (entryPause > 0) {
k := entryPause
while (k > 0) {
tooltip Status: Delaying Entry: %k% Seconds, %statusCoord%, %buttonsHorizontal%
sleep 1000
k--
}
}
;Click Flatten Button
if (flatBeforeEntry > 0) {
MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
;TradoVate ------------
if (useTradovate == 1) {
MouseClick, Left, %tradoFlatCoord%, %tradoAlignH%, 1, 0
}
delayFunction(flatBeforeEntry, "Flat Before Next Entry")
}
;Click Sell (short)
MouseClick, Left, %sellCoord%, %buttonsHorizontal%, 1, 0
;TradoVate -------------
if (useTradovate == 1) {
MouseClick, Left, %tradoSellCoord%, %tradoAlignH%, 1, 0
}
status = 2
a = 0
trades++
tooltip Status: Short Image Cords: %FoundX% x %FoundY%, %statusCoord%, %statusHorizontal%
sleep delayTime * 1000
;checkForErrors()
}
}
timeLeft := clearCounterPeriod - b
entryTime := FormatSeconds(a)
countdownTime := FormatSeconds(timeLeft)
FormatTime, TimeString,, Time
;tooltip Status: %status% Trades: %trades% Count: %TimeLeft% Entry: %a% Time: %TimeString%, %statusCoord%, %statusHorizontal%
tooltip Status: %status% | Trades: %trades% of %tradeLimit% | Count: %countDownTime% | Entry: %entryTime% | Time: %TimeString% | Errors: %tosErrors%, %statusCoord%, %statusHorizontal%
; Tradovate
if (tradoAlignT == 1) {
tooltip "<----", %tradoAlignV%, %tradoAlignH%, 2
}
if (trades >= tradeLimit) {
trades = 0
;Click Flatten Button
MouseClick, Left, %flatCoord%, %buttonsHorizontal%, 1, 0
sleep resetPeriod * 1000
j++
if (j == 2 ) {
tooltip Reset Count: %j% Time: %TimeString%, %statusCoord%, %statusHorizontal%
exit
}
}
if (b >= clearCounterPeriod) {
b = 0
trades = 0
checkForErrors()
}
}
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
}
checkForErrors()
{
global statusCoord
global statusHorizontal
global tosErrors
tosHorizontal := statusHorizontal - 30
tooltip Errors: %tosErrors% | %FoundX% x %FoundY%, %statusCoord%, %tosHorizontal%
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *50 images\tosWarningOK.bmp
if (ErrorLevel = 0) {
;Clear the TOS Performance Issue Message
FoundX:=FoundX+5, FoundY:=FoundY+5
MouseClick, Left, %FoundX%, %FoundY%, 1, 0
tosErrors++
tooltip OK Warnings Cleared: %tosErrors% | %FoundX% x %FoundY%, %statusCoord%, %tosHorizontal%
}
ImageSearch, FoundX, FoundY, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, *140 images\tosWarningContinue.png
if (ErrorLevel = 0) {
;Clear the TOS Order Submit Error Message
FoundX:=FoundX+10, FoundY:=FoundY+10
MouseClick, Left, %FoundX%, %FoundY%, 1, 0
tosErrors++
tooltip CONTINUE Warnings Cleared: %tosErrors% | %FoundX% x %FoundY%, %statusCoord%, %tosHorizontal%
}
; Lets mouse click top left to clear this weird drop down menu error I've received many times
MouseClick, Left, 5, 5, 1, 0
return
}