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); }}
plotting the open
Re: plotting the open
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
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
Re: plotting the open
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
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
Re: plotting the open
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
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
Re: plotting the open
Earik,
Ahh, excellent, adding -1 to bars_per_day did the trick. Onward...
Thanks!
Todd
Ahh, excellent, adding -1 to bars_per_day did the trick. Onward...
Thanks!
Todd
Who is online
Users browsing this forum: No registered users and 27 guests