Hi , i am trying to do and indicator that returns me the summatory of the value (close-open) for the last 10 month but for each month separately, i mean: the last 10 januaries, the last 10 februaries, …..
that is what i did,But it doesn´t work, i don´t know why
Retorno = close[0]-open[0]
for i=0 to 10 do
Retorno = (close[i+12]-open[i+12]) + Retorno
next
Return Retorno
Thank you very much
Hi, it’s because in the loop, with i+12 instead of i*12 you’re adding all the consecutive months before the one 12 ago instead of “jumping” every 12 months + with 0 to 10 you’re adding that 11 times instead of 9 times to first one to make a total of 10 + you’re counting current candle’s retorno several times inside the loop.
Let’s try with this one to display on a monthly timeframe each month the sum of same-name 10 months as current month + previous same-name 9 one’s
x=close[0]-open[0]
y=0
Retorno=0
if barindex>120 then// wanting at least 10 times 12 months in history
for i=1 to 9 do
y = x[i*12] + y // y intermediate calculation of the 9 times before (close-open)
next
Retorno= y+x// adding y to current close-open
endif
return Retorno as "Retorno",0
Now is perfect, thank you very much, my idea was the following
x=(close[0]*100/open[0])-100 // (close-open)%
y=0
Retorno=0
if barindex>120 then
for i=1 to 9 do
y = x[i*12] + y // y intermediate calculation of the 9 times before (close-open)
next
Retorno= y+x// adding y to current close-open
endif
RetornoMedio = Retorno/10 //average
return RetornoMedio ,0
An indicator that returns the average of (close-open)% of the last 10 months (for each month) to do seasonality studies for stocks.
Thanks again