#Binary display of a number with labels
# Written by Svanoy
def size = 127; #This is the number being displayed with the labels
def onewhole = (RoundDown(size / 2, 0));
def oneremain = if (RoundDown(size / 2, 0)) - (size / 2) == 0 then 0 else 1;
def twowhole = (RoundDown(onewhole / 2, 0));
def tworemain = if (RoundDown(onewhole / 2, 0)) - (onewhole / 2) == 0 then 0 else 1;
def fourwhole = (RoundDown(twowhole / 2, 0));
def fourremain = if (RoundDown(twowhole / 2, 0)) - (twowhole / 2) == 0 then 0 else 1;
def eightwhole = (RoundDown(fourwhole / 2, 0));
def eightremain = if (RoundDown(fourwhole / 2, 0)) - (fourwhole / 2) == 0 then 0 else 1;
def sixteenwhole = (RoundDown(eightwhole / 2, 0));
def sixteenremain = if (RoundDown(eightwhole / 2, 0)) - (eightwhole / 2) == 0 then 0 else 1;
def thritytwowhole = (RoundDown(sixteenwhole / 2, 0));
def thirtytworemain = if (RoundDown(sixteenwhole / 2, 0)) - (sixteenwhole / 2) == 0 then 0 else 1;
def sixtyfourwhole = (RoundDown(thritytwowhole / 2, 0));
def sixtyfourremain = if (RoundDown(thritytwowhole / 2, 0)) - (thritytwowhole / 2) == 0 then 0 else 1;
addlabel(yes, " ", If sixtyfourremain == 1 then color.LIGHT_GREEN else color.BLACK );
addlabel(yes, " ", If thirtytworemain == 1 then color.LIME else color.BLACK );
addlabel(yes, " ", If sixteenremain == 1 then color.CYAN else color.BLACK );
addlabel(yes, " ", If eightremain == 1 then color.MAGENTA else color.BLACK );
addlabel(yes, " ", If fourremain == 1 then color.PINK else color.BLACK );
addlabel(yes, " ", If tworemain == 1 then color.PLUM else color.BLACK );
addlabel(yes, " ", If oneremain == 1 then color.YELLOW else color.BLACK );
addlabel(yes, "# of contracts available to run: " + size, color.WHITE);
addlabel(yes, "Current # of contracts running: " + getquantity(),color.WHITE);
#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
Delay = 30000
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
#P:: Pause
#Z::
Goto, ContractCalc
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
}
Check:
Loop{
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)
{
}
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
}
}
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
}
}
If DoubleCheck = 1
{
;Sleep, Delay
DoubleCheck = 0
Goto, Check
}
If (UpArrow = 0 and DownArrow = 1)
{
If (Buy = 0 and Sell = 0)
{
;Click Sell Button
;Send +S
MouseClick, Left, 1580, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
Buy = 0
Sell = 1
;Sleep, Delay
}
Else If (Buy = 1 and Sell = 0)
{
;Click Flatten Button
MouseClick, Left, 1818, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;Click Sell Button
;MouseClick, Left, 1580, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
Buy = 0
Sell = 0
Goto, Wait
}
}
Else If (UpArrow = 1 and DownArrow = 0)
{
if (Buy = 0 and Sell = 0)
{
;Click Buy Button
;Send +B
MouseClick, Left, 1495, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
Buy = 1
Sell = 0
;Sleep, Delay
}
Else If (Buy = 0 and Sell = 1)
{
;Click Flatten Button
MouseClick, Left, 1818, 125, 1, 0
MouseClick, Left, 875, 30, 1, 0
;Click Buy Button
;MouseClick, Left, 1495, 125, 1, 0
;MouseClick, Left, 875, 30, 1, 0
Buy = 0
Sell = 0
Goto, Wait
}
}
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, ContractCalc
}
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, ContractCalc
}
}
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:
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
}
;#########################################################################################
#C::
ContractCalc:
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
MouseClick, Left, 1510, 168, 1, 0
count = 0
Loop{
Send {Delete}
count := count + 1
sleep, 10
} Until count = 5
SendInput, %Contracts%
MouseClick, Left, 750, 250, 1, 0
MouseClick, Left, 875, 30, 1, 0
Goto, Check
;################################################################################################
#B::
Buy = 1
Sell = 0
Goto, ContractCalc
;#################################################################################################
#S::
Buy = 0
Sell = 1
Goto, ContractCalc
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Outside Auto-Trading Solutions for Thinkorswim | Playground | 4 | ||
P | Auto entering password | Playground | 0 | |
R | ToS Trade Button script? | Playground | 5 | |
M | Trade Algo | Playground | 2 | |
M | Daily Watchlist of Stocks to Day Trade Weekly Options For ThinkOrSwim | Playground | 999 |
Start a new thread and receive assistance from our community.
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.
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.