Beispiel #1
0
        public static List <Model.Candle> HA_D_Candles(Instrument instrument, out InstrumentDayPrice instrumentDayPrice)
        {
            instrumentDayPrice = new InstrumentDayPrice();
            Model.Candle        haPreviounsCandle = null;
            Model.Candle        haCurrentCandle   = null;
            List <Model.Candle> haCandles         = new List <Candle>();
            List <Model.Candle> candles           = Data.Prices.GetCandles(instrument.Name, 22, "D");
            EMA ema = new EMA(22);

            for (int i = 0; i < candles.Count; i++)
            {
                instrumentDayPrice.Max     = Math.Max(instrumentDayPrice.Max, candles[i].Hight);
                instrumentDayPrice.Current = candles.LastOrDefault().Close;
                if (i == 0)
                {
                    instrumentDayPrice.Min = candles[i].Low;
                    instrumentDayPrice.Min = Math.Min(candles[i].Low, instrumentDayPrice.Min);
                    haPreviounsCandle      = Data.Candle.GeneratePrevious(candles[i]);
                    haCandles.Add(haPreviounsCandle);
                    //Console.WriteLine(haPreviounsCandle.OriginalColor);
                }

                else
                {
                    haCurrentCandle = Data.Candle.Generate(haPreviounsCandle, candles[i]);
                    //Console.WriteLine(haCurrentCandle.OriginalColor);
                    haCandles.Add(haCurrentCandle);
                    haPreviounsCandle = haCurrentCandle;
                }

                if (i < 5)
                {
                    ema.AddDataPoint(candles[i].Close);
                }
                else
                {
                    instrumentDayPrice.EMA = ema.Average;
                }
            }


            return(haCandles);
        }
Beispiel #2
0
        public static List <Model.Candle> HA_D_Candles(List <Model.Candle> D, out InstrumentDayPrice instrumentDayPrice)
        {
            instrumentDayPrice = new InstrumentDayPrice();
            Model.Candle        haPreviounsCandle = null;
            Model.Candle        haCurrentCandle   = null;
            List <Model.Candle> haCandles         = new List <Candle>();
            EMA ema = new EMA(5);

            for (int i = 0; i < D.Count; i++)
            {
                if (i == 0)
                {
                    instrumentDayPrice.Max     = Math.Max(instrumentDayPrice.Max, D[i].Hight);
                    instrumentDayPrice.Current = D.LastOrDefault().Close;
                    haPreviounsCandle          = Data.Candle.GeneratePrevious(D[i]);
                    haCandles.Add(haPreviounsCandle);
                }
                else
                {
                    haCurrentCandle = Data.Candle.Generate(haPreviounsCandle, D[i]);

                    haCandles.Add(haCurrentCandle);
                    haPreviounsCandle = haCurrentCandle;
                }

                if (i < 5)
                {
                    ema.AddDataPoint(D[i].Close);
                }
                else
                {
                    instrumentDayPrice.EMA = ema.Average;
                }
            }


            return(haCandles);
        }