Troubleshooting a problem with plots

Have a QScript to share, or need help with programming? Post your comment here.
Post Reply
kurthulse
Posts: 13
Joined: Tue Jul 21, 2015 9:16 pm
Contact:

Troubleshooting a problem with plots

Post by kurthulse » Sat Jun 16, 2018 12:11 am

I'm hoping someone (Earik?) can help me understand what's going wrong here. The following example script results in a line plotted only after barnumber = 9000. Nothing gets plotted before that bar. That doesn't seem right. Why does the calculation of vRSI (which is never plotted) affect whether a different variable gets plotted?

if (barnum == barsback) {
vPlot = 10;
vPlot_color = white;
vRSI = 50;
}

if (barnum < 9000) {
vRSI = 55;
} else {
vRSI = rsi(c, 20);
}

plot1 = vPlot; color1 = vPlot_color;
plot2 = 0; color2 = gray;
plot3 = 100; color3 = gray;

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

Re: Troubleshooting a problem with plots

Post by earik » Sun Jun 17, 2018 12:20 am

Hi Kurt,

W59 has an automatic reference bar adjustment feature. So if you were trying to plot a 100 period average, but your script was only set to reference bars of 40, then the script would launch once, fail, then re-launch itself with a larger reference bars setting. It's there to avoid scripts from not plotting when the only issue is that the reference bar setting needs to be adjusted. This includes all the reference bars setting for helper functions.

For whatever reason, you are managing to fake that test out. Since you don't call rsi until the 9000th bar, W59 incorrectly is waiting until there are 9000 bars available. That's obviously not correct, and this is blowing up on you... :?

The workaround is to move the function call outside that barnum < 9000 check. Do it like this, and it will work:

dummy = rsi(c, 20); # put the function call in a dummy variable, rather than inside the "else" block
if (barnum < 9000) {
vRSI = 55;
} else {
vRSI = dummy; # now just set vRSI to the variable, rather than the function
}

I should add that this way is better than the other one, because in the other one, the RSI value still is going to be incorrect from bars 9000 to 9050, since the RSI never had a chance to get past its own reference set since it was never called. W59 is probably seeing that, which is why it's not interested in plotting anything until those values are correct. Generally speaking, at least for indicator functions, you don't want to put them inside "if" clauses for this reason.

Regards,

Earik

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests