previous array element value?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #168075 quote
    pableitor
    Participant
    Master

    Any idea how to get an arrays variable previous value ?  For instance, I tried this silly code:

    $x[0] = close
    return  $x[0][1]

    but $x[0][1] which is supposed to be the old value returns the present value same as $x[0] 

    #168078 quote
    robertogozzi
    Moderator
    Master

    It’s not allowed because arrays are not historicized, unlike common variables which allow to see previously  retained values.

    #168080 quote
    robertogozzi
    Moderator
    Master

    IF you have an array and want to historicize a very few elements, say elements 1  and 4, you can write:

    $Element[0] = close //$Element[0][1] is not allowed
    $Element[1] = high  //$Element[1][1] is not allowed
    $Element[2] = close //$Element[2][1] is not allowed
    $Element[3] = low   //$Element[3][1] is not allowed
    $Element[4] = range //$Element[4][1] is not allowed
    a = $Element[1]     //a[1], a[2], ... is allowed to see the history of Element[1]
    b = $Element[4]     //b[1], b[2], ... is allowed to see the history of Element[4]

    (unless you want to use a1, a2, a3,… a1000, provided you have enough time and memory).

    pableitor thanked this post
    #168081 quote
    pableitor
    Participant
    Master

    ok, maybe they reserve the format $x[i][j] for future 2-D arrays.  Yes, I found a simple workaround by using  temp variables like you said, but it takes  memory and time for long vectors:

    $x[0] = open
    $x[1] = close
    
    ...
    
    a = $x[0]
    b = $x[1]
    ...
    
    return  a[1], b[1],...
    #168084 quote
    Nicolas
    Keymaster
    Master

    Historizing arrays would have take more memory than this workaround, considering that the current one dimension array can handle one million column! 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

previous array element value?


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
pableitor @pableitor Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Nicolas
4 years, 9 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/26/2021
Status: Active
Attachments: No files
Logo Logo
Loading...