Category Oscilators  Published on 25/01/2023

AboveBelow Zone

Description

The 'AboveBelow Zone' is a custom indicator that provides an average of which side of the price exponential smooth has closed without the noise of the chart. 

It is useful for measuring trade zones or as a trade filter (e.g., only go long if above, go short if below).

 


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

namespace cAlgo
{
    [Levels(0)]
    [Cloud("Zone", "Levelzero", FirstColor = "ForestGreen", SecondColor = "Orange", Opacity = 0.3)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mAboveBelow : Indicator
    {
        [Parameter("Period (9)", DefaultValue = 9, Group = "Indicator")]
        public int inpPeriod { get; set; }
        [Parameter("Smooth Type (ema)", DefaultValue = MovingAverageType.Exponential, Group = "Indicator")]
        public MovingAverageType inpSmoothType { get; set; }

        [Output("Zone", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outABZone { get; set; }
        [Output("Levelzero", LineColor = "Transparent", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries outLevelZero { get; set; }

        private IndicatorDataSeries _above, _below, _abo;
        private MovingAverage _pricesmooth, _abosmooth;


        protected override void Initialize()
        {
            _above = CreateDataSeries();
            _below = CreateDataSeries();
            _abo = CreateDataSeries();
            _pricesmooth = Indicators.MovingAverage(Bars.ClosePrices, inpPeriod, inpSmoothType);
            _abosmooth = Indicators.MovingAverage(_abo, inpPeriod, inpSmoothType);
        }

        public override void Calculate(int i)
        {
            _above[i] = (Bars.ClosePrices[i] > _pricesmooth.Result[i] ? Bars.ClosePrices[i] - _pricesmooth.Result[i] : 0.0);
            _below[i] = (Bars.ClosePrices[i] < _pricesmooth.Result[i] ? Bars.ClosePrices[i] - _pricesmooth.Result[i] : 0.0);
            _abo[i] = _above[i] + _below[i];

            outABZone[i] = _abosmooth.Result[i];
            outLevelZero[i] = 0;
        }
    }
}

mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mAboveBelow.algo
  • Rating: 0
  • Installs: 417
  • Modified: 20/11/2023 12:17
Comments
Log in to add a comment.
No comments found.