ONCE Command Suspected Bug

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #16053 quote
    GleamBright
    Participant
    New

    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 quote
    Nicolas
    Keymaster
    Master

    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 quote
    GleamBright
    Participant
    New

    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 quote
    Nicolas
    Keymaster
    Master

    “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 quote
    GleamBright
    Participant
    New

    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)
  • You must be logged in to reply to this topic.

ONCE Command Suspected Bug


Platform Support: Charts, Data & Broker Setup

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by GleamBright
9 years, 3 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 11/07/2016
Status: Active
Attachments: No files
Logo Logo
Loading...