コード例 #1
0
        public SimpleEvaluator(SymbolInformation symbol)
            : base(symbol)
        {
            this.tp   = Indicators.TP(symbol);
            this.psar = Indicators.PSAR(this.Symbol, 0.02, 0.02, 0.2);

            for (var i = 1; i <= 250; i++)
            {
                this.emas[i] = Indicators.EMA(symbol, SourceType.Close, i);
                //this.demas[i] = Indicators.DEMA(symbol, SourceType.Close, i);
                //this.temas[i] = Indicators.TEMA(symbol, SourceType.Close, i);
                this.smas[i] = Indicators.SMA(symbol, SourceType.Close, i);

                //this.emas[i] = Indicators.EMA(this.tp, i);
                //this.demas[i] = Indicators.DEMA(this.tp, i);
                //this.temas[i] = Indicators.TEMA(this.tp, i);
                //this.smas[i] = Indicators.SMA(this.tp, i);
            }
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: torfranz/QuotesCheck
        public Model(SymbolInformation symbol, Learner learner, double costOfTrades)
        {
            this.Symbol       = symbol;
            this.Learner      = learner;
            this.CostOfTrades = costOfTrades;

            // create additional data required for features
            this.High   = this.Symbol.High;
            this.Low    = this.Symbol.Low;
            this.Close  = this.Symbol.Close;
            this.Open   = this.Symbol.Open;
            this.Volume = this.Symbol.Volume;
            this.Days   = this.Symbol.Day;

            this.Ema20  = Indicators.EMA(this.Symbol, SourceType.Close, 20);
            this.Ema50  = Indicators.EMA(this.Symbol, SourceType.Close, 50);
            this.Ema200 = Indicators.EMA(this.Symbol, SourceType.Close, 200);
            this.RSI    = Indicators.RSI(this.Close, 50).Scale(0, 100, -1.0, 1);

            //this.KAMA = Indicators.KAMA(symbol, SourceType.Close, 50);
            this.ST = Indicators.ST(this.Symbol, 50, 3);
            (this.RelativeMACD, this.RelativeSignal) = Indicators.RelativeMACD(this.Close, 20, 200, 9, MovingAverage.EMA);
            this.RelativeMACD           = this.Scale(this.RelativeMACD, -0.15, 0.15);
            this.RelativeSignal         = this.Scale(this.RelativeSignal, -0.15, 0.15);
            this.Ema20_50               = this.Scale(Indicators.RelativeDistance(this.Ema20, this.Ema50), -0.20, 0.20);
            this.Ema50_200              = this.Scale(Indicators.RelativeDistance(this.Ema50, this.Ema200), -0.20, 0.20);
            this.Ema50_Close            = this.Scale(Indicators.RelativeDistance(this.Ema50, this.Close), -0.40, 0.40);
            this.St_Close               = this.Scale(Indicators.RelativeDistance(this.ST, this.Close), -0.30, 0.30);
            this.Vola                   = this.Scale(Indicators.VOLA(this.Symbol, SourceType.Close, 30, 250), 0, 0.7);
            this.obos                   = this.Scale(Indicators.OBOS(this.Symbol, 50), 0, 100);
            var(elrBullish, elrBearish) = Indicators.ELR(this.Symbol, 50);
            this.bullish                = this.Scale(Indicators.Ratio(elrBullish, this.Close), -0.10, 0.10);
            this.bearish                = this.Scale(Indicators.Ratio(elrBearish, this.Close), -0.10, 0.101);
            var(dmi, diPlus, diMinus)   = Indicators.DMI(this.Symbol, 50);
            this.dmi           = this.Scale(dmi, 0, 100);
            this.diPlus        = this.Scale(diPlus, 0, 100);
            this.diMinus       = this.Scale(diMinus, 0, 100);
            this.DayOfWeek     = Scale(Indicators.DayOfWeek(symbol), 0, 6);
            this.Month         = Scale(Indicators.Month(symbol), 1, 12);
            this.RelMacdSignal = this.Scale(Indicators.Distance(RelativeMACD, RelativeSignal), -0.1, 0.1);
            //var corr = new PearsonCorrelation();
            //var sim = corr.Similarity(this.Ema20, this.Ema20);
        }
コード例 #3
0
        public async Task <ChartView> EmaView(string symbol, string interval, int candles, DateTime dateFrom, int ema)
        {
            var listModel = new List <ChartWithEma>();

            var instrument = await _instrumentRepository.GetInstrument(symbol);

            var chart = await _chartRepository.GetChartRangeTimeAsync(symbol, interval, dateFrom, candles, instrument.Precision);

            var timeArray  = chart.Quotations.Select(x => x.Time.ConvertDateTimeToTicks()).ToArray();
            var openArray  = chart.Quotations.Select(x => x.Open).ToArray();
            var highArray  = chart.Quotations.Select(x => x.High).ToArray();
            var lowArray   = chart.Quotations.Select(x => x.Low).ToArray();
            var closeArray = chart.Quotations.Select(x => x.Close).ToArray();

            var emasH = Indicators.EMA(closeArray, ema);

            listModel.AddRange(chart.Quotations.Select(
                                   x => new ChartWithEma
            {
                Time  = x.Time.ConvertDateTimeToTicks(),
                Open  = x.Open,
                High  = x.High,
                Low   = x.Low,
                Close = x.Close,
            }));

            var buyTrades  = listModel.Where(x => x.TypeAction == "B").ToList();
            var sellTrades = listModel.Where(x => x.TypeAction == "S").ToList();
            var c          = CombineArrays(timeArray, openArray, highArray, lowArray, closeArray);

            var series = new List <dynamic>()
            {
                CombineArrays(timeArray, openArray, highArray, lowArray, closeArray),
                CombineArrays(timeArray.Skip(ema).ToArray(), emasH.Skip(ema).ToArray()),
            };
            var chartView = new ChartView {
                Series = series
            };

            return(chartView);
        }
コード例 #4
0
ファイル: PivotStrategy.cs プロジェクト: Filip555/Money-Maker
        // Ema - 44
        public Task Play(Pivot pivot, Chart chart, int ema, int stopLoss)
        {
            var emasH = Indicators.EMA(chart.Quotations.Select(x => x.Close).ToArray(), ema);

            for (int i = 0; i < emasH.Count(); i++)
            {
                chart.Quotations[i].AddEma(emasH[i]);
            }
            var openTransactions = Account.GetOpenTransaction(chart.Symbol);

            if (openTransactions == null)
            {
                var lastQuotation = chart.GetLastQuotation();
                if (lastQuotation.High < pivot.P && lastQuotation.Close > pivot.S1 && lastQuotation.Low < pivot.S1)
                {
                    if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S1, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.P, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.P, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S1, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
                else if (lastQuotation.High < pivot.S1 && lastQuotation.Close > pivot.S2)
                {
                    if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S2, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S1, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S1, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S2, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
                else if (lastQuotation.High < pivot.S2 && lastQuotation.Close > pivot.S3)
                {
                    if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S3, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S2, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S2, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.S3, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
                else if (lastQuotation.Low > pivot.P && lastQuotation.Close < pivot.R1)
                {
                    if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R1, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.P, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.P, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R1, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
                else if (lastQuotation.Low > pivot.R1 && lastQuotation.Close < pivot.R2)
                {
                    if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R2, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R1, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R1, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R2, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
                else if (lastQuotation.Low > pivot.R2 && lastQuotation.Close < pivot.R3)
                {
                    if (lastQuotation.Close > lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R3, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R2, 0));
                        var volumen            = GetVolumen(TypeTransaction.Buy);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                    else if (lastQuotation.Close < lastQuotation.EmaValue)
                    {
                        var takeProfit         = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R2, 0));
                        var stopLossAdditional = (int)Math.Abs(Math.Round(lastQuotation.Close - pivot.R3, 0));
                        var volumen            = GetVolumen(TypeTransaction.Sell);
                        if (takeProfit / stopLoss > 2)
                        {
                            Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(PivotStrategy).Name);
                        }
                    }
                }
            }
            return(Task.CompletedTask);
        }
コード例 #5
0
        public async Task <ChartView> SimulateView(string symbol, string interval)
        {
            var listModel = new List <ChartWithEma>();

            var symbols = await _instrumentRepository.GetInstruments();

            var instrument = symbols.FirstOrDefault(x => x.Symbol == symbol);

            var chartTakeProfit = await _chartRepository.GetChartAsync(instrument.Symbol, interval, 150, instrument.Precision);

            var takeProfit = (decimal)Math.Round((chartTakeProfit.Quotations
                                                  .Sum(x =>
            {
                var low = x.Low * Math.Pow(10, instrument.Precision);
                var high = x.High * Math.Pow(10, instrument.Precision);
                var pipsDiff = Math.Round(Math.Abs(low - high), 1);
                return(pipsDiff / 10);
            }) / chartTakeProfit.Quotations.Count()), 2);
            var chart = await _chartRepository.GetChartAsync(instrument.Symbol, interval, 10000, instrument.Precision);

            var emaValue = 50;
            var emasH    = Indicators.EMA(chart.Quotations.Select(x => x.Close).ToArray(), emaValue);

            for (int i = 0; i < emasH.Count(); i++)
            {
                chart.Quotations[i].AddEma(emasH[i]);
            }

            var quotations = chart.Quotations.ToArray();

            var timeArray  = quotations.Select(x => x.Time.ConvertDateTimeToTicks()).ToArray();
            var openArray  = quotations.Select(x => x.Open).ToArray();
            var highArray  = quotations.Select(x => x.High).ToArray();
            var lowArray   = quotations.Select(x => x.Low).ToArray();
            var closeArray = quotations.Select(x => x.Close).ToArray();

            listModel.AddRange(quotations.Select(
                                   x => new ChartWithEma
            {
                Time  = x.Time.ConvertDateTimeToTicks(),
                Open  = x.Open,
                High  = x.High,
                Low   = x.Low,
                Close = x.Close,
            }));

            var buyTrades  = listModel.Where(x => x.TypeAction == "B").ToList();
            var sellTrades = listModel.Where(x => x.TypeAction == "S").ToList();
            var c          = CombineArrays(timeArray, openArray, highArray, lowArray, closeArray);

            var series = new List <dynamic>()
            {
                CombineArrays(timeArray, openArray, highArray, lowArray, closeArray),
                CombineArrays(timeArray, emasH),
                GetTradeSignals(buyTrades.Select(x => x.Time).ToArray(), "B"),
                GetTradeSignals(sellTrades.Select(x => x.Time).ToArray(), "S")
            };
            var chartView = new ChartView {
                Series = series
            };

            return(chartView);
        }