Reputation: 1
Hi guys I could really use some help. I'm not a programmer I'm just started out
Im trying to store every resulting calculated value of two tables and somehow store it into another table for later use.
Close = {1,2,6,2,2,...8} --livedata with a series of value upto 100
Open = {3,10,1,5,3,...10}--livedata with series of value upto 100
So here's my code
body = {}
For i = 1,100 do
if close[i] > open[i] then
V = close[i] - open[i]
else
V = open[i] - close[i]
end
table.insert(body,1,V)
end
for k,v in pairs(body) do print(k,v) end
Here's the result
1 2
2 2
3 2
4 2
5 2
100 2
It just keep repeating it last calculated value for a 100 times
I'd expect it the result to be something like this
1 2
2 8
3 5
4 3
5 1
100 2
Really appreciate it anyone who help
Upvotes: 0
Views: 137
Reputation: 26794
You're not showing the exact code you're running (as the variables have different names and For
should be lowercase), but the main issue seems to be with the table.insert
call (table.insert(body,1,V)
), as you're always inserting in the first position, so you're results have the reversed order. If you fix these issues (just use table.insert(body,V)
), you should get the expected results.
Upvotes: 0