Exemple #1
0
        public PlotCollectionSet GetData(PlotCollectionSet dataset, int nDataIdx, int nLookahead, Guid?guid = null, bool bAddToParams = false)
        {
            EmaData data = GetEmaData(dataset, nDataIdx, nLookahead, bAddToParams);

            return(new PlotCollectionSet(new List <PlotCollection>()
            {
                data.DstData
            }));
        }
Exemple #2
0
        public EmaData GetEmaData(PlotCollectionSet dataset, int nDataIdx, int nLookahead = 0, bool bAddToParams = false)
        {
            EmaData data   = Pre(dataset, nDataIdx);
            MinMax  minmax = new MinMax();

            for (int i = 0; i < data.SrcData.Count; i++)
            {
                Process(data, i, minmax, nLookahead, bAddToParams);
            }

            data.DstData.SetMinMax(minmax);

            return(data);
        }
Exemple #3
0
        public double Process(EmaData data, int i, MinMax minmax = null, int nLookahead = 0, bool bAddToParams = false)
        {
            bool bActive = data.SrcData[i].Active;

            PlotCollection dataSrc = data.SrcData;
            PlotCollection dataDst = data.DstData;
            double         dfMult  = data.Multiplier;

            if (i < dataSrc.Count)
            {
                if (data.Index < m_config.Interval)
                {
                    if (bActive)
                    {
                        data.Total += dataSrc[i].Y;
                        data.Index++;
                        if (dataDst != null)
                        {
                            dataDst.Add(dataSrc[i].X, data.Total / (data.Index + 1), false, dataSrc[i].Index);
                        }
                    }
                    else
                    {
                        if (dataDst != null)
                        {
                            dataDst.Add(dataSrc[i].X, dataSrc[i].Y, false, dataSrc[i].Index);
                        }
                    }
                }
                else
                {
                    if (data.EMA == 0)
                    {
                        data.EMA = data.Total / m_config.Interval;
                    }

                    if (i < dataSrc.Count - nLookahead)
                    {
                        data.EMA = (dataSrc[i].Y - data.EMA) * data.Multiplier + data.EMA;
                    }
                    else
                    {
                        bActive = false;
                    }

                    if (dataDst != null)
                    {
                        dataDst.Add(data.EMA, bActive, dataSrc[i].Index);
                    }

                    if (bAddToParams && bActive)
                    {
                        dataSrc[i].SetParameter(dataDst.Name, (float)data.EMA);
                    }

                    if (minmax != null)
                    {
                        minmax.Add(data.EMA);
                    }
                }
            }

            return(data.EMA);
        }