Conditional order to buy at new daily high


Category:
0
0

Hello Pete

Thanks for a quick response to my earlier question; I agree about the title to this post, its more clear now, here is my question.

I had an order to buy DQ at break of the high of the day in the paper trade account, but some how the order keep following the stock but it never get executed, its very strange, attached are the screen shots.

Below is the conditional order.

BUY +100 DQ MKT MARK WHEN DQ STUDY ‘close crosses above high ;1m’ IS TRUE

Thanks.

Attachments:
Marked as spam
Posted by (Questions: 9, Answers: 8)
Asked on May 22, 2018 5:34 pm
197 views
0
Private answer

Sorry to say this solution will not work with the conditional orders. This solution uses recursion, which is not permitted in the conditional orders (at this time). Please check the new answer I provided on 5/23/18.

This is really a great question. I can see how you would think the condition you created would do the trick. But there are some missing elements and I will explain everything.

First, let’s take a look at the code generated from your Conditional Order:

close crosses above high

And we can see that your Conditional Order is set to the 1 min time frame.

In English this is stating: “when the close of the current one min bar crosses above the high of the current one min bar”

That, is completely impossible. The close of the bar can never cross above the high of the same bar. They can be equal. But the close can never be above the high, of the same bar. So we need to add a bit to this code to get the current high of the day. And we need to do this so that we exclude the current bar. Because we only want this to be true when the close of the current bar has crossed above the “previous” daily high.

So we employ a few tricks that are compatible with the Conditional Order:

def newDay = GetDay() <> GetDay()[1];
rec highOfDay = if newDay then high else if high > highOfDay[1] then high else highOfDay[1];
plot trigger = close > highOfDay[1];

Line 1 checks the current day of each bar on the chart, and when the first bar of the day appears on the chart it equals true.

Line 2 is recursive and first checks if newDay is true and assigns the high of that bar. Next, it checks if the high of any given bar is higher than the previous value of highOfDay. So this variable always contains the highest high for the day up to that point.

Line 3 is the trigger. This checks that the close of the current bar is higher than the highOfDay of the previous bar. When this evaluates to true, you have the close crossing above the previous daily high.

Screenshot below shows what this looks like on a chart. So you can see exactly where and when the trigger is going to be true. Be sure to unchecked the Ext Hours box. Unless you want to include extended hours trade. If you do use extended hours trade, the premarket high can become the high of the day.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 22, 2018 6:16 pm
0

Hello Pete

I placed the conditional order on a stock, when I placed the condition, the OK button Is not working and it will not accept the condition, Attached is the order I placed.

Thanks.

( at May 23, 2018 10:10 am)
0

Right, terribly sorry about that. My error occurred to me as I was drifting off to sleep last night and by the morning it had completely left my mind. I will provide the next best solution in a new answer to the question.

( at May 23, 2018 10:21 am)
0
Private answer

Sorry that the first answer didn’t do the trick. (but it did explain why your attempt failed). The previous answer I provided works great for a chart or a scan but not for conditional orders. Which is a real bummer because that is a really slick way of doing it. The other bummer is that without using recursion, we have very little tools (in the code) that can get the job done. But do we need code at all?

Now that I look at this with a clear head. I can clearly see there is a very simple solution using standard order entry tools. There is no reason to try to do this using a conditional order. Because when you place the order, the previous daily high is clearly visible on the chart. So you simple enter a buy-stop order one tick above the previous daily high. Done.

Lesson: Sometimes we lost in the weeds trying to find a solution using the code, when a more appropriate tool is readily available.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 23, 2018 10:35 am
0

Ah so much for the Automation!!, They do have an API interface, but that’s too much for me, Thanks for the quick reply on this one.

( at May 25, 2018 7:53 pm)
0

Hello Pete,

I contacted their Scrip support and they come up with following script, but when i added this to conditional order its not working, any idea what might be causing the problem. ( each def statement start on a new line but somehow lines are not breaking and it all wrapped up in a paragraph)

Thanks.

Thanks for getting in touch with me. Below is an example script that I think accomplishes what you’re looking for. Please carefully review and test this script to be sure it’s working the way you want and expect it to and feel free to make any necessary adjustments.

#assumes no right expansion

def today = getyyyymmdd() == highestall(getyyyymmdd());
def excludecurrent = barnumber() < highestall(barnumber()); def conditionalhigh = if today and excludecurrent then high else double.nan; def condtodayhigh = highestall(conditionalhigh); plot data = high > condtodayhigh;

( at June 10, 2018 2:40 am)
0

Have you tried to plot it on a chart to see what it’s doing?

I still struggle with entire premise of your quest here. The issue is easily addressed by placing a buy stop order one tick above the previous day’s high. There is no need for a conditional order at all. Perhaps you can explain why this is needed?

I will say that the script you got from support has shown me a unique way of getting around the recursion limits. I will not forget this little trick.

( at June 10, 2018 8:14 am)