How to have specific stocks automatically buy once certain criteria is met


Category:
0
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
Posted by (Questions: 34, Answers: 56)
Asked on February 5, 2017 6:12 am
1203 views
0
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
Posted by (Questions: 34, Answers: 56)
Answered on February 5, 2017 6:16 am
0

I took care of the edit for you.

( at February 5, 2017 8:20 am)
0
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
Posted by (Questions: 37, Answers: 4118)
Answered on February 5, 2017 8:31 am
0

Thank you so much! I am very pleased how fast you responded to my question, thank you! I will be sure to watch your video. ?

( at February 5, 2017 9:25 am)
0
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:
Price close of 5 minute candle crosses above price (close) offset one of the one day. (Screenshot below)

close(“period” = AggregationPeriod.FIVE_MIN) crosses above close(“period” = AggregationPeriod.DAY) from 1 bars ago

 

 

Attachments:
Marked as spam
Posted by (Questions: 34, Answers: 56)
Answered on February 5, 2017 12:37 pm
0

I am away from my computer the rest of the day but will try to explain in a brief comment. The condition wizard has a fixed aggregation period. It is set on the screen behind the one shown in your screenshot. So there is no way to combine two time frames into the same condition. In your example, I see no difference between a five minute bar crossing above previous day’s high versus a daily candle crossing above the previous day’s high. But you may have further details yet to describe.

( at February 5, 2017 4:24 pm)
0

You know what… You’re right! BUT one thing that I would need is that the candle is green on the day. For example, Let’s say a stock closes at 2 and has a high of 2.50, then the next day the stock is gapping up in premarket up to 2.75 but when the market opens the stock sells off from 2.75 to 2.60. I can’t have that happen… I would need the stock to be green on the day, in this example, the stock would be red on the day because it opened at 2.75 and went down to 2.60… (Which I wouldn’t want to buy) Thanks!

( at February 5, 2017 6:39 pm)
0

Also, how would I make it so that when the price ON THE 5 MINUTE CANDLE closes below the 9 EMA? What should I put in the condition wizard?

( at February 5, 2017 7:37 pm)
0
Private answer

I'll work on a response to this Monday morning.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 5, 2017 7:46 pm
0
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:

rec trackDailyHigh = if high > high[1] then high else trackDailyHigh[1];
rec previousDailyHigh = if RegularTradingStart(GetYYYYMMDD()) <= GetTime() then trackDailyHigh[1] else previousDailyHigh[1];
plot test = previousDailyHigh;

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.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 6, 2017 12:07 pm
0

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! ?

( at February 6, 2017 6:31 pm)
0

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.

( at February 6, 2017 7:19 pm)
0

You’re the man, I can’t thank you enough, seriously!

( at February 6, 2017 8:09 pm)
0
I agree completely. Pete is amazing. Ive already given a $20 donation in appreciation. I definitely want him to keep doing this. I will give more when my automated trading starts making money for me.
( at March 5, 2017 3:22 pm)
0

Thank you, thank you, thank you. I very much appreciate your support!

( at March 5, 2017 5:11 pm)