I guess the question was whether it's actually possible to reference this way.
It's a seasonal indicator I'm trying to create.
The indicator is suppose to calculate average return for every date given a time period, then for every year multiplicate these values into a serie.
I should mention the future reference did not work when I tried it separate from the indicator.
I submit the codes if anyone is interested, not very clean, still learning:
Function:
Code: Select all
Inputs:
years(numericsimple);
variables:
counter(0),
counter2(0),
return(1);
Array:
dates[365]("symbol"),
returns[365](1);
dates[1] = "2015-01-01"; returns[1] = 1;
dates[2] = "2015-01-02"; returns[2] = 1;
.
.
.
dates[364] = "2015-12-30"; returns[364] = 1;
dates[365] = "2015-12-31"; returns[365] = 1;
//main
if BarNumber=1 then begin
for counter = 1 to 365 begin
for counter2 = 1 to years begin
value1=year(currentdate)+1900-years;
value2=MonthFromDateTime(stringtodate(dates[counter]));
value3=dayfromdatetime(stringtodate(dates[counter]));
value4=StringToDateTime(NumToStr(value1,0)+"-"+NumToStr(value2,0)+"-"+NumToStr(value3,0))-eldatetodatetime(date);
value5=close[-value4-1]/close[-value4];
return=return*value5;
end;
returns[counter]=power(return,(1/years));
return=1;
end;
end;
if month(date)=1 and month(date[1])=12 then begin
RM.seasonal_indicator=1*returns[1];
end
else begin
for counter=1 to 365 begin
condition1=month(date)=MonthFromDateTime(stringtodate(dates[counter]));
condition2=dayofmonth(date)=dayfromdatetime(stringtodate(dates[counter]));
if condition1 and condition2 then begin
RM.seasonal_indicator=RM.seasonal_indicator[1]*returns[counter];
end
else begin
RM.seasonal_indicator=RM.seasonal_indicator[1];
end;
end;
end;
Indicator:
Code: Select all
inputs:
years(10);
plot1( RM.seasonal_indicator(years) , "Seasonal",green );