Parabolic SAR Indicator fix required (Won't Build)

Created at 20 Oct 2017, 07:46
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AM

amsman

Joined 22.11.2016

Parabolic SAR Indicator fix required (Won't Build)
20 Oct 2017, 07:46


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.EAustraliaStandardTime, AccessRights = AccessRights.None)]
    public class ParabolicSAR : Indicator
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double minaf { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double maxaf { get; set; }
        
        private ParabolicSAR _parabolic;
        
        [Output("PSAR", PlotType = PlotType.Points, Color = Colors.White, Thickness = 3)]
        public IndicatorDataSeries _parabolic { get; set; }
      
        protected override void Initialize()
        {
            _parabolic = Indicators.ParabolicSAR(minaf, maxaf);          
        }
        public override void Calculate(int index)
        {
            double parabolic = _parabolic.Result[index];
         }
    }
}

I believe Spotware don't want to share their "built in" cTrader Indicators so I coded simple versions of the RSI, CCI which all work fine but I cannot get the PSAR Indicator to build...probably something simple. Can someone please sort for me?

PS: I am coding them so I can build a range of standalone (with more functionality) indicators, If anyone wants the code for the other base Indicators, speak up and I will post them in the Indicator thread/forum. Cheers


@amsman
Replies

amsman
20 Oct 2017, 07:50

RE:

Error CS0102: The type 'cAlgo.ParabolicSAR' already contains a definition for '_parabolic'

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.EAustraliaStandardTime, AccessRights = AccessRights.None)]
    public class ParabolicSAR : Indicator
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double minaf { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double maxaf { get; set; }
        
        private ParabolicSAR _parabolic;
        
        [Output("PSAR", PlotType = PlotType.Points, Color = Colors.White, Thickness = 3)]
        public IndicatorDataSeries _parabolic { get; set; }
      
        protected override void Initialize()
        {
            _parabolic = Indicators.ParabolicSAR(minaf, maxaf);          
        }
        public override void Calculate(int index)
        {
            double parabolic = _parabolic.Result[index];
         }
    }
}

I believe Spotware don't want to share their "built in" cTrader Indicators so I coded simple versions of the RSI, CCI which all work fine but I cannot get the PSAR Indicator to build...probably something simple. Can someone please sort for me?

PS: I am coding them so I can build a range of standalone (with more functionality) indicators, If anyone wants the code for the other base Indicators, speak up and I will post them in the Indicator thread/forum. Cheers

 


@amsman

PanagiotisCharalampous
20 Oct 2017, 12:19

Hi amsman,

The reason you cannot build your indicator is that you define _parabolic twice and you do not use the correct type in your indicator declaration. See a corrected version below

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.EAustraliaStandardTime, AccessRights = AccessRights.None)]
    public class ParabolicSAR : Indicator
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double minaf { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double maxaf { get; set; }

        [Output("PSAR", PlotType = PlotType.Points, Color = Colors.White, Thickness = 3)]
        public API.Indicators.ParabolicSAR _parabolic { get; set; }

        protected override void Initialize()
        {
            _parabolic = Indicators.ParabolicSAR(minaf, maxaf);
        }
        public override void Calculate(int index)
        {
            double parabolic = _parabolic.Result[index];
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

amsman
20 Oct 2017, 14:44

RE:

Panagiotis Charalampous said:

Hi amsman,

The reason you cannot build your indicator is that you define _parabolic twice and you do not use the correct type in your indicator declaration. See a corrected version below

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.EAustraliaStandardTime, AccessRights = AccessRights.None)]
    public class ParabolicSAR : Indicator
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double minaf { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double maxaf { get; set; }

        [Output("PSAR", PlotType = PlotType.Points, Color = Colors.White, Thickness = 3)]
        public API.Indicators.ParabolicSAR _parabolic { get; set; }

        protected override void Initialize()
        {
            _parabolic = Indicators.ParabolicSAR(minaf, maxaf);
        }
        public override void Calculate(int index)
        {
            double parabolic = _parabolic.Result[index];
        }
    }
}

Best Regards,

Panagiotis

Thanks for the prompt reply Panagiotis, Code is now building but still not displaying the PSAR Indicator on the Chart (Indicator(IsOverlay = false changed to true)


@amsman

PanagiotisCharalampous
20 Oct 2017, 16:20

Hi amsman,

Apologies, i thought you just wanted to resolve the build errors. See below a properly working Parabolic SAR custom indicator

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.EAustraliaStandardTime, AccessRights = AccessRights.None)]
    public class ParabolicSAR : Indicator
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double minaf { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double maxaf { get; set; }

        public API.Indicators.ParabolicSAR _parabolic { get; set; }

        [Output("PSAR", PlotType = PlotType.Points, Color = Colors.White, Thickness = 3)]
        public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            _parabolic = Indicators.ParabolicSAR(minaf, maxaf);
        }
        public override void Calculate(int index)
        {
            Result[index] = _parabolic.Result[index];
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

amsman
21 Oct 2017, 03:21

Works perfectly, appreciate the prompt reply again Panagiotis. Your help on these forums is adding value to the platform.


@amsman