♥ 0 |
I need to have orders execute once stocks from my watchlist meet certain conditions for the day. Buy when: Stock price is above yesterday’s high and the current 5-minute candle is green. Sell (the stock we just bought) when: The current 5-minute candle closes below the 9 exponential moving average. )
Marked as spam
|
Private answer
In response to the follow-up comments I will add the following details. To the question about refining the buy condition to make sure prices are coming up and crossing above the previous day’s high. You would need to do this on an intraday time frame, so we’ll take the 5 min as per your example. Since we cannot reference the daily time frame from the 5 min time frame, we need to use recursion to record and retain that value into the next day. Here is the code that works on any intraday time frame to record the highest high from the pervious day and carry that value into the next trading day:
The problem we run into is that recursion is not supported in Conditional Orders or Study Alerts. You can only use this in Watchlists, Scans, and Chart Studies. There is no work around. You will not be able to code your buy condition into the conditional order editor. Go head and copy and paste this and check out the error messages. Ok, so now on to your exit condition. At least we may be able to automate the exits. That all depends on that 9 period EMA you are using. You ask for a way to code a condition for when the 5 min candle crosses below the “9 EMA”. Is that the 9 period EMA on the 5 minutes time frame? Or is the 9 period EMA using some other time frame? If it is using the 5 min time frame, then you can build this directly in condition wizard. See screenshot below for details. Marked as spam
|
|||||||
Private answer
I'll work on a response to this Monday morning. Marked as spam
|
|||||||
Private answer
I am having trouble… It won’t let me press ok in the condition wizard, it keeps saying “Secondary period cannot be less than primary.” I put: close(“period” = AggregationPeriod.FIVE_MIN) crosses above close(“period” = AggregationPeriod.DAY) from 1 bars ago
Marked as spam
|
|||||||
Private answer
The tool we can use in Thinkorswim to automatically execute trades is called a “Conditional Order”. The techniques for using this are explained in great detail in our video titled “Thinkorswim AutoTrade Almost“. Your specifications are relatively simple to implement and you should be able to build it yourself using the condition wizard (no code writing required). The part of your specification that cannot be achieved on the Thinkorswim platform is to have a set of rules apply to a list of stocks. The rules must be manually applied to each individual stock, applying the Conditional Order to each. You can set them to automatically regenerate after being triggered. After viewing the video, spend some time practicing until you become familiar with the tools. If you still need assistance building the condition statement to match your specifications just leave a comment to this answer and we’ll post something for you. Marked as spam
|
|||||||
Private answer
I don’t know what the heck happened there and it won’t let me edit it, “curr5-minutenute.” Lol. I just meant 5-minute. Marked as spam
|
Please log in to post questions.
First of all, thank you very very very much!
Man… There is no way to get my buying strategy to automate… Damn ?
For my selling strategy, Yes, I am talking about the 9 EMA on the 5 min time frame. I don’t want it so that when the 5-minute candle crosses the 9 EMA it’s a sell order, I want it so when the 5-minute candle CLOSES below the 9 EMA its a sell order.
Thank you! ?
Ok, so you need the check if the bar that has most recently closed has crossed and close below the 9 period EMA. Simply adjust the Offset on the left side of the condition wizard to +1 and it will look back at the previous bar to see if it has crossed below and closed below the 9 period EMA.
You’re the man, I can’t thank you enough, seriously!
Thank you, thank you, thank you. I very much appreciate your support!