When examining some problems with my ProOrder code, I found some very strange behaviour using the ONCE statement. I have shortened those problems to some demonstrative examples.
First example:
once i = 0
if i = 1 then
buy 1 contracts at market
else
sellshort 1 contracts at market
endif
Expected behaviour: Generating only short orders.
Real behaviour: Generating only short orders.
That is ok
Second example, adding the line i = 1:
once i = 0
if i = 1 then
buy 1 contracts at market
else
sellshort 1 contracts at market
i = 1
endif
Expected behaviour: First should be a short order, after that only long orders.
Real behaviour: Generating only long orders.
That is not ok. Why is the first sellshort statement skipped although i is not equal to 1?
Third example, adding the line i = 0:
once i = 0
if i = 1 then
buy 1 contracts at market
i = 0
else
sellshort 1 contracts at market
i = 1
endif
Expected behaviour: Alternating short and long orders, starting with a short order.
Real behaviour: Alternating short and long orders, starting with a short order.
That is ok again.
Fourth example, something with a counter:
once i = 0
if i < 3 then
buy 1 contracts at market
else
sellshort 1 contracts at market
endif
i = i + 1
Expected behaviour: First 3 orders are long orders, after that only short orders.
Real behaviour: Generating only long orders
That is not ok again.
You can try those examples on any market in any timeframe. The result is the same every time.
My conclusion is: The ONCE statement does not work correct. Or did I overlook something? Can anyone provide a clue what went wrong here?
Many thanks in advance for any reply!