I am a novice in pine script
I have encountered a problem in understanding time series
I can’t understand why the output log in the global scope is different from the value in the SCOP 1 on the same bar,
but the logs of GLOBAL and SCOP 2 are the same, even though they are all entered under the condition of bar_index % 2 == 0.
I really want to know why the same variable macdLine Why is it different?
because I think I haved visited macdLine[0], macdLine[1], macdLine[2], macdLine[3] in the global scope, so the time series of macdLine is continuous on each bar.
indicator("MACD")
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
// Global log.info statement
log.info("GLOBAL macdLine {3}, {2}, {1}, {0}", macdLine[0], macdLine[1], macdLine[2], macdLine[3])
pine_series() =>
// Local variable assignment
a0 = macdLine[0]
a1 = macdLine[1]
a2 = macdLine[2]
a3 = macdLine[3]
// Log.info statement inside the function
log.info("SCOP 1 macdLine {3}, {2}, {1}, {0}", a0, a1, a2, a3)
pine_series2() =>
// Local variable assignment
if bar_index % 2 == 0
a0 = macdLine[0]
a1 = macdLine[1]
a2 = macdLine[2]
a3 = macdLine[3]
// Log.info statement inside the function
log.info("SCOP 2 macdLine {3}, {2}, {1}, {0}", a0, a1, a2, a3)
if bar_index % 2 == 0
pine_series()
pine_series2()
the log.info output is :
[2024-06-25T00:00:00.000-00:00]: GLOBAL macdLine -844.149, -993.119, -1,331.554, -1,461.542
[2024-06-25T00:00:00.000-00:00]: SCOP 1 macdLine -748.141, -993.119, -993.119, -1,461.542
[2024-06-25T00:00:00.000-00:00]: SCOP 2 macdLine -844.149, -993.119, -1,331.554, -1,461.542
I can understand that the if condition will cause the time series values to be different, but I can’t understand why different values appear when I have called macdLine[0], macdLine[1], macdLine[2], macdLine[3] in the global scope.