Exemple #1
0
        public void Calculate()
        {
            //var currentSampleCounter = Samples.IndexOf(Sample);

            var previousCandlesCount = Samples.Count(a => a.Candle.Timestamp < Sample.Candle.Timestamp);

            // For MFI
            if (previousCandlesCount > 0)
            {
                // This line uses a function in the candle class to set the Money Flow Change by passing the previous typical price
                var previousTypicalPrice = Samples.Where(a => a.Candle.Timestamp < Sample.Candle.Timestamp).OrderByDescending(a => a.Candle.Timestamp).Take(1).FirstOrDefault().TypicalPrice;

                MoneyFlowChange = Sample.TypicalPrice - previousTypicalPrice;
            }
            else
            {
                MoneyFlowChange = 0;
            }

            if (previousCandlesCount >= MFIPeriod - 1) // We have enough candles we can actually start calculating the MFI
            {
                // Have to start with MoneyFlowRatio
                // Positive flow gets the sum of all the raw money flow on days where money flow change was positive, negative flow is opposite.
                decimal?PositiveFlow = Samples.Where(a => a.Candle.Timestamp <= Sample.Candle.Timestamp).OrderByDescending(a => a.Candle.Timestamp).Take(MFIPeriod).Where(a => ((MFIIndicator)a.Indicators["mfi"]).MoneyFlowChange > 0).Sum(a => a.RawMoneyFlow);
                decimal?NegativeFlow = Samples.Where(a => a.Candle.Timestamp <= Sample.Candle.Timestamp).OrderByDescending(a => a.Candle.Timestamp).Take(MFIPeriod).Where(a => ((MFIIndicator)a.Indicators["mfi"]).MoneyFlowChange < 0).Sum(a => a.RawMoneyFlow);

                if (NegativeFlow != 0)
                {
                    MoneyFlowRatio = PositiveFlow / NegativeFlow;
                }

                MFI = 100 - (100 / (1 + MoneyFlowRatio));
            }
        }
Exemple #2
0
        public void Calculate()
        {
            double p1 = MACDEmaPeriod + 1;
            double MACDEMAMultiplier = Convert.ToDouble(2 / p1);

            MACDLine = (Sample.EMAshort.Value - Sample.EMAlong.Value); // default is 12EMA - 26EMA
            var previousCandlesCount = Samples.Count(a => a.Candle.Timestamp < Sample.Candle.Timestamp);


            if (previousCandlesCount == Sample.EMAlong.Period + MACDEmaPeriod - 1)
            {
                // Set this to SMA of MACDLine to seed it
                Signal = Samples.Where(a => a.Candle.Timestamp <= Sample.Candle.Timestamp).OrderByDescending(a => a.Candle.Timestamp).Take(MACDEmaPeriod).Average(a => (((MACDIndicator)a.Indicators["macd"]).MACDLine));
            }
            else if (previousCandlesCount > Sample.EMAlong.Period + MACDEmaPeriod - 1)
            {
                // We can calculate this EMA based off past Candle EMAs
                double?lastMACDSignalLine = ((MACDIndicator)Samples.Where(a => a.Candle.Timestamp < Sample.Candle.Timestamp).OrderByDescending(a => a.Candle.Timestamp).Take(1).FirstOrDefault().Indicators["macd"]).Signal;
                Signal = ((MACDLine - lastMACDSignalLine.Value) * MACDEMAMultiplier) + lastMACDSignalLine.Value;
            }
            Histogram = MACDLine - Signal;
        }
Exemple #3
0
 public override string ToString()
 {
     return(Label.Value + " " + SampleCountPerRecord.Value.ToString() + "/" + Samples.Count().ToString() + " ["
            + string.Join <TAL>(",", Samples.Skip(0).Take(10).ToArray()) + " ...]");
 }
 public override string ToString()
 {
     return("Channel: " + Channel + " Count: " + Samples.Count());
 }