I am trying a way to continously monitor a bar for certain conditions and then executing a trade once that condition has occured. Unfortunately i cannot find examples of how to implement/facilitate this without either freezing up sierra due to what i can only assume is a massive amount of memory leaks caused by a self repeating while loop.
But if you have autoloop=1 on, then basically once you reach the end of the code it ends and essentially reboots when there is a function call (a new bar opening, current bar closing etc). So if you use an if statement and the conditions are not met then that trade is never going to be executed from what i understand, even if the conditions are met lateron while the bar is forming.
To the point:
This is essentially what i need to happen but this leads to memory leaks.
Now if you try this
It actually works but not in the way youd expect them to.
To be more specific i am dealing with Flexrenkos here, and if you use larger settings like 32-31-30 for ES or YM then obviously those retracebars (long wick bars) can last forever, to see what i mean you can look at Outlanders Flexrenko Day Trading Thread.
So what i need is some form of loop that checks whether or not the bar has not closed yet that will not lead to sierra freezing.
I'm open to suggestions or pointers towards ACSIL member functions i should be using.
It evaluates in real time by default, you don't have to tell it to do that. Autoloop should equal 1 unless you are controlling the indexing, which it doesn't appear you are. Also, there is a tradingsystem.cpp file you can look at that has a bunch of examples in it.
setting autoloop = 1 means that for every function call (new bar) the code will be repeated. This doesnt change the fact that if you have something along the lines of the crossover example in an if statement for executing a trade that it should not be executed if the conditions are not met.
If the If statement is not executed then the program ends at that point and has to wait being reloaded once a new bar pops up.
So this is why i thought about using a while loop, because a while loop will not terminate until the condition stops being true, this way you can do stuff like execute trades and monitor the bar while it has not closed yet. Unfortunately as you may imagine at this point the while loop needs to end and given the way its structured its going to repeat in an infinite loop right now.
So either i am dead wrong or ill have to try and rewrite the if statement and see if that works later on. In which case i would be very confused because as far as i understand the matter: If statements are skipped if the condition is not met. So in my case wouldnt it simply be skipped?
As for the tradingstudies.cpp file... almost all examples in there (from what ive seen) execute trades after a bar has closed and not while the bar is still open.
So how do i perform a condition check while a bar is still open, where the condition is not met yet, but may be met 2-3 minutes later without terminating the program and awaiting a function call