Parabolic SAR oscillator free

by mfejza in category Oscilator at 19/05/2023
Description

The Parabolic SAR indicator is transformed into an oscillator by displaying the simple smoothed difference between the PSAR indicator and price.

In this version, a positive difference value in the indicator indicates a bullish market sentiment, while a negative difference value indicates a bearish market sentiment.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class mPSARosc : Indicator
    {
        [Parameter("PSAR Step (0.02)", DefaultValue = 0.02)]
        public double inpStep { get; set; }
        [Parameter("PSAR Max (0.2)", DefaultValue = 0.2)]
        public double inpMax { get; set; }
        [Parameter("Smooth Period (7)", DefaultValue = 7)]
        public int inpSmoothPeriod { get; set; }

        [Output("PSAR Osc Positive", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 3, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries outPSARoscPositive { get; set; }
        [Output("PSAR Osc Negative", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 3, LineStyle = LineStyle.Solid)]
        public IndicatorDataSeries outPSARoscNegative { get; set; }
        
        private ParabolicSAR _psar;
        private IndicatorDataSeries _raw, _psaroscpos, _psaroscneg;
        private MovingAverage _smoothaverage;

        protected override void Initialize()
        {
            _psar = Indicators.ParabolicSAR(inpStep, inpMax);
            _raw = CreateDataSeries();
            _psaroscpos = CreateDataSeries();
            _psaroscneg = CreateDataSeries();
            _smoothaverage = Indicators.MovingAverage(_raw, inpSmoothPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int i)
        {
            _raw[i] = Bars.ClosePrices[i] - _psar.Result[i];
            _psaroscpos[i] = i>inpSmoothPeriod && _smoothaverage.Result[i] > _smoothaverage.Result[i-1] ? _smoothaverage.Result[i] : 0;
            _psaroscneg[i] = i>inpSmoothPeriod && _smoothaverage.Result[i] < _smoothaverage.Result[i-1] ? _smoothaverage.Result[i] : 0;
            
            outPSARoscPositive[i] = _psaroscpos[i];
            outPSARoscNegative[i] = _psaroscneg[i];
        }
    }
}
Comments
0