Is there a major bug with the ONCE statement?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #31636 quote
    GST
    Participant
    New

    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!

    Wing thanked this post
    #31706 quote
    Nicolas
    Keymaster
    Master

    To prevent this kind of “wrong” calculation of your i variable, you must use this line at the top of your code:

    defparam preloadbars=0

    It will disallow the system to load bars history before starting the strategy. It should solve your issue.

    #31732 quote
    GST
    Participant
    New

    Oh yes! I was not aware that the code is being executed even before the startdate of the strategy. Therefore your advice certainly clarifies the situation. Many thanks for that, Nicolas.

    Unfortunately, it does not solve my issue completely. After including the defparam statement, I would expect 3 buy orders in the fourth example (i = 0 / 1 / 2). But I only get 2 buy orders before the system moves to trigger sellshort orders. I have shown this in attachment Once1. And the second example does not work at all. So it seems, that the first round of calculation still happens before starting the strategy. And I am not able to guess why. Could you be of help once again?

    P.S.: When changing the starttime of the strategy to 00:00, the result does make me mad. Why is it starting 2 days earlier? See attachment Once2.

    Many thanks in advance!

    Once1.jpg Once1.jpg Once2.jpg Once2.jpg
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Is there a major bug with the ONCE statement?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
GST @gst Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by GST
8 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/10/2017
Status: Active
Attachments: 2 files
Logo Logo
Loading...