public void Play(Chart chart) { var highLastDay = chart.GetLastDayQuotations(DateTime.Now).Where(w => w.IsInEuropeTimeFrame())?.DefaultIfEmpty().Max(m => m?.High ?? 0) ?? 0; var lowLastDay = chart.GetLastDayQuotations(DateTime.Now).Where(x => x.IsInEuropeTimeFrame())?.DefaultIfEmpty().Min(m => m?.Low ?? 0) ?? 0; var lastQuotation = chart.GetLastQuotation(); if (!TodayPlayedSymbol() && Account.GetOpenTransaction(chart.Symbol) != null) { if (lastQuotation.Close > (highLastDay + Instrument.Spread * Math.Pow(10, 0 - Instrument.Precision))) { var volumen = Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, Instrument.Valuation.BidPrice); var openPriceToPrecision = lastQuotation.Close * Math.Pow(10, Instrument.Precision); var closePriceToPrecision = highLastDay * Math.Pow(10, Instrument.Precision); var takeProfit = Math.Abs(closePriceToPrecision - openPriceToPrecision) / 10d; var stopLoss = takeProfit; if (ComputeProcentOfProfit(Instrument, volumen, MaxPriceOneTransaction, takeProfit) >= 2) { Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(InsideBarStrategy).Name); } } else if (lastQuotation.Close + Instrument.Spread * Math.Pow(10, 0 - Instrument.Precision) < lowLastDay) { var volumen = Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, Instrument.Valuation.BidPrice); var openPriceToPrecision = lastQuotation.Close * Math.Pow(10, Instrument.Precision); var closePriceToPrecision = lowLastDay * Math.Pow(10, Instrument.Precision); var takeProfit = Math.Abs(closePriceToPrecision - openPriceToPrecision) / 10d; var stopLoss = takeProfit; if (ComputeProcentOfProfit(Instrument, volumen, MaxPriceOneTransaction, takeProfit) >= 2) { Account.AddTransaction(1, Instrument, lastQuotation.Close, stopLoss, takeProfit, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(InsideBarStrategy).Name); } } } }
public void Should_return_0dot02_volumen_can_buy_when_have_1500_pln_on_index_DE30() { var symbol = "DE30"; var categoryName = CategoryName.Index; var contractSize = 25; var bidPrice = 12265.3; var askPrice = 12267.8; var currency = "EUR"; var laverage = 5; var precision = 1; var spread = 1; var valuation = new Valuation(bidPrice, askPrice); var instrument = new Instrument(symbol, categoryName, currency, valuation, new TimeSpan(02, 00, 00)); instrument.SetContractSize(contractSize); instrument.SetLeverage(laverage); instrument.SetPrecision(precision); instrument.SetSpread(spread); var volumeToBuy = instrument.ComputeVolumeToBuyByMaxPrice(1500, instrument.Valuation.BidPrice); Assert.Equal(0.02M, volumeToBuy); }
private decimal GetVolumen(TypeTransaction typeTransaction) { if (typeTransaction.Equals(TypeTransaction.Buy)) { return(Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, Instrument.Valuation.AskPrice)); } if (typeTransaction.Equals(TypeTransaction.Sell)) { return(Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, Instrument.Valuation.BidPrice)); } return(0); }
public Task Play(string info, string interval) { var volume = (decimal)Instrument.ComputeVolumeToBuyByMaxPrice(1000, Instrument.Valuation.BidPrice); var transaction = Account.GetOpenTransaction(Instrument.Symbol); if (info == "MOCNE KUP") { if (transaction != null) { if (transaction.TypeTransaction.Equals(TypeTransaction.Sell)) { Account.CloseTransaction(transaction.OrderId, Instrument.Valuation.AskPrice, DateTime.Now); } } if (interval == "60") { Account.AddTransaction(1, Instrument, Instrument.Valuation.AskPrice, null, null, volume, TypeTransaction.Buy, DateTime.Now, typeof(TechnicalAnalysisStrategy).Name); } } else if (info == "MOCNE SPRZEDAJ") { if (transaction != null) { if (transaction.TypeTransaction.Equals(TypeTransaction.Buy)) { Account.CloseTransaction(transaction.OrderId, Instrument.Valuation.AskPrice, DateTime.Now); } } if (interval == "60") { Account.AddTransaction(1, Instrument, Instrument.Valuation.BidPrice, null, null, volume, TypeTransaction.Sell, DateTime.Now, typeof(TechnicalAnalysisStrategy).Name); } } else { if (transaction != null) { if (transaction.TypeTransaction == TypeTransaction.Buy) { Account.CloseTransaction(transaction.OrderId, Instrument.Valuation.AskPrice, DateTime.Now); } if (transaction.TypeTransaction == TypeTransaction.Sell) { Account.CloseTransaction(transaction.OrderId, Instrument.Valuation.BidPrice, DateTime.Now); } } } return(Task.CompletedTask); }
public void Play(Chart chart) { var lastQuotation = chart.GetLastQuotation(); var transaction = Account.GetOpenTransaction(Instrument.Symbol); if (transaction != null) { if (transaction.DateOpen.Date < lastQuotation.Time.Date) { Account.CloseTransaction(transaction.OrderId, lastQuotation.Close, lastQuotation.Time); } } if (Account.GetOpenTransaction(Instrument.Symbol) == null) { var volumen = Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, lastQuotation.Close); Account.AddTransaction(0, Instrument, lastQuotation.Close, null, null, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(BuyOnEndDayStrategy).Name); } }
public void Play(Chart chart) { var lastQuotation = chart.GetLastQuotation(); CloseTransaction(lastQuotation); chart.SetInsideBar(lastQuotation.Time); if (chart.HasInsideBar() && Account.GetOpenTransaction(chart.Symbol) != null) { if (!TodayPlayedSymbol()) { if (BreakingDownChart(lastQuotation, chart)) { var volumen = Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, lastQuotation.Close); Account.AddTransaction(1, Instrument, lastQuotation.Close, null, null, volumen, TypeTransaction.Sell, lastQuotation.Time, typeof(InsideBarStrategy).Name); } else if (BreakingOutChart(lastQuotation, chart)) { var volumen = Instrument.ComputeVolumeToBuyByMaxPrice(MaxPriceOneTransaction, lastQuotation.Close); Account.AddTransaction(1, Instrument, lastQuotation.Close, null, null, volumen, TypeTransaction.Buy, lastQuotation.Time, typeof(InsideBarStrategy).Name); } } } }