Make a run() at the end of the first bar even if StartDate = NOW

Posted By: NorbertSz

Make a run() at the end of the first bar even if StartDate = NOW - 01/24/22 15:16

Hello!

I have a script that I want to run immediately at start, and also when the bars finished - even the first one!
If I do this:
Code
StartDate = NOW;

the code will run immediately, but won't run again at the end of the first bar.

My solution is this:

Code
bool runStuff = false;
int runCounter = 0;

...

function run(){

	if (is(LOOKBACK)){
		runCounter++;
	}
	if (runCounter >= LookBack){
		runStuff = true;
	}

	if (runStuff){
		//...run the stuff
	}
}


Is there a more elegant way for doing an immediate run and also a normal run? Maybe a flag for it, like
Code
is(LASTLOOKBACK)

or something like this?

So runstuff would be just this:
Code
if (!is(LOOKBACK) || (is(LASTLOOKBACK)){
	//...run the stuff
}


Thank you!
Posted By: NorbertSz

Re: Make a run() at the end of the first bar even if StartDate = NOW - 01/24/22 15:38

Now I see that it's not a good solution, because in the last LookBack run, the last finished bar not yet exists for Zorro.
How can I force the script to run immediately, and run again normally when a bar finished?
© 2024 lite-C Forums