Category Trend  Published on 02/05/2024

cciemas

Description

using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
   [Indicator(IsOverlay = true)]
   public class CciEma : Indicator
   {
       [Parameter("CCI Length", DefaultValue = 7, MinValue = 1)]
       public int CciLength { get; set; }

       [Parameter("EMA 1 Length", DefaultValue = 10)]
       public int Ema1Length { get; set; }

       [Parameter("EMA 2 Length", DefaultValue = 30)]
       public int Ema2Length { get; set; }

       [Output("CCI", Color = Colors.Blue)]
       public IndicatorDataSeries Cci { get; set; }

       [Output("EMA 1", Color = Colors.Red)]
       public IndicatorDataSeries Ema1 { get; set; }

       [Output("EMA 2", Color = Colors.Green)]
       public IndicatorDataSeries Ema2 { get; set; }

       protected override void Initialize()
       {
           // Initialize and add EMA indicators
           Ema1 = EMA(MarketSeries.Close, Ema1Length);
           Ema2 = EMA(MarketSeries.Close, Ema2Length);

           // Initialize CCI indicator
           Cci = (MarketSeries.Close - SMA(MarketSeries.Close, CciLength)) / (0.015 * StdDev(MarketSeries.Close, CciLength));
       }

       public override void Calculate(int index)
       {
           // Calculate CCI and EMA values
           double cciValue = Cci.Result[index];
           double ema1Value = Ema1.Result[index];
           double ema2Value = Ema2.Result[index];

           // Plot signals
           if (ema1Value >= ema2Value && cciValue > -100)
               ChartObjects.DrawTriangle("BuySignal" + index, index, MarketSeries.Low[index] - Symbol.PipSize, Colors.Green);
           else if (ema1Value <= ema2Value && cciValue < 100)
               ChartObjects.DrawTriangle("SellSignal" + index, index, MarketSeries.High[index] + Symbol.PipSize, Colors.Red);

           // Raise alerts
           if (ema1Value >= ema2Value && cciValue > -100)
               Notifications.PlaySound("BuyAlert.wav");
           else if (ema1Value <= ema2Value && cciValue < 100)
               Notifications.PlaySound("SellAlert.wav");
       }
   }
}


using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    [Levels(100, -100)]

    public class CCI : Indicator
    {
        private CommodityChannelIndex cci;

        private double g_icci_140;
        private double g_icci_148;


        [Parameter("CCI Period", DefaultValue = 50)]
        public int CciPeriod { get; set; }

        [Parameter("Momentum", DefaultValue = 40)]
        public int Momentum { get; set; }

        [Output("Gray", LineColor = "Gray", IsHistogram = true, Thickness = 1)]
        public IndicatorDataSeries g_ibuf_164 { get; set; }

        [Output("Blue", LineColor = "Blue", IsHistogram = true, Thickness = 4)]
        public IndicatorDataSeries g_ibuf_168 { get; set; }

        [Output("Red", LineColor = "Red", IsHistogram = true, Thickness = 4)]
        public IndicatorDataSeries g_ibuf_176 { get; set; }

        protected override void Initialize()
        {
            cci = Indicators.CommodityChannelIndex(CciPeriod);
        }

        public override void Calculate(int index)
        {
            g_icci_140 = cci.Result[index];
            g_icci_148 = cci.Result[index - 1];

            g_ibuf_164[index] = 0;
            g_ibuf_168[index] = 0;
            g_ibuf_176[index] = 0;

            if ((g_icci_140 - g_icci_148) < (-Momentum))
                g_ibuf_176[index] = g_icci_140;
            else if ((g_icci_140 - g_icci_148) > (Momentum))
                g_ibuf_168[index] = g_icci_140;
            else
                g_ibuf_164[index] = g_icci_140;
        }
    }
}


TO
tomasz.suszycki

Joined on 09.04.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: CCI Histogram.algo
  • Rating: 0
  • Installs: 128
Comments
Log in to add a comment.
No comments found.