Category Oscilators  Published on 16/08/2023

RateOfChange Bands indicator

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

The Rate Of Change Bands were created by Vitali Apirine (Stocks and Commodities, March 2021, pg. 14). 

This indicator is a great method not only to check the momentum but also to assess the trend strength. 

When we use the Rate of Change (ROC) with values above and below certain bands, it helps us understand the pressure behind the price momentum.

To make it simpler, think of using this indicator by itself in four different timeframes: 10, 50, 100, and 200. This combination helps us figure out how fast prices are changing and the overall feeling in the market.

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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mROCbands : Indicator
    {
        [Parameter("Main Period (12)", DefaultValue = 12)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Period (3)", DefaultValue = 3)]
        public int inpPeriodSmooth { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("ROC Bands", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSC { get; set; } 
        [Output("ROC Band Up", LineColor = "Rec", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCup { get; set; } 
        [Output("ROC Band Down", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCdn { get; set; } 
        
        private IndicatorDataSeries _price, _rocsquare, _deviation;
        private PriceROC _rocprice;
        private MovingAverage _rocsmooth, _smoothsquare;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _rocsquare = CreateDataSeries();
            _deviation = CreateDataSeries();
            _rocprice = Indicators.PriceROC(_price, inpPeriod);
            _rocsmooth = Indicators.MovingAverage(_rocprice.Result, inpPeriodSmooth, MovingAverageType.Exponential);
            _smoothsquare = Indicators.MovingAverage(_rocsquare, inpPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _rocsquare[i] = Math.Pow(_rocprice.Result[i], 2);
            _deviation[i] = Math.Sqrt(_smoothsquare.Result[i]);
            
            outOSC[i] = _rocsmooth.Result[i];
            outOSCup[i] = _deviation[i];
            outOSCdn[i] = -_deviation[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}



mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mROCbands.algo
  • Rating: 5
  • Installs: 514
  • Modified: 16/08/2023 13:44
Comments
Log in to add a comment.
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mROCbands : Indicator
    {
        [Parameter("Main Period (12)", DefaultValue = 12)]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Period (3)", DefaultValue = 3)]
        public int inpPeriodSmooth { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("ROC Bands", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSC { get; set; } 
        [Output("ROC Band Up", LineColor = "Rec", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCup { get; set; } 
        [Output("ROC Band Down", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCdn { get; set; } 
        
        private IndicatorDataSeries _price, _rocsquare, _deviation;
        private PriceROC _rocprice;
        private MovingAverage _rocsmooth, _smoothsquare;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _rocsquare = CreateDataSeries();
            _deviation = CreateDataSeries();
            _rocprice = Indicators.PriceROC(_price, inpPeriod);
            _rocsmooth = Indicators.MovingAverage(_rocprice.Result, inpPeriodSmooth, MovingAverageType.Exponential);
            _smoothsquare = Indicators.MovingAverage(_rocsquare, inpPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _rocsquare[i] = Math.Pow(_rocprice.Result[i], 2);
            _deviation[i] = Math.Sqrt(_smoothsquare.Result[i]);
            
            outOSC[i] = _rocsmooth.Result[i];
            outOSCup[i] = _deviation[i];
            outOSCdn[i] = -_deviation[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}
mfejza's avatar
mfejza · 1 year ago
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mROCbands : Indicator
    {
        [Parameter("Fast Period (12)", DefaultValue = 12)]
        public int inpPeriodFast { get; set; }
        [Parameter("Slow Period (3)", DefaultValue = 3)]
        public int inpPeriodSlow { get; set; }
        [Parameter("Signal Period (12)", DefaultValue = 12)]
        public int inpPeriodSignal { get; set; }
        [Parameter("Data Source (close)", DefaultValue = enumPriceTypes.Close)]
        public enumPriceTypes inpPriceType { get; set; }

        [Output("ROC Bands", LineColor = "Black", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSC { get; set; } 
        [Output("ROC Band Up", LineColor = "Rec", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCup { get; set; } 
        [Output("ROC Band Down", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries outOSCdn { get; set; } 
        
        private IndicatorDataSeries _price, _rocsquare, _deviation;
        private PriceROC _rocprice;
        private MovingAverage _rocsmooth, _smoothsquare;
        

        protected override void Initialize()
        {
            _price = CreateDataSeries();
            _rocsquare = CreateDataSeries();
            _deviation = CreateDataSeries();
            _rocprice = Indicators.PriceROC(_price, inpPeriodFast);
            _rocsmooth = Indicators.MovingAverage(_rocprice.Result, inpPeriodSlow, MovingAverageType.Exponential);
            _smoothsquare = Indicators.MovingAverage(_rocsquare, inpPeriodSignal, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            switch (inpPriceType)
            {
                case enumPriceTypes.Open:
                    _price[i] = Bars.OpenPrices[i];
                    break;
                case enumPriceTypes.Close:
                    _price[i] = Bars.ClosePrices[i];
                    break;
                case enumPriceTypes.High:
                    _price[i] = Bars.HighPrices[i];
                    break;
                case enumPriceTypes.Low:
                    _price[i] = Bars.LowPrices[i];
                    break;
                case enumPriceTypes.Median:
                    _price[i] = Bars.MedianPrices[i];
                    break;
                case enumPriceTypes.Typical:
                    _price[i] = Bars.TypicalPrices[i];
                    break;
                case enumPriceTypes.Weighted:
                    _price[i] = Bars.WeightedPrices[i];
                    break;
                default:
                    _price[i] = Bars.ClosePrices[i];
                    break;
            }
            _rocsquare[i] = Math.Pow(_rocprice.Result[i], 2);
            _deviation[i] = Math.Sqrt(_smoothsquare.Result[i]);
            
            outOSC[i] = _rocsmooth.Result[i];
            outOSCup[i] = _deviation[i];
            outOSCdn[i] = -_deviation[i];
        }
    }
    
    public enum enumPriceTypes
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}