Back

Could someone give me an example on how to use CCI

 I have been playing around with quantconnect using other people's algos and changing them . I am a Beginner on coding/algo trading in gereral XD. So could someone give me a example on using CCI. I want to use 4 of them 14,50,100,200 periods. So the buy conditions when 14 period crosses up -100 while the persistant of the other 3 longer period CCI is greater than 0. And the sell condition being when any of the 50,100,200 period dipping below -100

examples:

https://www.tradingview.com/x/Df6eCWzS/

 

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


heres what I have rn but for somereason it doesnt work 

class Quadcci(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2007, 1, 1)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        
        self.AddEquity("spy", Resolution.Daily,)
      
        self.Fast = self.CCI("spy", 14,  MovingAverageType.Simple, Resolution.Daily)
        self.Med = self.CCI("spy", 50,  MovingAverageType.Simple, Resolution.Daily)
        self.CCIupperBound = 100 # CCI upper bound line
        self.CCIlowerBound = -100 # CCI lower bound 
        self.CCIBaseLine = 0 # cci baseline

        
    def OnData(self, data):
        # get current price of Spy
        holdings = self.Portfolio["spy"].Quantity
        price = self.Securities["spy"].Close
        
        
        # buy if price closes above upper bollinger band
        if holdings <= 0:
               if self.Fast and self.Med > self.CCIupperBound:
                self.SetHoldings("spy", 1.0)
        
        # sell if price closes below middle bollinger band
        if holdings > 0 and self.Fast and self.Med < self.CCIupperBound:
                self.Liquidate()

 

 

0

Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed