array variables availability in ProRealTime – examples and discussions
Forums › ProRealTime English forum › ProBuilder support › array variables availability in ProRealTime – examples and discussions
- This topic has 254 replies, 50 voices, and was last updated 1 month ago by robertogozzi.
-
-
01/01/2022 at 6:09 PM #184269
Hi, no
(unless you have a mathematical relationship between array index and value with a function f, in which case a workaround would be to loop on i with i as index and f(i) as value $period[i]=f(i) to minimise number of lines for initialisation… but I assume you would have mentionned it if it was the case)
1 user thanked author for this post.
01/15/2022 at 7:41 PM #185587Will be possible in a few days for ProRealTime software, then updates with new instructions will come to other versions dealed by brokers. I’m currently testing these new capabilities (with other many cool new instructions and not specific to arrays..). The new instructions for arrays are: Unset($var) Reset the whole array ArraySort($var,mode) Sort ASCEND or DESCEND (mode) the whole data set of an array
Hi @Nicolas,
Maybe you can help out …
Do you think that it can it be so that someone forgot to implement these for ProOrder ? Both don’t work there, while for ProBuilder they do (see top-part vs bottom-part in the attachment).
The other array commands seem to work fine in ProOrder.Thank you !
Peter01/17/2022 at 11:34 AM #18566802/09/2022 at 1:23 PM #18796202/09/2022 at 1:44 PM #18796602/09/2022 at 2:11 PM #18796703/07/2022 at 4:09 AM #18946003/07/2022 at 5:38 AM #189461You can write:
1234567891011121314If BarIndex = 0 then$MyValue[0] = 0$MyValue[1] = 1$MyValue[2] = 2..Endif// orIf BarIndex = 0 thenFor i = 0 TO 20$MyValue[i] = iEndif03/07/2022 at 8:44 AM #189465is there a way to populate an array and use its values over several bars (like a “once” variable, which is memorized from one bar to the next) ?
No.
And this makes arrays virtually useless (says me). All is relative (read : with huge imagination we can utilise arrays), but what they should do (your question) they don’t.03/07/2022 at 9:45 AM #189470Values stored in arrays can be used at any time like any other variable. The values will remain the same as long as you don’t populate them with new ones.
I think Peter is talking about history of arrays, the values they used to have X bars ago.
03/07/2022 at 10:35 AM #189476I think Peter is talking about history of arrays, the values they used to have X bars ago.
No ?
I’d say the discussion could be interesting (including me missing it all !).So No, I am *not* talking about $Arr[x,3] or something – the 3 denoting 3 bars back. When arrays would work as “expected” (from normal coding environments) then this is not even needed. But the other day I found out this (if my memory serves me well) :
What I would always be talking about is about Strategy code.
What you, Nicolas, would normally think about is Indicator code.… And that other day it seemed to me that Indicator code does do what I’d want or would find normal …
**Better skip till under the horizontal line below.**
There is much more going on which an inherent coder (me) can’t think of for logic. This is, for example, the variables in Strategy Code being accessible by Indicator code (I suppose you know that, *or* by now I am talking from my *ss). What I should add is that I am not heading for that this is all “wrong” as such, because if it works, it works, and if it is what PRT coders are used to, who am I to debunk it. But so many things don’t work as expected, and it makes me make mistakes (in judgment but also in coding). Anyway, this is not a subject really. This is :
The question from @fhornus is there for a reason. And if I were you or Roberto, I would answer with a “but this is just possible !”. Instead of (like Roberto) coming up with an other solution (which is a moot one IMHO and springs from misunderstanding). So possibly I understand what fhornus’ problem is, and this is from within Strategy code. The point is also (kind of) :
He uses ONCE in his question for a reason. I would do that too (and in my topic about it from 2 months or so back, I actually presented all around ONCE). This in itself is so super vague that I can (and have !) posted about the usage of Once with a completely wrong perception. Still – when it is interpreted by e.g. Roberto- his responses are so different from what I expect, that it indeed leads to *ME* (!!) having it wrong, while he can not see it. Too hard to explain, but this is probably why I understand fhornus’ question.
If I – in Strategy code – do something like
$Arr[0] = 89
$Arr[1] = 200then in a next bar call (call of my Strategy code) I want to work with $Arr[0] and $Arr[1]. But it can’t because it does not exist any more. And would I apply
MyVar = 10
MyVar = MyVar + $Arr[0]I’ll receive a nice 10 instead of 99 because of the internal construction (this is caught internally) and I can’t even see I am doing it wrongly (no error message because that is how PRT deals with it). The logical solution :
Once $Arr[]
This is not related to the history of arrays and that I 20 bars further want to see the array content of the first or second etc. bar. The application of arrays is for normal coding environments (be it Basic, C++, VB.net, cobol, Fortran, Mumps) completely different from how PRT presents it. And since the Indicator Code can do it (can it ??) it is beyond me why not with Strategy code. It would be useful !!
Do I have it all wrong ?
03/07/2022 at 10:45 AM #189480Sorry, I dont get it, I just made a test wit the code you provided and the result is 99:
123456789101112$Arr[0] = 89$Arr[1] = 200MyVar = 10MyVar = MyVar + $Arr[0]a=1if a=0 thenbuy at marketendifgraph myvarIf you have defined $Arr[0] = 89 one time, this value will last forever until you change it.
03/07/2022 at 11:05 AM #189485Thanks to Roberto for his answer -as always- and to PeterSt …for getting the point.
My purpose in fact was not coding strategy , rather to generate statistics to -try to- analyse the dynamic of market mouvements, but in both cases the point is the same : to use data collected in one bar within an array, in an other bar later on. I’ve tried “Once $Arr[]”, but with no success.Rgds
03/07/2022 at 11:13 AM #18948603/07/2022 at 11:16 AM #189487If you give a value to a variable in an array, you will be able to use it later, so I don’t understand your question 🙂
ONCE is an instruction that is used to give a variable a value only one time, at the first read of the code, it is used for specific purpose and I don’t think it is relevant for your own issue.
There are plenty of examples on how to use arrays in the first pages of this thread. But here is a simple example:
12345if close>open then$var[barindex] = 1else$var[barindex] = -1endifin this example we store in the $var variable array the type of candlestick (green is equal to 1 and red equal to -1), so you can make analysis in the last X bars for example, of how many bars were green or red:
1234567891011X = 50 //lookback analysisgreen = 0red = 0for i = barindex downto max(1,barindex-X) doif $var[i]>0 thengreen=green+1elsered=red+1endifnext -
AuthorPosts
Find exclusive trading pro-tools on