I have changed (errorneously?) the base loop in a strategy from:
CODE:
Please log in to see this code.
To:
CODE:
Please log in to see this code.
In my opinion the (bool) flag IsLastPositionActive can only take 2 values
and the statements should be semantically equivalent.
My strategy shows a difference of 13% annually over 16 years backtest
with if (!IsLastPositionActive).
Please comment.
Regards, Rene
Size:
Color:
When you remove the "else", here's what happens:
1. IsLastPositionActive was true.
2. You exited, making IsLastPositionActive = false.
3. The code falls down and since !IsLastPositionActive == true, executes your entries.
Simple as that. That's why the standard single-position template is there.
P.S. See also (on a somewhat related matter): the WealthScript Programming Guide > Programming Trading Strategies > Peeking > Trading based on Position Active Status.
Size:
Color:
Thank you for the explanation.
My strategy exits at bar with a limit/stopLoss or holding period expired
and calculates new entries for the open at bar+1.
Therefore, in my opinion, I can use if(!IsLastPositionActive)
and Buy at bar+1 and it is not a mistake.
As I understand, the basic templates with "else" makes
a one day "break" for each symbol and
the if(!IsLastPositionActive) allows a fast entry.
That would explain the annual difference (and would not be peeking).
Is this correct ?
Rene
Size:
Color:
Well, that's up to you to not get the exit alerts because they use "bar" vs. "bar+1" as they should be, not to mention that it doubles your chance of peeking into the future.
Size:
Color: