Ok, so you are looking for a way to have a global variable that can be changed by a function. Here is a small indicator to show this :
Code: Select all
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds
//@version=5
indicator("My function", overlay=true)
result = array.new_float(1, 0.0)
my_function(i) =>
oldValue = array.get(result, 0)
array.set(result,0, oldValue + i)
for i = 1 to 10 by 1
my_function(i*1.1)
if barstate.islast
label.new(bar_index, high, str.tostring(array.get(result,0)), textcolor=color.white)