ONCE

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #8304 quote
    GraHal
    Participant
    Master
    Hi Please forgive the ‘daft’ question … Just trying to get my head around why ONCE is defined as …

    a definition statement which will be processed only once

    I know there is some code accompanying the definition of ONCE on this Site, but sometimes example code doesn’t help me to understand.

    For what period, timeframe, bar or ‘whatever’ will it be processed only ONCE please?

    All conditions are checked out once per bar (that’s how ProOrder works) so what is the restriction on ONCE?

    I can see it is not ONCE for the life of an Auto-System  until it is stopped and started again, so I just need a few more words of explanation to get it clear in my mind please.

    If it doesn’t make sense what I’m asking then just say and I’ll elaborate.

    Many Thanks

    GraHal

    #8328 quote
    Nicolas
    Keymaster
    Master
    Hi Graham, Usually ONCE is used to give a variable a first time value at code initialization. For example if your code need to make calculation with a variable value would needs to have at least 30 bar past datas elapsed, then it would not make its own calculation. So at code initialization, we affect this variable a dumb value, like :
    ONCE myvariable = close 
    If its related to price or 1, 1000, 3.14, whatever .. Sorry if its not clear, just tell me.. 🙂
    #8404 quote
    GraHal
    Participant
    Master
    Hi Nicolas, thanks Yes that is how I had fixed the use of ONCE in my mind (i.e. once until Strategy is stopped) but I keep seeing uses of ONCE that seem to contradict the definition of ONCE (statement which will be processed only once). For example the code snippet below from a Strategy off this site, seems to use ONCE per day (re Time) and per trade (re position size)?? Thats how I got confused again. Cheers GraHal // trading window ONCE BuyTime = 84500 ONCE SellTime = 113000 // money management // variable position size – thanks Adolfo 🙂 ONCE Capital = 10000 ONCE Risk = 0.01 ONCE StopLoss = 10 ONCE equity = Capital + StrategyProfit ONCE maxrisk = round(equity*Risk) ONCE PositionSize = abs(round((maxrisk/StopLoss)/PointValue)*pipsize) // fixed position size // ONCE PositionSize = 10
    #8413 quote
    Nicolas
    Keymaster
    Master
    A lot of these variables declared once are not necessary to be declared within once instruction.
    #8428 quote
    Adolfo
    Participant
    Senior
    @GraHal You’re wellcome 🙂 Maybe you can use this time variable “PositionSize” to be 10 “ONCE” and then will be calculated by formula, but in this case only “PositionSize” should be declared with ONCE instruction, other ones are not needed to use that, as Nicolas rightly said (as usual) 🙂 Best wishes.
    #8442 quote
    GraHal
    Participant
    Master
    Hey great, thanks guys, that gives me a bit more confidence now in my coding … I thought I was wrong but I was right after all … and you are right Adolfo and we know that Nicolas is right!! haha Cheers GraHal
    #8628 quote
    GraHal
    Participant
    Master
    I just had another thought … Nicolas said re the ONCE instruction …

    A lot of these variables declared once are not necessary to be declared within once instruction.

    I was still a bit troubled because I thought … why didn’t the ONCE instruction prevent the incorrect usage of ONCE or the expression builder throw it out as an error when backtest was attempted? It would be useful if code is ‘challenged / questioned’ (Trading Strategy Code in particular) by experienced coders and then ‘newbie coders’ can see how to get it right. I challenge my own mistakes in life generally and have taught myself loads in the process … ‘a man who never made a mistake, never made anything’!? Just a few thoughts anyway GraHal
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

ONCE


Platform Support: Charts, Data & Broker Setup

New Reply
Author
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by GraHal
9 years, 8 months ago.

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