Need help with my CCI indicator

Camelotnite

New member
I'm a big fan of CCI indicator. Hence I took the code and change it to a CCI indicator instead. The test results look amazing. There are some coding which I don't really understand (e.g. def CCI = 1 * (ChgRatio + 1)). Any comments will be much appreciated.

Code:
``````#######################start code
input length = 5;
input over_Bought = 100;
input over_Sold = -100;
input price = close;
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;

def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;

def CCI = 1 * (ChgRatio + 1);
def BULL = over_Sold;
def BEAR = over_Bought;
def UpSignal = if CCI crosses above BEAR then BEAR else Double.NaN;
def DownSignal = if CCI crosses below BULL then BULL else Double.NaN;

def Bearish = CCI crosses below 100;
def Bullish = CCI crosses above -100;

#For Orders

def Ent = CCI(length)."CCI" crosses above -100 ;
def Ext = CCI(length)."CCI" crosses below 100 or CCI(length)."CCI" >= 85;

#end code``````

That is not a CCI indicator. You are plotting the RSI and just naming it CCI.

Here's a CCI study on the upper price chart with buy/sell arrows you might like to check out

Code:
``````input length = 8;
input trigger = 45;
input arrowdisplacer = .00075; #Change by .001 increments to move arrows
input showallarrows = no; #show only one arrow per direction or all

def price = close + low + high;
def linDev = LinDev(price, length);
def CCI = if linDev == 0
then 0
else (price - Average(price, length)) / linDev / 0.015;

def Up = CCI[1] <= trigger and CCI > trigger;
def Down = CCI[1] >= -trigger and CCI < -trigger;

def count = if Up == 1 and count[1] == 0 then 1
else if count[1] >= 1 and CCI >= -trigger then count[1] + 1
else 0;
rec count1 = if Down == 1 and count1[1] == 0 then 1
else if count1[1] >= 1 and CCI <= trigger then count1[1] + 1
else 0;

plot ArrowUp = if (Up and showallarrows == no and count == 1) or (Up and showallarrows == yes)
then low * (1 - arrowdisplacer)
else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.Yellow);
ArrowUp.SetLineWeight(3);

plot ArrowDn = if Down and count1 == 1
then high * (1 + arrowdisplacer)
else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.Cyan);
ArrowDn.SetLineWeight(3);

AddLabel(yes, "CCI: " + Round(CCI, 0) + if CCI[1] < CCI then " UP" else " DN",
if CCI > 0 then if CCI[1] > CCI then Color.DARK_GREEN
else Color.GREEN else if CCI[1] < CCI then Color.DARK_RED
else  Color.RED);``````

Very nice - I am using it - works very well to show good entry and exit positions on SPY - Thank you

Not the exact question you're looking for?

87k+ Posts
322 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?