ONCE Command Suspected Bug

Forums ProRealTime English forum ProRealTime platform support ONCE Command Suspected Bug

Viewing 5 posts - 1 through 5 (of 5 total)
  • #16053

    I’m having trouble with the ‘ONCE’ command. It seems to be assigning incorrect values to variables. A simple example of the code is as below:

    Once a=0
    If a=1  then
    Buy 1 contracts at market
    Endif

    For some reason this code executes successfully, but if I use a=0 in the ‘if’ command, the code does not execute. Alternatively, the ‘if’ command executes successfully if I eliminate the ‘ONCE’ command.

    I have a few other similar examples using various variables, where the ‘ONCE’ command seems to be assigning a different value than requested.

    Has anyone come across this issue before and am I doing anything wrong?

    #16055

    Just tested it and got not this issue.

    What instrument / timeframe?

    You can view your a variable value with the GRAPH instruction to see when it has been set to 1.

    If I remember correctly, I used to met the same question as you, but don’t know in what environment, but you should maybe use a “defparam preloadbars=0” and see what happen.

    #16088

    Market: Spot Gold, 5 minute bars. Would you mind explaining what ‘Defparam preloadbars=0’ actually does? Where can I reference more info about uses of defparam?

    Thanks for the tip about graphing variables, without being able to track the variable values it is very difficult to troubleshoot my code. I’m a beginner in ProReal Time and a recreational coder.

     

    #16090

    “defparam” is used to define some important parameters at the very beginning of the code. Here, it is the “preloadbars” which is important, this instruction will ensure that no price data history has been loaded before the first instruction is set (“once” in your case).

    I’m not sure it will help for your problem, since I don’t reproduce it myself ..

    #16214

    The defparam  command ‘fixed’ it. If I run the below code, the system executes as planned, and initiates a position at bar 10. If the defparam command is deleted from the code, variable ‘a’ starts at a value of 1000 and the code is unsuccessful/ it cannot initiate a position.

    defparam preloadbars=0
    GRAPH a
    Once a = 0
    if a = 10 then
    Buy 1 contract at market
    endif
    a=a+1

    Thanks for the help, that had me really concerned there for a while, although it’s still a bug in my opinion. The ONCE command isn’t successfully assigning the value of the variable.

     

     

Viewing 5 posts - 1 through 5 (of 5 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login