array variables availability in ProRealTime – examples and discussions

Viewing 15 posts - 166 through 180 (of 255 total)
  • Author
    Posts
  • #184269 quote
    JC_Bywan
    Moderator
    Master

    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)

    Nicolas56 thanked this post
    #185587 quote
    PeterSt
    Participant
    Master

    Will 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 !
    Peter

    image_2022-01-15_192705.png image_2022-01-15_192705.png
    #185668 quote
    Nicolas
    Keymaster
    Master

    There is always a time between updates of the engines, so I would say it is normal.

    #187962 quote
    sharteel
    Participant
    Junior

    Hello Nicolas,

    i m learning and for that i m looking the example, the example #3 is not working for me when i import it in the 1 tick graph.

    Something more should be added in the code ?

     

    Regards,

    tom

    #187966 quote
    Nicolas
    Keymaster
    Master

    I changed the code and it works now.

    #187967 quote
    sharteel
    Participant
    Junior

    thanks Nicolas !!!!

    Now, i ll try to reset the upvol and dnvol array value for discarding the cumulative effect of the runtime.

    #189460 quote
    fhornus
    Participant
    Junior

    array versus “once” variable

     

    Hi,

    is 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) ?

    Thanks.

    #189461 quote
    robertogozzi
    Moderator
    Master

    You can write:

    If BarIndex = 0 then
       $MyValue[0] = 0
       $MyValue[1] = 1
       $MyValue[2] = 2
       .
       .
    Endif
    
    // or
    
    If BarIndex = 0 then
       For i = 0 TO 20
         $MyValue[i] = i
    Endif
    #189465 quote
    PeterSt
    Participant
    Master

    is 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.

    #189470 quote
    Nicolas
    Keymaster
    Master

    Values 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.

    #189476 quote
    PeterSt
    Participant
    Master

    I 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] = 200

    then 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 ?

    #189480 quote
    Nicolas
    Keymaster
    Master

    Sorry, I dont get it, I just made a test wit the code you provided and the result is 99:

    $Arr[0] = 89
    $Arr[1] = 200
    
    MyVar = 10
    MyVar = MyVar + $Arr[0]
    
    a=1
    if a=0 then 
     buy at market 
    endif 
    
    graph myvar

    If you have defined $Arr[0] = 89 one time, this value will last forever until you change it.

    graph-array.png graph-array.png
    #189485 quote
    fhornus
    Participant
    Junior

    Thanks 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

    #189486 quote
    fhornus
    Participant
    Junior

    Thanks Nicolas ; I’ll try that in Probuilder

    #189487 quote
    Nicolas
    Keymaster
    Master

    @fhornus

    If 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:

    if close>open then 
     $var[barindex] = 1
    else 
     $var[barindex] = -1
    endif

    in 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:

    X = 50 //lookback analysis
    
    green = 0
    red = 0
    for i = barindex downto max(1,barindex-X) do 
     if $var[i]>0 then 
      green=green+1
     else
      red=red+1
     endif
    next
Viewing 15 posts - 166 through 180 (of 255 total)
  • You must be logged in to reply to this topic.

array variables availability in ProRealTime – examples and discussions


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Nicolas @nicolas Keymaster
Summary

This topic contains 254 replies,
has 50 voices, and was last updated by robertogozzi
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 02/06/2020
Status: Active
Attachments: 59 files
Logo Logo
Loading...