#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, Pixel, Screen
;Declaration of variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Delay = 0
UpArrow = 0
DownArrow = 0
DoubleCheck = 0
PrevUpArrow = 0
PrevDownArrow = 0
Buy = 0
Sell = 0
OpenBuyOrder = 0
OpenSellOrder = 0
SixtyFour = 0
ThirtyTwo = 0
Sixteen = 0
Eight = 0
Four = 0
Two = 0
One = 0
Contracts = 0
Clock = 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;windows key + p to pause/unpause
#P::Pause
;windows key + z to start with no positions open
#Z::
;Main subroutine
;Determine current trade signal as to not enter a trade in progress/wait until trade signal changes
Main:
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\UpTrendLabel.tiff
If (ErrorLevel = 0)
{
OpenBuyOrder = 1
}
Else If (ErrorLevel = 1)
{
OpenBuyOrder = 0
}
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\DownTrendLabel.tiff
If (ErrorLevel = 0)
{
OpenSellOrder = 1
}
Else If (ErrorLevel = 1)
{
OpenSellOrder = 0
}
;Determine the amount of contracts to run(read from label code on screen lower chart)
Goto, ContractCalc
;Loop to check for change in trade signal
Check:
Loop{
;Check for TeamViewer logout screen and remove (Only needed if using TeamViewer to remote in)
ImageSearch, FoundX, FoundY, 0, 0, 1900, 1050, *w23 *h23 C:\Users\Home\Desktop\AutoHotKey Images\TVOK.tiff
If (ErrorLevel = 0)
{
;MouseMove, (FoundX-22), (FoundY+11)
MouseClick, Left, (FoundX-22), (FoundY+11), 1, 0
MouseClick, Left, (FoundX-22), (FoundY+11), 1, 0
Sleep,5000
MouseClick, Left, 875, 30, 1, 0
}
Else If (ErrorLevel = 1)
{
}
ImageSearch, FoundX, FoundY, 0, 0, 1900, 1050, *w38 *h22 C:\Users\Home\Desktop\AutoHotKey Images\OK2.tiff
If (ErrorLevel = 0)
{
;MouseMove, 300, -190
;MouseClick, Left, (FoundX-22), (FoundY+11), 1, 0
;MouseClick, Left, (FoundX-22), (FoundY+11), 1, 0
;Sleep,5000
MouseClick, Left, 300, -190, 1, 0
}
Else If (ErrorLevel = 1)
{
}
;Check for Buy Signal
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\UpTrendLabel.tiff
If (ErrorLevel = 0 and OpenBuyOrder = 0)
{
UpArrow = 1
If PrevUpArrow != %UpArrow%
{
DoubleCheck = 1
PrevUpArrow := UpArrow
}
}
Else If (ErrorLevel = 1)
{
OpenBuyOrder = 0
UpArrow = 0
If PrevUpArrow != %UpArrow%
{
DoubleCheck = 1
PrevUpArrow := UpArrow
}
}
;Check for Sell Signal
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\DownTrendLabel.tiff
If (ErrorLevel = 0 and OpenSellOrder = 0)
{
DownArrow = 1
If PrevDownArrow != %DownArrow%
{
DoubleCheck = 1
PrevDownArrow := DownArrow
}
}
Else If (ErrorLevel = 1)
{
OpenSellOrder = 0
DownArrow = 0
If PrevDownArrow != %DownArrow%
{
DoubleCheck = 1
PrevDownArrow := DownArrow
}
}
;ignore
;If DoubleCheck = 1
; {
; Sleep, Delay
; DoubleCheck = 0
; Goto, Check
; }
;Logic to determine what to do upon signal change
;If currently not in trade and trade signal is Sell
If (UpArrow = 0 and DownArrow = 1)
{
If (Buy = 0 and Sell = 0)
{
;Click Sell Button
;Keybind (currently disabled)
;Send +S
;Physical mouse click
MouseClick, Left, 1580, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;track current trade state
Buy = 0
Sell = 1
;Sleep, Delay
;confirm trade
Goto, Confirm
}
;If in long position and trade signal is Sell
Else If (Buy = 1 and Sell = 0)
{
;Click Flatten Button
MouseClick, Left, 1818, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;track current trade state
Buy = 0
Sell = 0
;wait for position to close
Goto, Wait
}
}
;If currently not in trade and trade signal is Buy
Else If (UpArrow = 1 and DownArrow = 0)
{
if (Buy = 0 and Sell = 0)
{
;Click Buy Button (disabled)
;Send +B
;physical mouse click
MouseClick, Left, 1495, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;track current trade state
Buy = 1
Sell = 0
;Sleep, Delay
;confirm trade
Goto,Confirm
}
;If in short position and trade signal is Buy
Else If (Buy = 0 and Sell = 1)
{
;Click Flatten Button
MouseClick, Left, 1818, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;track current trade state
Buy = 0
Sell = 0
;wait for position to close
Goto, Wait
}
}
;The rest of this module currently does nothing
;would be used to flatten all positions
Else If (UpArrow = 0 and DownArrow = 0)
{
If (Buy = 1 and Sell = 0)
{
;Click Sell Button
;Buy = 0
;Sell = 0
;Send +S
;MouseClick, Left, 1570, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Click Flatten Button
;MouseClick, Left, 1818, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Sleep, Delay
;Goto, Wait
}
Else If (Buy = 0 and Sell = 1)
{
;Click Buy Button
;Buy = 0
;Sell = 0
;Send +B
;MouseClick, Left, 1495, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Click Flatten Button
;MouseClick, Left, 1818, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Sleep, Delay
;Goto, Wait
}
}
Else If (UpArrow = 1 and DownArrow = 1)
{
If (Buy = 1 and Sell = 0)
{
;Click Sell Button
;Buy = 0
;Sell = 0
;Send +S
;MouseClick, Left, 1570, 135, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Sleep, Delay
;Goto, Main
}
Else If (Buy = 0 and Sell = 1)
{
;Click Buy Button
;Buy = 0
;Sell = 0
;Send +B
;MouseClick, Left, 1495, 135, 1, 0
;MouseClick, Left, 875, 30, 1, 0
;Sleep, Delay
;Goto, Main
}
}
}
Return
;#########################################################################################
;Wait for label indicating an open position to turn off
Wait:
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w8 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\PositionOpen.tiff
If (ErrorLevel = 0)
{
Goto, Wait
}
Else If (ErrorLevel = 1)
{
Goto, ContractCalc
}
;#########################################################################################
;Timer module
Clock:
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\Clock.tiff
If (ErrorLevel = 0)
{
Clock = 1
}
Else If (ErrorLevel = 1)
{
Clock = 0
}
Loop{
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w14 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\Clock.tiff
If (ErrorLevel = 0 and Clock = 0)
{
Goto, Check
}
Else If (ErrorLevel = 1 and Clock = 1)
{
Goto, Check
}
}Return
;#########################################################################################
;Confirmation module to check position is open after clicking Buy/Sell
Confirm:
Sleep, 3000
ImageSearch, FoundX, FoundY, 700, 0, 800, 200, *w8 *h17 *TransBlack C:\Users\Home\Desktop\AutoHotKey Images\PositionOpen.tiff
If (ErrorLevel = 0)
{
Goto, Clock
}
Else If (ErrorLevel = 1)
{
;Click Cancel Button
MouseClick, Left, 1660, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
Buy = 0
Sell = 0
Goto, Check
}
;#########################################################################################
;Calculate number of contracts to run (from onscreen label display)
#C::
ContractCalc:
Sleep,10
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\64.tiff
If (ErrorLevel = 0)
{
SixtyFour = 64
}
Else
{
SixtyFour = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\32.tiff
If (ErrorLevel = 0)
{
ThirtyTwo = 32
}
Else
{
ThirtyTwo = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\16.tiff
If (ErrorLevel = 0)
{
Sixteen = 16
}
Else
{
Sixteen = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\8.tiff
If (ErrorLevel = 0)
{
Eight = 8
}
Else
{
Eight = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\4.tiff
If (ErrorLevel = 0)
{
Four = 4
}
Else
{
Four = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\2.tiff
If (ErrorLevel = 0)
{
Two = 2
}
Else
{
Two = 0
}
ImageSearch, FoundX, FoundY, 0, 500, 125, 1000, *w8 *h17 C:\Users\Home\Desktop\AutoHotKey Images\1.tiff
If (ErrorLevel = 0)
{
One = 1
}
Else
{
One = 0
}
Contracts := SixtyFour + ThirtyTwo + Sixteen + Eight + Four + Two + One
;MsgBox, 0, , %Contracts%, 5
;move cursor to qty textbox
MouseClick, Left, 1510, 168, 1, 0
;delete current text in textbox
count = 0
Loop{
Send {Delete}
count := count + 1
sleep, 10
} Until count = 5
;input number of contracts to run
SendInput, %Contracts%
MouseClick, Left, 750, 250, 1, 0
MouseClick, Left, 875, 30, 1, 0
Goto, Check
;################################################################################################
;windows key + b if starting script while already in long trade
#B::
Buy = 1
;OpenBuyOrder = 1
Sell = 0
;OpenSellOrder = 0
Goto, ContractCalc
;#################################################################################################
;windows key + s if starting script while already in short trade
#S::
Buy = 0
;OpenBuyOrder = 0
Sell = 1
;OpenSellOrder = 1
Goto, ContractCalc