AccumulativeSwingIndex and AacceleratorOscillator

Created at 17 Jul 2017, 17:40
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!
AC

acrigney

Joined 25.05.2017

AccumulativeSwingIndex and AacceleratorOscillator
17 Jul 2017, 17:40


Hi Guys,

              I am new to cAlgo but I really love your work and being able to move away from MT4! With direct c# code!!

But I am not getting valid numbers for these indicators.

Here is some test code

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class SampleTrendcBot : Robot
    {
        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        private AcceleratorOscillator _acceleratorOscillator;
        private AccumulativeSwingIndex _accumulativeSwingIndex;
        [Parameter("Limit Move", DefaultValue = 12)]
        public int LimitMove { get; set; }

        protected override void OnStart()
        {
        

            _acceleratorOscillator = Indicators.AcceleratorOscillator(MarketSeries);
            double value = _acceleratorOscillator.Result[0];
            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);

            var x = _accumulativeSwingIndex.Result[0];
            res = String.Format("AaccumulativeSwingIndex = {0}, time {1}", x, DateTime.Now.ToLocalTime());
            Print(res);
        }

        protected override void OnTick()
        {
            double value = _acceleratorOscillator.Result[0];
            res = String.Format("_acceleratorOscillator = {0}", value);
            Print(res);
            var x = _accumulativeSwingIndex.Result[0];
            res = String.Format("AaccumulativeSwingIndex = {0}, time {1}", x, DateTime.Now.ToLocalTime());
            Print(res);
            x = _accumulativeSwingIndex.Result[1];
            res = String.Format("AaccumulativeSwingIndex = {0}, time {1}", x, DateTime.Now.ToLocalTime());
            Print(res);
            x = _accumulativeSwingIndex.Result[2];
            res = String.Format("AaccumulativeSwingIndex = {0}, time {1}", x, DateTime.Now.ToLocalTime());
            Print(res);
        }
        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }


    }

}

 


@acrigney
Replies

Spotware
25 Jul 2017, 10:40

Dear acrigney,

Thanks for posting your question in the forum. We tried to run your cBot but the build fails with 11 errors. Community members will probably not spend their time fixing the cBot. You will increase your chances of getting an answer if you provide a cBot that is working and make your questions more specific. For example, you say that you don't get valid numbers for the indicators. What numbers do you get and what would you expect to get?

If you could provide us with a working cBot as well as some numbers that you think are not valid, we would be more than happy to have a look at it.

Best Regards,

cTrader Team


@Spotware

acrigney
02 Aug 2017, 06:52

RE:

Sorry guys its all good now. I am was just testing the indicators. I have big plans for your tool with AI stuff!!

Spotware said

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using GA.DataTypes;
using System.Diagnostics;
using AroonUpDownIndicator;
using GA.GATrader;
using GA.Algorithm.Strategies;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public partial class GATraderNew : Robot
    {
        private InstrumentPopulation _forexPopulation;
        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";
        private AcceleratorOscillator _acceleratorOscillator;

        private AccumulativeSwingIndex _accumulativeSwingIndex;
        [Parameter("Limit Move", DefaultValue = 12)]
        public int LimitMove { get; set; }
        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }
        private AroonUpDown _aroonUpDownIndicator;

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

        private AverageTrueRange _averageTrueRange;
        [Parameter(DefaultValue = 14)]
        public int AverageTrueRangePeriods { get; set; }
        [Parameter(DefaultValue = 0.002)]
        public double SimpleATRValue { get; set; }
        [Parameter("AverageTrueRange MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType AverageTrueRangeMAType { get; set; }

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

        [Parameter("MovingAverageMAType MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MovingAverageMAType { get; set; }

        private MovingAverage _movingAverage;

        protected override void OnStart()
        {
            Tech.IndicatorsAccessor = Indicators;
            _acceleratorOscillator = Indicators.AcceleratorOscillator();
            //var xx =acceleratorOscillator.;
            double value = _acceleratorOscillator.Result[0];
            //Debug.WriteLine("AcceleratorOscillator = {0}", value);
            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);

            var x = _accumulativeSwingIndex.Result[0];

            string res = String.Format("ASI {0}, {1} {2}", _accumulativeSwingIndex.Result.LastValue, _accumulativeSwingIndex.Result.Maximum(_accumulativeSwingIndex.Result.Count - 1), DateTime.Now.ToLocalTime());
            Print(res);

            _aroonUpDownIndicator = Indicators.GetIndicator<AroonUpDown>(AroonPeriods);

            x = _aroonUpDownIndicator.ResultAroonUp[0];
            var y = _aroonUpDownIndicator.ResultAroonUp[0];
            int c = _aroonUpDownIndicator.ResultAroonUp.Count;

            res = String.Format("AroonUpDownIndicator Up {0}, AroonUpDownIndicator down {1}, {2} count= {3}", _aroonUpDownIndicator.ResultAroonUp.LastValue, _aroonUpDownIndicator.ResultAroonDown.LastValue, DateTime.Now.ToLocalTime(), c);
            Print(res);

            _averageTrueRange = Indicators.AverageTrueRange(AverageTrueRangePeriods, AverageTrueRangeMAType);

            x = _averageTrueRange.Result[0];

            res = String.Format("AverageTrueRange {0} {1} count= {2}", _averageTrueRange.Result.LastValue, DateTime.Now.ToLocalTime(), _averageTrueRange.Result.Count);
            Print(res);

            _movingAverage = Indicators.MovingAverage(SourceSeries, MovingAveragePeriods, MovingAverageMAType);

            res = String.Format("MovingAverage {0} {1} count= {2}", _movingAverage.Result.LastValue, DateTime.Now.ToLocalTime(), _movingAverage.Result.Count);
            Print(res);

            //Indicators.Aroon(AroonPeriods);
            //fastMa = Indicators.MovingAverage(Source, FastPeriods, MAType);
            //Tech.FastMa = fastMa;
            //var x = Indicators.AverageTrueRange(AverageTrueRangePeriods, AverageTrueRangeMovingAverageType);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);

        }

        //protected override void OnTick()
        //{
        //    Print("Current value {0}", MarketSeries.Open.Last(0));
        //    // current value
        //    Print("Previous value {0}", MarketSeries.High.Last(1));
        //    // previous value
        //    Print("The server time is: {0}", Server.Time);
        //    Print(String.Format("tick start {0}", DateTime.Now.ToLocalTime()));
        //    //_acceleratorOscillator = Indicators.AcceleratorOscillator();
        //    ////var xx =acceleratorOscillator.;
        //    //double value = _acceleratorOscillator.Result[0];
        //    //Debug.WriteLine("AcceleratorOscillator = {0}", value);
        //    //_accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);

        //    //var x = _accumulativeSwingIndex.Result[0];

        //    //string res = String.Format("ASI {0}, {1} {2}", _accumulativeSwingIndex.Result.LastValue, _accumulativeSwingIndex.Result.Maximum(_accumulativeSwingIndex.Result.Count - 1), DateTime.Now.ToLocalTime());
        //    //Print(res);

        //    //x = _aroonUpDownIndicator.ResultAroonUp[0];
        //    //var y = _aroonUpDownIndicator.ResultAroonUp[0];
        //    //int c = _aroonUpDownIndicator.ResultAroonUp.Count;

        //    //res = String.Format("AroonUpDownIndicator Up {0}, AroonUpDownIndicator down {1}, {2} count= {3}", _aroonUpDownIndicator.ResultAroonUp.LastValue, _aroonUpDownIndicator.ResultAroonDown.LastValue, DateTime.Now.ToLocalTime(), c);
        //    //Print(res);
        //    //x = _averageTrueRange.Result[0];

        //    //res = String.Format("AverageTrueRange {0} {1} count= {2}", _averageTrueRange.Result.LastValue, DateTime.Now.ToLocalTime(), _averageTrueRange.Result.Count);
        //    //Print(res);

        //    //res = String.Format("MovingAverage {0} {1} count= {2}", _movingAverage.Result.LastValue, DateTime.Now.ToLocalTime(), _movingAverage.Result.Count);
        //    //Print(res);
        //    //Print(String.Format("hello {0}", DateTime.Now.ToLocalTime()));
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////fastMa = Indicators.MovingAverage(Source, FastPeriods, MAType);
        //    ////Tech.FastMa = fastMa;
        //    ////var x = Indicators.AverageTrueRange(AverageTrueRangePeriods, AverageTrueRangeMovingAverageType);
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////Indicators.Aroon(AroonPeriods);
        //    ////sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);
        //}

        protected override void OnBar()
        {
            Print("On Bar Start");
            _acceleratorOscillator = Indicators.AcceleratorOscillator();
            //var xx =acceleratorOscillator.;
            double value = _acceleratorOscillator.Result[0];
            Debug.WriteLine("AcceleratorOscillator = {0}", value);
            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);

            var x = _accumulativeSwingIndex.Result[0];

            string res = String.Format("ASI {0}, {1} {2}", _accumulativeSwingIndex.Result.LastValue, _accumulativeSwingIndex.Result.Maximum(_accumulativeSwingIndex.Result.Count - 1), DateTime.Now.ToLocalTime());
            Print(res);

            x = _aroonUpDownIndicator.ResultAroonUp[0];
            var y = _aroonUpDownIndicator.ResultAroonUp[0];
            int c = _aroonUpDownIndicator.ResultAroonUp.Count;

            res = String.Format("AroonUpDownIndicator Up {0}, AroonUpDownIndicator down {1}, {2} count= {3}", _aroonUpDownIndicator.ResultAroonUp.LastValue, _aroonUpDownIndicator.ResultAroonDown.LastValue, DateTime.Now.ToLocalTime(), c);
            Print(res);
            x = _averageTrueRange.Result[0];

            res = String.Format("AverageTrueRange {0} {1} count= {2}", _averageTrueRange.Result.LastValue, DateTime.Now.ToLocalTime(), _averageTrueRange.Result.Count);
            Print(res);

            res = String.Format("MovingAverage {0} {1} count= {2}", _movingAverage.Result.LastValue, DateTime.Now.ToLocalTime(), _movingAverage.Result.Count);
            Print(res);
            Print(String.Format("hello {0}", DateTime.Now.ToLocalTime()));
            Print("On Bar Stop");
            //Indicators.Aroon(AroonPeriods);
            //fastMa = Indicators.MovingAverage(Source, FastPeriods, MAType);
            //Tech.FastMa = fastMa;
            //var x = Indicators.AverageTrueRange(AverageTrueRangePeriods, AverageTrueRangeMovingAverageType);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //Indicators.Aroon(AroonPeriods);
            //sma = Indicators.GetIndicator<SampleSMA>(Source, SmaPeriod);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Dear acrigney,

Thanks for posting your question in the forum. We tried to run your cBot but the build fails with 11 errors. Community members will probably not spend their time fixing the cBot. You will increase your chances of getting an answer if you provide a cBot that is working and make your questions more specific. For example, you say that you don't get valid numbers for the indicators. What numbers do you get and what would you expect to get?

If you could provide us with a working cBot as well as some numbers that you think are not valid, we would be more than happy to have a look at it.

Best Regards,

cTradet Team

 


@acrigney