Getvalue and aggregation period


Category:
0
0

Hi,

My script finds a specific date and then I am able to know how many bars ago that happen.

Then, using getvalue I can retrieve the close of that day which is used later. That works fine in daily charts.

I know that in intraday charts I need to use aggregation period to retrieve the value in the right time frame, but that seems to fail with the getvalue function. This is my code:

Assuming I have in the variable ElapsedDays the number of dailybars ago that I need, say 75.

def MyClose= getvalue(close(period=aggregationperiod.day), ElapsedDays);

addlabel(yes,”MyClose =”+ myclose);

This only work well in daily charts if I use 15 min charts for example it retrieves the wrong value.

Am I wrong?

RESOLVED
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on April 6, 2018 2:10 pm
1836 views
1
Private answer

Hi Pete

I found a workaround, although not pretty, it works perfectly:

def aggDay=aggregationPeriod.DAY;

def timeFrame = GetAggregationPeriod();

# The trading sesion has 23400000 miliseconds
def BarsTimeframe=roundup( 23400000/timeframe,0);

#unfortunately GetValue does not work well with aggregation period ——————–
#To get the Close in intradaycharts ( ElapsedDays ago), we need to convert to bars elapsed in the time used frame

def MyClose = GetValue(close(period = aggDay),(ElapsedDays-1)*BarsTimeframe);

Thanks

 

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on April 7, 2018 12:38 pm
0

Cool, I like it. Thanks for taking the time to come back and post your solution.

( at April 7, 2018 12:52 pm)
0
Private answer

Couple things. The GetValue() function may be going back 75 of the 15 min bars to get the daily close. You do not need to use GetValue() at all. Because GetValue(close, 75) is the same as close[75]. The only time I have been forced to use GetValue() is within a loop (thinkscript refers to a loop as ‘fold’).

So, try using close(period = AggregationPeriod.DAY)[75]

Keeping in mind that if your 15 min chart does not have at least 75 days of viewable data on the chart, you still may fail to get the value you seek.

Marked as spam
Posted by (Questions: 37, Answers: 4089)
Answered on April 6, 2018 2:57 pm
0
Private answer

Thanks Ham

That is not the solution because 75 was just to say a value, please notice that I said this will be a variable number stored in the variable ElapsedDays and it changes every day.

So allow me re-state the situation:

  • I have a routine to find a specific date, the day is stored in a variable MyDay
  • Find the number of elapsed days:

def ElapsedDays = CountTradingDays(MyDay, GetYYYYMMDD());

  • Find the close on that specific day (MyDay)

def aggDay=aggregationPeriod.DAY;
def MyClose = GetValue(close(period = aggDay),ElapsedDays-1);

With MyClose I will do further calculations, but say for simplicity I just want to plot it (an horizontal line) starting from MyDate.

The problem: when I use Daily chart it works, when I got to intradays MyClose gets wrong value and is not any more a horizontal line (of course I make sure that I have more than enough days of viewable data on the chart)

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Answered on April 7, 2018 2:51 am
0

It’s Hahn, not Ham.
Given your clarification, I am not aware of any other methods to achieve your stated goals. If it does not work in the way you are applying it I can think of no alternative.

( at April 7, 2018 7:23 am)