My current IndicatorBase page

I plan on adding a bunch of technical indicators here on my blog. This is where I’ll (aim) to keep the latest version of my IndicatorBase class.

    
	public abstract class IndicatorBase
    {
        protected CandleSeries Series { get; set; } 
        protected int RequiredCount { get; set; }
        protected bool HasRequiredCandleCount => Series.Length > RequiredCount;
        protected bool IsLastCandle = false;
        protected virtual void Initialize() { }
        public abstract void Compute(int startIndex = 0, int? endIndex = null);
  
        public IndicatorBase(IEnumerable<Candle> source) 
        {
            var ordered = source.OrderBy(x => x.Timestamp).DistinctBy(x => x.Timestamp);
            Series = new CandleSeries(ordered);
            Initialize();
        }
    }

CandleSeries class

I’m still a bit up in the air on this, but I wanted to make it work like ThinkScript or Pine script where you can index into different pieces of the candle.

    	
	public class CandleSeries
    {
        public int Length = 0; 
        public decimal[] Close { get; set; } 
        public decimal[] Open { get; set; } 
        public decimal[] Low { get; set; } 
        public decimal[] High { get; set; } 
        public decimal[] Average { get; set; } 
        public decimal[] Volume { get; set; } 
        public DateTimeOffset[] Timestamp { get; set; }
        public Candle[] Source { get; set; }

        public CandleSeries(Candle[] source)
        {
            Length = source.Length;
            Close = new decimal[source.Length];
            Open = new decimal[source.Length];
            High = new decimal[source.Length];
            Low = new decimal[source.Length];
            Average = new decimal[source.Length];
            Volume = new decimal[source.Length];
            Timestamp = new DateTimeOffset[source.Length];
            Source = source;

            for (int i = 0; i < source.Length; i++)
            {
                Close[i] = source[i].Close;
                Open[i] = source[i].Open;

                var high = source[i].High;
                var low = source[i].Low;
                High[i] = high;
                Low[i] = low;
                Average[i] = (high + low) / 2;
                Volume[i] = source[i].Volume;
                Timestamp[i] = source[i].Timestamp;
            }
        }

        public CandleSeries(IEnumerable source) : this(source.ToArray()) { }
    }
In Tags ,