Information

Username: aintDatCap
Member since: 12 Sep 2023
Last login: 14 Sep 2023
Status: Active

Activity

Where Created Comments
Algorithms 1 1
Forum Topics 0 0
Jobs 0 0

Last Algorithm Comments

AI
aintDatCap · 1 year ago

@YesOrNot sadly the source code still needs to be reviewed.

Here's the code:

using cAlgo.API;
using cAlgo.API.Indicators;


namespace cAlgo
{
    [Indicator(AccessRights = AccessRights.None)]
    public class LarryWilliamsLargeTradingIndex : Indicator
    {
        [Parameter(DefaultValue = 8)]
        public int Period { get; set; }

        [Output("BullishValue", LineColor = "Green", IsHistogram = true, Thickness = 2)]
        public IndicatorDataSeries BullishValue { get; set; }

        [Output("BearishValue", LineColor = "D4FE0000", IsHistogram = true, Thickness = 2)]
        public IndicatorDataSeries BearishValue { get; set; }

        [Output("Middle", LineColor = "FF737373", Thickness=1, LineStyle = LineStyle.Dots)]
        public IndicatorDataSeries Middle { get; set; }

        private MovingAverage movingAverage;        
        private AverageTrueRange averageTrueRange;


        protected override void Initialize()
        {
            //System.Diagnostics.Debugger.Launch();

            IndicatorDataSeries ma = CreateDataSeries();

            for(int i = 0; i < Bars.ClosePrices.Count; i++)
            {
                if (i < Period)
                    ma[i] = Bars.ClosePrices[i];
                else
                    ma[i] = Bars.ClosePrices[i] - Bars.ClosePrices[i - Period];
            }

            movingAverage = Indicators.SimpleMovingAverage(ma, Period);
            averageTrueRange = Indicators.AverageTrueRange(Period, MovingAverageType.Exponential);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            //var ma = (Bars.ClosePrices.LastValue - Bars.ClosePrices[index - Period]);

            var atr = averageTrueRange.Result[index];
            double result = movingAverage.Result[index] / atr  * 50;


            if (result < 0)
            {
                BearishValue[index] = result;
                BullishValue[index] = double.NaN;
            }
            else
            {
                BullishValue[index] = result;
                BearishValue[index] = double.NaN;
            }
            Middle[index] = 0;
        }

    }
}