Ejemplo n.º 1
0
        // ON-BALANCE VOLUME
        public static IEnumerable <AdlResult> GetAdl(IEnumerable <Quote> history)
        {
            // clean quotes
            Cleaners.PrepareHistory(history);

            // check parameters
            ValidateAdl(history);

            // initialize
            List <AdlResult> results = new List <AdlResult>();
            decimal          prevAdl = 0;

            // get money flow multiplier
            foreach (Quote h in history)
            {
                decimal mfm = (h.High == h.Low) ? 0 : ((h.Close - h.Low) - (h.High - h.Close)) / (h.High - h.Low);
                decimal mfv = mfm * h.Volume;
                decimal adl = mfv + prevAdl;

                AdlResult result = new AdlResult
                {
                    Index = (int)h.Index,
                    Date  = h.Date,
                    MoneyFlowMultiplier = mfm,
                    MoneyFlowVolume     = mfv,
                    Adl = adl
                };
                results.Add(result);

                prevAdl = adl;
            }

            return(results);
        }
Ejemplo n.º 2
0
        // CHAIKIN MONEY FLOW
        /// <include file='./info.xml' path='indicator/*' />
        ///
        public static IEnumerable <CmfResult> GetCmf <TQuote>(
            IEnumerable <TQuote> history,
            int lookbackPeriod = 20)
            where TQuote : IQuote
        {
            // sort history
            List <TQuote> historyList = history.Sort();

            // check parameter arguments
            ValidateCmf(history, lookbackPeriod);

            // initialize
            List <CmfResult> results    = new List <CmfResult>(historyList.Count);
            List <AdlResult> adlResults = GetAdl(history).ToList();

            // roll through history
            for (int i = 0; i < adlResults.Count; i++)
            {
                AdlResult r     = adlResults[i];
                int       index = i + 1;

                CmfResult result = new CmfResult
                {
                    Date = r.Date,
                    MoneyFlowMultiplier = r.MoneyFlowMultiplier,
                    MoneyFlowVolume     = r.MoneyFlowVolume
                };

                if (index >= lookbackPeriod)
                {
                    decimal sumMfv = 0;
                    decimal sumVol = 0;

                    for (int p = index - lookbackPeriod; p < index; p++)
                    {
                        TQuote h = historyList[p];
                        sumVol += h.Volume;

                        AdlResult d = adlResults[p];
                        sumMfv += d.MoneyFlowVolume;
                    }

                    decimal avgMfv = sumMfv / lookbackPeriod;
                    decimal avgVol = sumVol / lookbackPeriod;

                    if (avgVol != 0)
                    {
                        result.Cmf = avgMfv / avgVol;
                    }
                }

                results.Add(result);
            }

            return(results);
        }
Ejemplo n.º 3
0
        // CHAIKIN MONEY FLOW
        public static IEnumerable <CmfResult> GetCmf(IEnumerable <Quote> history, int lookbackPeriod = 20)
        {
            // clean quotes
            List <Quote> historyList = Cleaners.PrepareHistory(history).ToList();

            // check parameters
            ValidateCmf(history, lookbackPeriod);

            // initialize
            List <CmfResult> results    = new List <CmfResult>();
            List <AdlResult> adlResults = GetAdl(history).ToList();

            // roll through history
            for (int i = 0; i < adlResults.Count; i++)
            {
                AdlResult r = adlResults[i];

                CmfResult result = new CmfResult
                {
                    Index = r.Index,
                    Date  = r.Date,
                    MoneyFlowMultiplier = r.MoneyFlowMultiplier,
                    MoneyFlowVolume     = r.MoneyFlowVolume
                };

                if (r.Index >= lookbackPeriod)
                {
                    decimal sumMfv = 0;
                    decimal sumVol = 0;

                    for (int p = r.Index - lookbackPeriod; p < r.Index; p++)
                    {
                        Quote h = historyList[p];
                        sumVol += h.Volume;

                        AdlResult d = adlResults[p];
                        sumMfv += d.MoneyFlowVolume;
                    }

                    decimal avgMfv = sumMfv / lookbackPeriod;
                    decimal avgVol = sumVol / lookbackPeriod;

                    if (avgVol != 0)
                    {
                        result.Cmf = avgMfv / avgVol;
                    }
                }

                results.Add(result);
            }

            return(results);
        }
Ejemplo n.º 4
0
        // ACCUMULATION/DISTRIBUTION LINE
        /// <include file='./info.xml' path='indicator/*' />
        ///
        public static IEnumerable <AdlResult> GetAdl <TQuote>(
            IEnumerable <TQuote> history,
            int?smaPeriod = null)
            where TQuote : IQuote
        {
            // sort history
            List <TQuote> historyList = history.Sort();

            // check parameter arguments
            ValidateAdl(history, smaPeriod);

            // initialize
            List <AdlResult> results = new List <AdlResult>(historyList.Count);
            decimal          prevAdl = 0;

            // roll through history
            for (int i = 0; i < historyList.Count; i++)
            {
                TQuote h     = historyList[i];
                int    index = i + 1;

                decimal mfm = (h.High == h.Low) ? 0 : ((h.Close - h.Low) - (h.High - h.Close)) / (h.High - h.Low);
                decimal mfv = mfm * h.Volume;
                decimal adl = mfv + prevAdl;

                AdlResult result = new AdlResult
                {
                    Date = h.Date,
                    MoneyFlowMultiplier = mfm,
                    MoneyFlowVolume     = mfv,
                    Adl = adl
                };
                results.Add(result);

                prevAdl = adl;

                // optional SMA
                if (smaPeriod != null && index >= smaPeriod)
                {
                    decimal sumSma = 0m;
                    for (int p = index - (int)smaPeriod; p < index; p++)
                    {
                        sumSma += results[p].Adl;
                    }

                    result.AdlSma = sumSma / smaPeriod;
                }
            }

            return(results);
        }
Ejemplo n.º 5
0
        // ACCUMULATION / DISTRIBUTION LINE
        public static IEnumerable <AdlResult> GetAdl(IEnumerable <Quote> history, int?smaPeriod = null)
        {
            // clean quotes
            history = Cleaners.PrepareHistory(history);

            // check parameters
            ValidateAdl(history, smaPeriod);

            // initialize
            List <AdlResult> results = new List <AdlResult>();
            decimal          prevAdl = 0;

            // get money flow multiplier
            foreach (Quote h in history)
            {
                decimal mfm = (h.High == h.Low) ? 0 : ((h.Close - h.Low) - (h.High - h.Close)) / (h.High - h.Low);
                decimal mfv = mfm * h.Volume;
                decimal adl = mfv + prevAdl;

                AdlResult result = new AdlResult
                {
                    Index = (int)h.Index,
                    Date  = h.Date,
                    MoneyFlowMultiplier = mfm,
                    MoneyFlowVolume     = mfv,
                    Adl = adl
                };
                results.Add(result);

                prevAdl = adl;

                // optional SMA
                if (smaPeriod != null && h.Index >= smaPeriod)
                {
                    decimal sumSma = 0m;
                    for (int p = (int)h.Index - (int)smaPeriod; p < h.Index; p++)
                    {
                        sumSma += results[p].Adl;
                    }

                    result.Sma = sumSma / smaPeriod;
                }
            }

            return(results);
        }