Trying to access future data  [SOLVED]

Questions about MultiCharts and user contributed studies.
roymalmberg
Posts: 5
Joined: 09 Jan 2015
Has thanked: 3 times

Trying to access future data

Postby roymalmberg » 17 Jun 2015

Hello!
I've been browsing around, and according to previous posts it should be possible to reference future bars by using for example "close[-1]". However I'm having problems and get error:
"Trying to access future data. Bar reference value : -500"
The code is in a function which belong to an indicator placed on a chart with 9000 bars back. The code containing reference to future is only calculated on BarNumber=1.

Any ideas what could be the problem?

Best regards, Roy

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trying to access future data

Postby TJ » 17 Jun 2015

Hello!
I've been browsing around, and according to previous posts it should be possible to reference future bars by using for example "close[-1]". However I'm having problems and get error:
"Trying to access future data. Bar reference value : -500"
The code is in a function which belong to an indicator placed on a chart with 9000 bars back. The code containing reference to future is only calculated on BarNumber=1.
Any ideas what could be the problem?
Best regards, Roy
How do you expect us to help you?

roymalmberg
Posts: 5
Joined: 09 Jan 2015
Has thanked: 3 times

Re: Trying to access future data

Postby roymalmberg » 17 Jun 2015

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 );

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Trying to access future data

Postby JoshM » 18 Jun 2015

I've been browsing around, and according to previous posts it should be possible to reference future bars by using for example "close[-1]". However I'm having problems and get error:
"Trying to access future data. Bar reference value : -500"
The code is in a function which belong to an indicator placed on a chart with 9000 bars back. The code containing reference to future is only calculated on BarNumber=1.

Any ideas what could be the problem?
Even though you've already found a workaround, here's an answer for other people finding this thread:

Data of future bars can be accessed with a negative index (like -1, which you already got) and one of the `Symbol_` keywords like Symbol_Close. So `Symbol_Close[-10]` returns the closing price 10 bars from now.

But note that you cannot access more future price bars then there are on the chart, so the difference between Symbol_CurrentBar and Symbol_Length need to be big enough to access the future bar you're interested in.

McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Re: Trying to access future data

Postby McGeorge » 26 Jul 2018

Hi there,

I need a report from a tick bar chart with historical data to see how many ticks there are for each minute. To achieve this, I need to reference the DateTime of next bar (DateTime[-1]) to determine if the current bar is the last tick of the minute. The codes are as below:

Code: Select all

Variables:
TickCount(0),
ThisMinute(0),
PrevMinute(0),
NextMinute(0);


If Date[0] = 1180627 Then Begin
ThisMinute = MinutesFromDateTime(DateTime[0]);
PrevMinute = MinutesFromDateTime(DateTime[1]);
NextMinute = MinutesFromDateTime(DateTime[-1]);
If ThisMinute = PrevMinute Then Begin
TickCount = TickCount + 1;
End
Else Begin
If LastBarOnChart = False Then Begin
If ThisMinute <> NextMinute Then Begin
TickCount = 0;
Print ("DateTime = ", ThisMinute, ", TickCount = ", TickCount:0:0, ", Last Tick of Minute");
End;
End
Else Print ("DateTime = ", ThisMinute, ", TickCount = ", TickCount:0:0, ", Last Tick of Minute");
End;
End;
When I executed the codes, I got an error alert saying "Trying to access future data. Bar reference value : -1". Since I already added the LastBarOnChart function in an IF loop, I do not expect an error alert like this.

Could you advise what happened to the codes?

Thanks.

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Trying to access future data

Postby sptrader » 26 Jul 2018

You're trying to reference Tomorrow's date, today is the 26th.

McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Re: Trying to access future data

Postby McGeorge » 27 Jul 2018

You're trying to reference Tomorrow's date, today is the 26th.
Hi SPTrader,

Thanks for your response but the data is historical data on 27/JUNE/2018 not 27/JULY/2018. What is the real reason then?

Thanks.

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: Trying to access future data

Postby sptrader » 27 Jul 2018

You're trying to reference Tomorrow's date, today is the 26th.
Hi SPTrader,

Thanks for your response but the data is historical data on 27/JUNE/2018 not 27/JULY/2018. What is the real reason then?

Thanks.
It might be referencing your computer clock time. When I changed the date in your code to the 26th, it compiled.

McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Re: Trying to access future data

Postby McGeorge » 27 Jul 2018

You're trying to reference Tomorrow's date, today is the 26th.
Hi SPTrader,

Thanks for your response but the data is historical data on 27/JUNE/2018 not 27/JULY/2018. What is the real reason then?

Thanks.
It might be referencing your computer clock time. When I changed the date in your code to the 26th, it compiled.
HI SPTrader,

I had no problem getting the codes compiled. The error alert popped up when I inserted the study into the chart. Not sure what you mean by "it might be referencing your computer clock time". In my codes I did not reference computer time. The reserved word that references computer time is "ComputerDateTime", which I did not use in my codes .

I hope the MC support can answer my questions.

Thanks.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trying to access future data

Postby TJ » 27 Jul 2018

HI SPTrader,

I had no problem getting the codes compiled. The error alert popped up when I inserted the study into the chart. Not sure what you mean by "it might be referencing your computer clock time". In my codes I did not reference computer time. The reserved word that references computer time is "ComputerDateTime", which I did not use in my codes .

I hope the MC support can answer my questions.

Thanks.

You have to find out the offending code.

eg.
Try to make a test indicator that has this line:


DateTime[-1]

McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Re: Trying to access future data

Postby McGeorge » 27 Jul 2018

HI SPTrader,

I had no problem getting the codes compiled. The error alert popped up when I inserted the study into the chart. Not sure what you mean by "it might be referencing your computer clock time". In my codes I did not reference computer time. The reserved word that references computer time is "ComputerDateTime", which I did not use in my codes .

I hope the MC support can answer my questions.

Thanks.

You have to find out the offending code.

eg.
Try to make a test indicator that has this line:


DateTime[-1]
Hi TJ,

I tried codes as simple as below and same error alert popped up. It appears referencing future data is totally not allowed, which is not what is expected.

Code: Select all

If LastBarOnChart = False Then Print ("Close = ", Close[-1]);
Any idea what happened?

Thanks.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Trying to access future data  [SOLVED]

Postby Henry MultiСharts » 27 Jul 2018

Hello McGeorge,

There is no way to access the values of the future bars as they do not exist on the current calculation. Only current and past bars can be accessed.
If you need the DateTime of the next bar - increment the DateTime of the current bar accordingly.


Return to “MultiCharts”