I am trying to determine in the last hour of trading, if the slope of the CCI indicator is going Up or Down. I wanted "Slope UP" or "Slope Down" to show-up on a bubble in the last hour. I thought I had it until I looked at the actual CCI and saw that my calculation was hit or miss on being accurate. So I added some extra lines so that I could try to troubleshoot. I have verified that the numbers I'm using in the up/down calculation match what is in the chart, but the calculation doesn't work. Below is the code I've been working on. Any ideas what I am overlooking? Thanks.
declare lower;
input cciLength = 20;
input cciAvgLength = 15;
input price = close;
input length = 3;
input displace = 0;
def AvgExp = (ExpAverage(price[-displace], length));
plot CCI = CCI(length = cciLength);
plot CCIAvg = Average(CCI, cciAvgLength);
CCI.SetDefaultColor(GetColor(9));
CCIAvg.SetDefaultColor(GetColor(8));
def CCISlope = if CCI > CCI[-1] then 1 else 0 ; # 1 is UP, 0 is DOWN
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59 , high, if CCISLope == 1 then "CCI - Slope UP" else "CCI - Slope DOWN", if CCISlope == 1 then Color.GREEN else Color.RED);
#For testing/verification
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59 , high, "CCI Fast: " + CCI, Color.GREEN);
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59, high, "Previous CCI Fast: " + CCI[1], Color.GREEN);
declare lower;
input cciLength = 20;
input cciAvgLength = 15;
input price = close;
input length = 3;
input displace = 0;
def AvgExp = (ExpAverage(price[-displace], length));
plot CCI = CCI(length = cciLength);
plot CCIAvg = Average(CCI, cciAvgLength);
CCI.SetDefaultColor(GetColor(9));
CCIAvg.SetDefaultColor(GetColor(8));
def CCISlope = if CCI > CCI[-1] then 1 else 0 ; # 1 is UP, 0 is DOWN
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59 , high, if CCISLope == 1 then "CCI - Slope UP" else "CCI - Slope DOWN", if CCISlope == 1 then Color.GREEN else Color.RED);
#For testing/verification
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59 , high, "CCI Fast: " + CCI, Color.GREEN);
AddChartBubble(SecondsFromTime(1500) >= 0 and SecondsFromTime(1500) <= 59, high, "Previous CCI Fast: " + CCI[1], Color.GREEN);
Last edited: