Don't execute the run() function on the current incomplete bar?

Posted By: Tamas

Don't execute the run() function on the current incomplete bar? - 11/17/20 17:09

Hi,

I tested a simple Zorro provided workshop script (workshop5) with the following added line in the run() function:

printf("\nBar %i of %i at %s",Bar,NumBars,strdate("%Y-%m-%d %H:%M",wdateBar(Bar)));

In Trade mode, it prints all the way to the last current bar, including the incomplete one, then it waits for that bar to complete:

The Zorro manual says in the Trade mode this:
"After the lookback period, Zorro will wait for the end of the current bar (unless StartDate is set to NOW), then execute the run function again."

This is indeed happening, the last current incomplete bar is run() again once it ends.

My problem is that I have a calculation in the run() function which creates a series and on the last bar the run() function is run twice, once when I start the script in Trade mode and when the bar is still incomplete and once more when the bar actually ends.

Is there a way to run the run() function only when the bar is complete? Running it twice screws up the series my script is creating by adding an additional value to it.

Thanks!

Tamas
Posted By: Tamas

Re: Don't execute the run() function on the current incomplete bar? - 11/17/20 17:56

Here is the example, the BarPeriod is set to 5 mins to test the workshop5 script and StartDate set to 20201101, EndDate commented out.

As you can see after starting the script in Trade mode at 2020-11-17 at 17:48 (not shown on the screenshot), the last run() at bar 747 (which ends at 2020-11-17 17:50) was also run on the incomplete last bar.

At 17:50, the run() function was run again and it printed the same bar which is now complete.

So is there a way to avoid running the run() function on incomplete bars?

Thanks!
I hope I am not missing something here, but it is strange that when the script is started in Trade mode, the run() functions runs twice on the last bar, when it's incomplete and when it's complete.

Attached picture Screenshot 2020-11-17 at 17.50.37.png
Posted By: jcl

Re: Don't execute the run() function on the current incomplete bar? - 11/19/20 07:41

This can happen when the lookback period ends with an incomplete bar. The bars are no duplicates, they have different prices and if you would suppress one of them, the series weren't 100% correct either. But you can use the NOSHIFT flag of the current beta version for this.
© 2024 lite-C Forums