plotting the open

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
abacaba
Posts: 144
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

plotting the open

Post by abacaba » Tue Sep 27, 2016 12:07 am

I'm building a script that will do calculations on the O,C,H,L for the daily RTH and 24 hr time frames. Everything is fine, except the following code will not return the open. It returns the open of the last bar of the day instead. No problem with H,L,C. I'm stuck at this point. Any suggestions will be greatly appreciated. Changing the day offset will plot the open, but that produces other problems with H,L,C.

Thanks in advance.

Todd

Input: OH_color(blue),thick(1);
IF (barnum == barsback)
{
startbar,endbar=barnum;
bpd= bars_per_day;
}
IF (day[-1]!= day )
{
myclose=close;myhigh=high;mylow=low;myopen=open;
startbar=barnum+1;endbar=barnum+bpd-1;
For (i=1 to bpd-1 by 1)
{
if (low<mylow)mylow=low;
if (high>myhigh)myhigh=high;
}
OH=myopen;
}
If (OH!=0)
{
If ((startbar>=10) and (endbar>startbar) )
{
ref1=trendline(startbar,OH,endbar,OH,OH_color); }}

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: plotting the open

Post by earik » Tue Sep 27, 2016 5:25 pm

Hi Todd,

You may have to write it differently for daily and intraday time frames. Judging by the loop you've got in there to figure out the high and low, this one would seem to be the intraday version. Your loop gets triggered when (day[-1] != day), which is the final bar of the intraday session. To figure out the open, you need to get the opening of a bar that has passed, rather than the bar that you're on right then. There's a "bars_per_day" keyword that will return the number of bars in a given day which makes this pretty easy. So try setting myopen = open[bars_per_day], rather than myopen = open, and see if that cleans it up.

Regards,

Earik

abacaba
Posts: 144
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

Re: plotting the open

Post by abacaba » Thu Sep 29, 2016 1:04 am

Earik,

Thanks for the suggestion. Is this what you mean (in bold)?

Input: OH_color(blue),thick(1);
IF (barnum == barsback)
{
startbar,endbar=barnum;
bpd= bars_per_day;
}
IF (day[-1]!= day )
{
myclose=close;myhigh=high;mylow=low;myopen=open[bars_per_day];
startbar=barnum+1;endbar=barnum+bpd-1;
For (i=-1 to bpd-1 by 1)
{
if (low<mylow)mylow=low;
if (high>myhigh)myhigh=high;
}
OH=myopen;
}
If ((startbar>=10) and (endbar>startbar) ) {
ref2=trendline(startbar,OH,endbar,OH,OH_color); }

Not sure, but the open of the day will still not plot on the next day time frame, which is not a problem with L,H,C. I should have mentioned this in the original post -- the idea is to derive SR levels for the current day from the previous days' O,H,L,C.

Todd

Todd

User avatar
earik
Site Admin
Posts: 474
Joined: Mon Dec 01, 2014 12:41 pm
Contact:

Re: plotting the open

Post by earik » Fri Sep 30, 2016 5:25 pm

Hi Todd,

Yes, that's what I meant. You actually might need to do bars_per_day - 1 to get the right bar. This still doesn't show the correct value? Does it show any value at all? And the exact same script works when you replace the OH = myopen assignment with some other variable?

Earik

abacaba
Posts: 144
Joined: Sat Aug 15, 2015 5:02 pm
Contact:

Re: plotting the open

Post by abacaba » Sat Oct 01, 2016 7:18 pm

Earik,

Ahh, excellent, adding -1 to bars_per_day did the trick. Onward...

Thanks!

Todd

Post Reply

Who is online

Users browsing this forum: No registered users and 83 guests