Initialize an empty list to store the orders.
Loop through each signal in the array. If the signal is not equal to zero, append a tuple to the list with the timestamp, price, and signal value.
Here's some sample code to illustrate this approach:
signals = [0, 0, 1, 0, 0, -1, -1, ...]
orders = []
for i in range(len(signals)):
if signals[i] != 0:
timestamp = # calculate the timestamp based on the index i
price = # calculate the price based on the index i and your data
signal = signals[i]
orders.append((timestamp, price, signal))
import csv
orders = []
with open('signals.csv', 'r') as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
timestamp = row[0]
price = float(row[1])
signal = int(row[2])
orders.append((timestamp, price, signal))