Yes this is the idea but I'm working on this for the purpose of the mathematical procedures it can calculate and a wide flexibility. So, what I'm looking for is not necessarily just the daily returns but more the accumulation of variable x which is different in every pass of a loop. Because I can use the built-in formula block to calculate the necessary math's but if I want to do this to find averages, I need to compute back in time by running the loop and adding the values.
I will want to run larger calculations in the future and going into the custom code block and writing the mathematical code for each and every candle will be too extensive. I really appreciate your help in your suggestion I'll be keeping the code you wrote for when I need it in the future, but I'm still stuck on my initial problem.
I've set the loop up so that on every pass a variable gets modified by +1, this I set as the candle id for every pass on 30 cycles. on the daily timeframe the loop computes through the last 30days and the math is calculated on every pass, I just need to sum the return of each pass.