Attached is a copy of the file used to produce the subsequent charts. I used April 1st $indu on a 1 minute time frame on $playback. The min/max scale is set for the range needed at 11AM so if you replay just let the chart pass the first hour and the lines will come back into scale. The line movement is noticeable just before 11am, 12:30 and 13:30.
1. All of your drawLine calls need to be inside a check for BARSTATE_NEWBAR. You'll actually need two drawLine calls for Basis1. Just before the NEWBAR routine with all the drawLine calls you'll do a drawLine for Basis1 where point A is the close(0) ( or your eventual second external calc) on bar 0 and B is vReturn on bar -1. This duplicates the Basis1 segment in real time.
The Basis1 drawLine inside the NEWBAR routine will redraw the line from point A, which will be close(0) on bar 0 to vReturn on bar -1. This is a bit confusing. The key is to remember that at NEWBAR we're setting bar -1 to the value of vReturn. So your drawLine lines need to reflect the same action as what setBar does to the indicator line.
Then Basis2 will be drawn from vReturn1 on bar -1 to aMyArray1[0] on bar -2. Basis3 will be drawn from aMyArray1[0] on bar -2 to aMyArray1[1] on bar -3. The rest of the lines use the next two elements of the array and their respective bars.
2. vReturn1 = (vReturn+5) needs to be inside the BARSTATE_NEWBAR routine just before the drawLine calls. By doing this outside the NEWBAR routine, the line gets out of wack because vReturn1 needs to store the last value of vReturn from the previous bar. In real time, you were allowing vReturn1 to get set the the current bar's value of vReturn. That's why the line realigns after a reload. When a formula is reloading it only executes once per bar, which eliminates the need for the NEWBAR routine. But as you can see now, you need to incorporate this to handle real time data where there are multiple executions of the formula during the bar.
3. Delete the line: aMyArray1[0] = vReturn1. It's not needed. Your pop/unshift routine takes care of updating the array.
Jason K.
Project Manager eSignal - an Interactive Data company
I have included your suggestions into the attached code. The following charts show the old code you reviewed on top and the attached code on the bottom. We are getting close but the lines remain different. The second chart is after a reload and both setbar blue lines move and change shape after the reload.
The instructions from #1 weren't completely incorporated into your code. I made the corrections for you. Take a look at the attached code to see what the differences were. By the way, I took the +5 logic out so that the drawline line overlaps the indicator line. I think it's easier to see that way, but feel free to add that back in.
Thank you for all the time you have invested during the last 9 days. The code works great! The changes are subtle and I have learned a lot from this effort.
Comment