Auto Trade (ALGO) in TOS

@Svanoy is there anyway to make it where it can go back into a buy again if the label goes white? all my trades will have a stop loss, and when back testing sometimes i get stopped out on a few longs before hitting a good long trade.
 
@Svanoy Ok awesome, i'll try that. i was typing something but I noticed you edited your post? found a easier way to reset the buy label? Ok i'll look into that tomorrow. Thankyou for all your help. you will probley be hearing from me soon
 
@Svanoy @Kevin N I'm not sure what is wrong. when I start the script nothing happens. I have one of my labels green to signal a buy but it does nothing. no mouse movement or key strokes.. I have tried to mess with a few things but still no luck. i am using SciTE for my autohotkey. I tried changing my image files to .tiff, i tried to run SciTE and autohotkey in admin mode, removed the delays, etc
Code:
#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

;Key Combo to start script
;windows + s key
^9::

^0:: Pause


Loop{

;Watch for Buy Signal
ImageSearch, FoundX, FoundY, 25, 226, 239, 272, *w24 *h24 C:\Users\Home\Desktop\AutoHotKey Images\BuyLabel.png

;If found click mouse on random screen location, send ctrl + f key combo, send ctrl + b key combo.
    If (ErrorLevel = 0)
        {
        MouseClick, Left, 1747, 248, 1, 0
        delay = 10
        Send ^{f}
        delay = 10
        Send ^{b}
        }
;If not found do nothing
    Else If (ErrorLevel = 1)
        {
        }
;Watch for Sell Signal
ImageSearch, FoundX, FoundY, 25, 226, 239, 272, *w24 *h24 C:\Users\Home\Desktop\AutoHotKey Images\SellLabel.png

;If found click mouse on random screen location, send ctrl + f key combo, send ctrl + s key combo.
    If (ErrorLevel = 0)
        {
        MouseClick, Left, 1747, 248, 1, 0
        delay = 10
        Send ^{f}
        delay = 10
        Send ^{s}
        }
;If not found do nothing
    Else If (ErrorLevel = 1)
        {
        }

}Return
Not sure if this has been mentioned, but I have to run my AHK script as administrator (eg: right click on the AHK file and choose run as administrator). BMP files tend to work the best for me. Check my script, I had some code in there to stop spamming the buy button by forcing it to wait x seconds before another "buy" press was allowed.
 
Last edited:
@Svanoy Hello, "Use the else ErrorLevel =1 to flatten the trades and reset the variables"
The issue I see with this is when the label turns green and I enter a trade, after the next candle the label will go back to white. I don't want to flatten the trade. I only want to get out of a trade if my stop loss is hit or if the strategy flips. Instead of reversing the position I will just flatten and then buy/sell to make it easier. because if I get stopped out the flatten button really wont matter when entering a new trade. I'm using the flatten button to reverse a position or start a new long/short.
 
@Svanoy how do I write the code to make the label stay green? this is what I have "AddLabel(yes, "BUY ", if rsi[1] crosses above over_sold then Color.GREEN else Color.WHITE);"

I'm not sure this will work though because I have tos exit my trade on a stop loss and not autohotkey.
 
@aCuddlyTurtle Not to hijack the thread from Svanoy, but this is how I accomplished the task.

def LE = < Your Long Entry Condition >
def LX = < Your Long Exit Condition >
def SE = < Your Short Entry Condition >
def SX = < Your Short Exit Condition >

def Long;
if LE {
Long = 1;
} else if LX {
Long = 0;
} else {
Long = Long[1];
}

AddLabel(yes, if Long == 1 then "LE " else "LX ", if Long == 1 then Color.GREEN else Color.YELLOW);

def Short;
if SE == 1 {
Short = 1;
} else if SX {
Short = 0;
} else {
Short = Short[1];
}

AddLabel(yes, if Short == 1 then "SE " else "SX ", if Short == 1 then Color.BLUE else Color.RED);

Just coordinate label colors to reflect your AHK triggers.

I had to jump in as this issue created a ton of headaches for me when creating my system.
 
@Svanoy Here is a example of of 2 failed shorts and then a successful short. The way my code is setup now the bot would get into the first trade and then miss the other 2.
example2.png
 
@Jonessw1 Thanks Jones, I have it setup now to where my labels do work. but they only work if I buy then sell then buy then sell. I need it to be able to buy, buy, buy if needed. I need the code to reset when it sees a white label
 
I need the code to reset when it sees a white label
Then put a third Image Search in to find the white label and reset the buy sell variables in the script when found.
The drawback here is your buy condition could trigger again before your stop loss from the first trade. The label would turn green and AHK would try to buy again while you are still in the prior trade.

I recommend the answer by @Jonessw1 though. It is the same way I do it.
 
@Svanoy I'm not really sure how to make @Jonessw1 code work with my stop losses. that code would work sometimes like buy when rsi crosses then sell when rsi crosses. I would need to have in my code, def= sell when rsi crosses and then also a stoploss in my thinkscript.
 
@Svanoy "Then put a third Image Search in to find the white label and reset the buy sell variables in the script when found."
what would that look like? something like this? If (ErrorLevel = 0 and Sell = 0) but change the sell to a 1 or 0?

Im going to try to go this route for now and get it running good then i'll add the on inside tos.
 
Just a word (not to deter you at all!) - You will eventually see what you want, as any combination of trades/stop recognition is possible.
You just need a bit more experience with AHK.

Run on paper for a few weeks; watch your script and what the edits to your code do.
Try your combinations and see the results. I'm sure that we will be here to offer more support.
 
@Jonessw1 Thankyou, once it get it somewhat usable I plan to papertrade and just leave it running on a backup computer. I'm always open to ideas and suggestions. I'm going to add some of your code into my tos, thankyou, I appreciate you reaching out.
 

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