public bool BearishScan(Symbol symbol, IEnumerable <Candle> candles) { //Bearish Strategy var fiveEma = candles.Ema(5)[candles.Count() - 1]; var twentyEma = candles.Ema(20)[candles.Count() - 1]; var twentySma = candles.Sma(20)[candles.Count() - 1]; var macdHist = candles.MacdHist(12, 26, 9)[candles.Count() - 1]; var indexedCandle = new IndexedCandle(candles, candles.Count() - 1); var macdBearOsc = indexedCandle.IsMacdOscBearish(12, 26, 9); if (fiveEma.Tick.Value < twentyEma.Tick.Value && fiveEma.Tick.Value < twentySma.Tick.Value && (macdHist.Tick.Value >= _MinNegativeMacdMHist && macdHist.Tick.Value <= _MaxNegativeMacdHist) && macdBearOsc) { var currentCandle = candles.LastOrDefault(); //EMA and MACD Satisfied _zeropdhaService.PlaceOrder(new BrokerOrderModel() { JobId = _jobId, SymbolId = symbol.Id, Exchange = symbol.Exchange, TradingSymbol = symbol.TradingSymbol, InstrumentToken = symbol.InstrumentToken, TransactionType = Constants.TRANSACTION_TYPE_SELL, Quantity = _MinQuantity, OrderType = Constants.ORDER_TYPE_MARKET, Product = Constants.PRODUCT_MIS, Variety = Constants.VARIETY_CO, Validity = Constants.VALIDITY_DAY, TriggerPrice = Convert.ToInt32(((currentCandle.Close + (currentCandle.Close * Convert.ToDecimal(_RiskPercentage))) / symbol.TickSize)) * symbol.TickSize }); return(true); } return(false); }
public bool BearishScan(Symbol symbol, IEnumerable <Candle> candles) { //Bearish Strategy var fiveEma = candles.Ema(5)[candles.Count() - 1]; var twentyEma = candles.Ema(20)[candles.Count() - 1]; var twentySma = candles.Sma(20)[candles.Count() - 1]; if (fiveEma.Tick.Value < twentyEma.Tick.Value && fiveEma.Tick.Value < twentySma.Tick.Value) { //EMA Satisfied for (var bar = 1; bar <= _MacdBackscanNoOfCandles; bar++) { var indexedCandle = new IndexedCandle(candles, candles.Count() - bar); var macdResult = indexedCandle.IsMacdBearishCross(12, 26, 9); if (macdResult) { //if macd is crossover in last 5 candles then place order _zeropdhaService.PlaceOrder(new BrokerOrderModel() { JobId = _jobId, SymbolId = symbol.Id, Exchange = symbol.Exchange, TradingSymbol = symbol.TradingSymbol, InstrumentToken = symbol.InstrumentToken, TransactionType = Constants.TRANSACTION_TYPE_SELL, Quantity = _MinQuantity, OrderType = Constants.ORDER_TYPE_MARKET, Product = Constants.PRODUCT_MIS, Variety = Constants.VARIETY_CO, Validity = Constants.VALIDITY_DAY, TriggerPrice = candles.LastOrDefault().High + (candles.LastOrDefault().High *Convert.ToDecimal(_RiskPercentage)) }); return(true); } } } return(false); }
public BrokerOrderModel Scan(Symbol symbol, IEnumerable <Candle> candles, bool isPlaceOrder = true) { BrokerOrderModel brokerOrderModel = null; try { var currentCandle = new IndexedCandle(candles, candles.Count() - 1); var rsi = candles.Rsi(9)[candles.Count() - 1]; var buySellRiseValue = currentCandle.Close * Convert.ToDecimal(_BuySellOnRisePercentage); var riskValue = currentCandle.Close * Convert.ToDecimal(_RiskPercentage); var rewardValue = (currentCandle.Close * Convert.ToDecimal(_RewardPercentage)); if (currentCandle.Prev.IsEmaBullishCross(_EmaShortPeriod, _EmaLongPeriod) && currentCandle.IsBullishExt() && currentCandle.Prev.IsBullishExt() //&& currentCandle.Prev.Close <= currentCandle.Open //&& currentCandle.Prev.GetBody() < currentCandle.GetBody() && rsi.Tick > 50) { brokerOrderModel = new BrokerOrderModel() { JobId = _jobId, SymbolId = symbol.Id, TickSize = symbol.TickSize, Exchange = symbol.Exchange, TradingSymbol = symbol.TradingSymbol, TransactionType = Constants.TRANSACTION_TYPE_BUY, Quantity = Convert.ToInt32(_MinInvestmentPerOrder / currentCandle.Close) > 0 ? Convert.ToInt32(_MinInvestmentPerOrder / currentCandle.Close) : 1, //Price = currentCandle.Close - buySellRiseValue, Price = currentCandle.Close, Product = Constants.PRODUCT_MIS, OrderType = Constants.ORDER_TYPE_LIMIT, Validity = Constants.VALIDITY_DAY, Variety = Constants.VARIETY_BO, //TriggerPrice = (currentCandle.Close - (riskValue + buySellRiseValue)), TriggerPrice = currentCandle.Close - (riskValue), SquareOffValue = rewardValue, StoplossValue = riskValue, TrailingStoploss = (riskValue) < 1 ? 1 : (riskValue) }; if (isPlaceOrder) { _zeropdhaService.PlaceOrder(brokerOrderModel); } //Log Candle ApplicationLogger.LogJob(_jobId, GlobalConfigurations.IndianTime + " Buying Current Candles [" + symbol.TradingSymbol + "]" + JsonConvert.SerializeObject(candles.ElementAt(candles.Count() - 1)) + Environment.NewLine + GlobalConfigurations.IndianTime + " Buying Previous Candles [" + symbol.TradingSymbol + "]" + JsonConvert.SerializeObject(candles.ElementAt(candles.Count() - 2))); } else if (currentCandle.Prev.IsEmaBearishCross(_EmaShortPeriod, _EmaLongPeriod) && currentCandle.IsBearishExt() && currentCandle.Prev.IsBearishExt() //&& currentCandle.Prev.Close >= currentCandle.Open //&& currentCandle.Prev.GetBody() < currentCandle.GetBody() && rsi.Tick < 50) { brokerOrderModel = new BrokerOrderModel() { JobId = _jobId, SymbolId = symbol.Id, TickSize = symbol.TickSize, Exchange = symbol.Exchange, TradingSymbol = symbol.TradingSymbol, TransactionType = Constants.TRANSACTION_TYPE_SELL, Quantity = Convert.ToInt32(_MinInvestmentPerOrder / currentCandle.Close) > 0 ? Convert.ToInt32(_MinInvestmentPerOrder / currentCandle.Close) : 1, //Price = currentCandle.Close + buySellRiseValue, Price = currentCandle.Close, Product = Constants.PRODUCT_MIS, OrderType = Constants.ORDER_TYPE_LIMIT, Validity = Constants.VALIDITY_DAY, Variety = Constants.VARIETY_BO, //TriggerPrice = (currentCandle.Close + (riskValue + buySellRiseValue)), TriggerPrice = (currentCandle.Close + (riskValue)), SquareOffValue = rewardValue, StoplossValue = riskValue, TrailingStoploss = (riskValue) < 1 ? 1 : (riskValue) }; if (isPlaceOrder) { _zeropdhaService.PlaceOrder(brokerOrderModel); } //Log Candle ApplicationLogger.LogJob(_jobId, GlobalConfigurations.IndianTime + " Selling Current Candles [" + symbol.TradingSymbol + "]" + JsonConvert.SerializeObject(candles.ElementAt(candles.Count() - 1)) + Environment.NewLine + GlobalConfigurations.IndianTime + " Selling Previous Candles [" + symbol.TradingSymbol + "]" + JsonConvert.SerializeObject(candles.ElementAt(candles.Count() - 2))); } } catch (Exception ex) { } return(brokerOrderModel); }