Raul Lopez Diaz
Raul Lopez Diaz

Reputation: 1

Save a price in an array to retrieve later

I am trying to send custom signals to a Bot based on TV condition. To open a trade, I use a cross of emas condition. What I want to achieve is that, once the position is opened, dont add more margin to that position if the deviation is less than a fixed "%". Problem comes when trying to store the vale of the price which we entered the position in order to do the calculations. I am trying with arrays, but it seems it keeps deleting the data.. any help?

arr = array.new_float(0)
 
if buySignal
    array.push(arr, close)
    lab = ""
    for i = 0 to array.size(arr) - 1
        lab := lab + tostring(array.get(arr, i)) + " "
    l = label.new(bar_index, close, lab)
    label.delete(l[1])

This is the code I have written, but it only stores the last value where the condition where met.

Upvotes: 0

Views: 617

Answers (1)

rumpypumpydumpy
rumpypumpydumpy

Reputation: 3823

You'll need to use the var keyword to declare the array so it isn't reinitialized on each new bar.

var float[] arr = array.new_float(0)

Upvotes: 1

Related Questions