Topics

Forum Topics not found

Replies

kalex718
16 Dec 2013, 15:21

This robot looks for a position by label and closes it if MA (type defined by input) crosses Lwma (/algos/indicators/show/81)

 

using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC)]
    public class CrossingRobot : Robot
    {
        private MovingAverage movingAverage;
        private Lwma lwma;

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

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

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


        [Parameter(DefaultValue = "Crossing Robot")]
        public string Label { get; set; }
        
        protected override void OnStart()
        {
            movingAverage = Indicators.MovingAverage(SourceSeries, MaPeriods, MAType);
            lwma = Indicators.GetIndicator<Lwma>(SourceSeries, LwmaPeriods);

        }

        protected override void OnTick()
        {
            var position = Positions.Find(Label);
            if (position == null)
                return;

            if (movingAverage.Result.HasCrossedAbove(lwma.Result, 0))
                ClosePosition(position);
        }

    }
}

 


@kalex718

kalex718
13 Sep 2012, 10:03

Hello,

Gann HiLo is uploaded to the CTDN: /algos/show/172

Good Luck!


@kalex718