ONCE
- This topic has 6 replies, 3 voices, and was last updated 8 years ago by GraHal.
-
-
05/29/2016 at 9:10 AM #8304
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
05/29/2016 at 7:10 PM #8328Hi 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 :
1ONCE myvariable = closeIf its related to price or 1, 1000, 3.14, whatever ..
Sorry if its not clear, just tell me.. 🙂
05/30/2016 at 6:26 PM #8404Hi 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 = 1005/30/2016 at 7:29 PM #841305/30/2016 at 8:36 PM #8428@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.
05/30/2016 at 9:06 PM #844206/02/2016 at 9:30 AM #8628I 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
-
AuthorPosts