Calling CCI in MTF


Category:
0
0

Hi Pete. You came to my rescue last week with a snippet of code I was having trouble with and got me back on track. I really didn’t want to bother you again as I don’t want to monopolize your time, but I have an error that I just can’t seem to get rid of. I’ve tried everything I can think of. I hope you don’t mind. Here’s the code and the issue is in the last 2 lines when I try to call the CCI. Thank you in advance.

def agg2 = AggregationPeriod.TWO_MIN;
def agg5 = AggregationPeriod.FIVE_MIN;

input CCIlength = 14;
input CCITlength = 6;
input CCI50length = 50;

def CCIprice = (close + low + high);
def linDev = LinDev(CCIprice, CCIlength);
def CCI = if linDev == 0 then 0 else (CCIprice – Average(CCIprice, CCIlength)) / linDev / 0.015;

def CCI142 = CCI(CCIlength,(period = agg2));
def CCI145 = CCI(CCIlength,(period = agg5));

Marked as spam
Posted by (Questions: 5, Answers: 9)
Asked on June 16, 2020 1:12 am
126 views
0
Private answer

I moved your question out of the Strategy Guide topic and into the Chart Studies topic because nothing in your question pertains to chart strategies.

When referencing higher time frames for the CCI there is only one way to get there:

input timeFrameOne = AggregationPeriod.DAY;
input length = 14;
def price = close(period = timeFrameOne) + low(period = timeFrameOne) + high(period = timeFrameOne);
def linDev = lindev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;

I am curious to know where you got the idea that it could be done using this method:

def CCI142 = CCI(CCIlength,(period = agg2));

That is completely invalid. Why should you know this? Because the CCI chart study takes a total of four input parameters and none of them are named "period". The input parameters used for referencing the CCI chart study are as follows:

CCI(length, over_sold, over_bought, showBreakoutSignals)

Those are the exact input parameters listed on the very top of the CCI chart study included with Thinkorswim. Notice there is nothing in there that says "period". And if you study the instructions provided by Thinkorswim you will find that secondary aggregation periods are only applied to fundamental data objects (such as open, high, low, close, etc...). They are not ever applied as an input parameter to ta built in chart study. Details here:

https://tlc.thinkorswim.com/center/reference/thinkScript/tutorials/Advanced/Chapter-11---Referencing-Secondary-Aggregation

 

Marked as spam
Posted by (Questions: 37, Answers: 4089)
Answered on June 16, 2020 7:50 am
0
Pete, thank you very much. I was somehow under the impression you could apply multiple aggregations to chart studies but obviously I was mistaken. I had previously read the reference material you provided the link for but it wasn’t clear to me at the time that higher aggregations could ONLY be applied to fundamental data. After reading it again today, and after your input, it makes more sense now. Clearly I still have a long way to go to learn how to use thinkScript, but once again you got me back on the right track and I sincerely thank you for that. I'm definitely learning a lot from you and today was a big piece in the puzzle for me. Thanks again.
( at June 16, 2020 1:35 pm)
0
Awesome. I love to get feedback like this. Teaching is one of my favorite things to do and I always appreciate it when folks take the time to acknowledge that I was able to help them learn something new. Best of luck to you!
( at June 16, 2020 2:43 pm)