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.
-
-
03/07/2022 at 12:10 PM #189500
Sorry, I dont get it, I just made a test wit the code you provided and the result is 99:
Haha, it well could be a language issue (my English). Your code :
123456789101112$Arr[0] = 89$Arr[1] = 200MyVar = 10MyVar = MyVar + $Arr[0]a=1if a=0 thenbuy at marketendifgraph myvardoes not comply to my expression about “across bars” (I said it differently before). Thus, try this (I did not test it today) :
1234567891011121314151617Once ArraySet = 0If not ArraySet then$Arr[0] = 89$Arr[1] = 200ArraySet = 1endifMyVar = 10MyVar = MyVar + $Arr[0]a=1if a=0 thenbuy at marketendifgraph myvar // Should graph 99 one time. All of the next times 10.And thus the issue :
- ArraySet is sustained for its value
- $Arr is “new” at the next bar-call (call of the code).
If I am right (after all) I should show you a most useful code/application with arrays, which I made in vain because the arrays are not sustained. I made it in vain because natural thinking makes me do it, even after I knew and made that topic about it (~ 2 months back – “What arrays can *not* be used for”).
1 user thanked author for this post.
03/07/2022 at 12:34 PM #189504@PeterSt
Your comment is “// Should graph 99 one time. All of the next times 10”
No, array elements keep any retained value until you change it purposely, like any variable.
The sole difference is that if you change a variable, you can still access its previous value with and index, such as MyVar[1], MyVar[2], etc…, while array elements CANNOT, you can’t access a prior value of an array element by using, say, $Arr[0][1] to retrieve the value that element $array[0] retained the prior bar!03/07/2022 at 1:27 PM #189511Can you post a description of an example of when you want an array to be totally erased at any new bar? It could be done, but you have to code it!
You mentioned that ProBuilder is not handling arrays like any other programming languages, because values are persistent other time. I do not know any language where arrays are automatically erased without any explicit instruction to do it?
03/07/2022 at 1:44 PM #189513No, array elements keep any retained value until you change it purposely, like any variable.
Even if I read that a 100 times I don’t understand the message in it. Maybe rephrase because the semantics seem so-so to begin with (I will try to learn Italian).
But apparently you guys don’t understand my messages either. 🙂No array elements retain their value, unlike normal variables do.
(from bar to bar)That should be correct (correct semantics maybe not – haha)
03/07/2022 at 1:47 PM #189514ARRAY ELEMENTS RETAIN THEIR VALUES LIKE ANY OTHER VARIABLE DO.
(no italian or french words here) 😆
12$var[0] = 1000//$var[0] will always keep 1000 as its value until you want to replace it with another one. From bar to bar or even in the same bar.
03/07/2022 at 3:15 PM #189527OK, you are right. It works. I guess there are just too many pitfalls and our mutual examples keep on being incorrect (mine too !).With a larger array-application, always something goes wrong (not working) because of the strange way how to deal with them. This is for that other topic, so never mind that for now (I just try to find excuses 🙂 🙂 ).Anyway, it requires 100% literal examples, or else something differently happens. Thus your last example1$var[0] = 1000will always show 1000 indeed, but not because it is going across bars. You just assign it newly each time in this example (it requires an If not to do that).
I repeat : my own examples also work out differently. But a lot is based on mistakes, where you don’t correct me on. Example (implied in my earlier example) :1234567// Suppose these are THE ONLY lines in a Strategy :$Arr[2] = $Arr[2] + 1000 // This errors-out internally.aaa = aaa + 1 // But this is fine (which I personally hate, but alas).Graph $Arr[2] // Graphs nothing because it errored out earlier.Graph aaa // Graphs 1, 2, 3, 4, ...As you can see this is not consistent behaviour and I never saw that (I never recognised it).
This code would be correctly working (tested this time) :
123456789101112Once ArraySet = 0If not ArraySet then // THIS ONE !$Arr[0] = 89 // So Yes, this value is retained.$Arr[1] = 200ArraySet = 1endifMyVar = 10MyVar = MyVar + $Arr[0]Graph MyVar // Always graphs 99.I like to bring across that this is enormously ambiguous coding because it requires nothing much to let the line denoted “THIS ONE !” to go wrong on the coding side (I forget line one, for example or anything else that makes the If work out to False always) and the code at this line :
MyVar = MyVar + $Arr[0]
will just not do its job. And, if I use arrays like your examples (everywhere I’d say, including the last posts) then you use them locally (within the one bar) and by nature that would not fail. This is because I won’t need any If Not ArraySet stuff.
So …
@fhorus, I don’t understand what your issue is, because all just works (LOL). But I hope that Nicolas sees that his last reply to fhorus is again with an example where the array is used “locally”. And this way we will never understand.
With my way of throwing confusement at you, also not.
The ONCE should be used to define a variable such that its scope is always under the definition. This is ambiguous :
123456789101112If not ArraySet then$Arr[0] = 89$Arr[1] = 200ArraySet = 1endif// What if the code in the If is never executed ?// We would have unexpected results in :bb = $Arr[0]// and all what further uses bb (or $Arr). And no error message anywhere.Now this :
123456789Once $Arr[] // This initialises all array elements at 0. But which ? so there's more to it (Dim command).If not ArraySet then$Arr[0] = 89$Arr[1] = 200ArraySet = 1endif// Now nothing is ambiguous.So the above (last code) can not be done because PRT does not allow for it.
Lastly :
123Once A = 0 // If I would leave this out, I'd kill myself on the next occasion.A = A + 1 // Count across bars.So you guys come up with examples leaving out the first line and deem it fine.
It is of course PRT providing the option (not for arrays !) so we can wonder who is “wrong” to begin with.Thus @fhorus, with the correct examples everybody turns out to be correct. But the main thing is : it just works as you (and me) want it to. Not with the ONCE but with some kind of decent If.
Apologies for all the confusing stuff. Luckily I was somewhat cautious. 🙁
This was the longest post possible to state that I was wrong after all.03/07/2022 at 3:27 PM #189530Ok, to conclude for everyone, you can just assign a value in a column of an array, just one time, and it will last forever.
For example, use ISSET:
IsSet : Returns 1 if the index of the array has already been set in the code, otherwise returns 0
123if not isset($var[0]) then$var[0] = 1000endif03/07/2022 at 3:42 PM #189532Thank you Nicolas, Roberto and PeterSt for your time and effort to bring us to an understanding of those points. It appears it was much needed ! So basic, however previously unclear.
So many years of using PRT and the point you’ve stressed here several times, Nicolas -“ variables retain their value”-, was simply not in my mind or fairly unclear, probably because most of the variables in my indicators just change their value on each new bar. Not surprising that I’ve sometimes got some trouble with boolean variables, from one bar to the next !
Ok, we’ve got it now ; hope it will also be useful to others.
03/07/2022 at 4:29 PM #189537No array elements retain their value, unlike normal variables do
NO, that’s incorrect. As I wrote, “No, array elements keep any retained value until you change it purposely, like any variable“. I can’t see how semantics could be of any help, just once you have assigned a value to an array element that value will ALWAYS be retained, bar after bar, untill you purposely change it, just like any variable. That’s all.
03/07/2022 at 5:50 PM #189549NO, that’s incorrect.
OK, you want to continue. Yes Roberto, I know that by now. Why repeat something which was put behind us ? please delete your own last post and this one from me. You are additionally confusing, IMHO.
Yes, you are right too. Happy ? sure you are.
Now you can delete your post. 🙂06/30/2022 at 11:48 AM #19645806/30/2022 at 2:58 PM #19647706/30/2022 at 3:41 PM #19648212/01/2022 at 1:30 PM #205126Hello . Is it possible to assign array from another ?
For example i have day array with some values , week and month – $Dx , $Wx , $Mx
After islastbarupdate in i want to populate array with another
IF sDay THEN
$Final = $Dx
ELSIF sWeek THEN
$Final =$Wx
ELSIF sMonth THEN etc .Later draw lines using $Final array ?
Or only for .. next loop ?
Thank you
12/01/2022 at 1:56 PM #205129Sorry there is no array duplicate, you have to make a loop to copy each row of an array into another one, like you suggested.
2 users thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on