protected override bool CanOpenOffer(TREND_TYPE trendType) { var result = false; var timeFrame = GetCurrentTimeFrame(); var sma200Price = TechnicalIndicatiorsWrapper.iMA(this, _symbol, timeFrame, 200, 0, MA_METHOD.MODE_SMA, APPLY_PRICE.PRICE_CLOSE, 0); var lastTwoBarsClosePrice = PredefinedVariablesWrapper.Close(this, 2); var lastOneBarClosePrice = PredefinedVariablesWrapper.Close(this, 1); var lastThreeBarPrice = PredefinedVariablesWrapper.Close(this, 3); if (trendType == TREND_TYPE.ASC) { if (sma200Price > lastThreeBarPrice && sma200Price < lastOneBarClosePrice && sma200Price < lastTwoBarsClosePrice) { result = true; Log.DebugFormat("Can open ASC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Sma200Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}, lastThreeBarsClosePrice={3}", sma200Price, lastOneBarClosePrice, lastTwoBarsClosePrice, lastThreeBarPrice); } } if (trendType == TREND_TYPE.DESC) { if (lastThreeBarPrice > sma200Price && lastTwoBarsClosePrice < sma200Price && lastOneBarClosePrice < sma200Price) { result = true; Log.DebugFormat("Can open DESC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Sma200Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}, lastThreeBarsClosePrice={3}", sma200Price, lastOneBarClosePrice, lastTwoBarsClosePrice, lastThreeBarPrice); } } return result; }
protected override bool CanOpenOffer(TREND_TYPE trendType) { var result = false; var timeFrame = GetCurrentTimeFrame(); var sma21Price = TechnicalIndicatiorsWrapper.iMA(this, _symbol, timeFrame, 21, 8, MA_METHOD.MODE_SMA, APPLY_PRICE.PRICE_CLOSE, 0); var sma70Price = TechnicalIndicatiorsWrapper.iMA(this, _symbol, timeFrame, 70, 8, MA_METHOD.MODE_SMA, APPLY_PRICE.PRICE_CLOSE, 0); var lastTwoBarsClosePrice = PredefinedVariablesWrapper.Close(this, 2); var lastOneBarClosePrice = PredefinedVariablesWrapper.Close(this, 1); var lastThreeBarPrice = PredefinedVariablesWrapper.Close(this, 3); if (trendType == TREND_TYPE.ASC) { if (lastThreeBarPrice < sma21Price && lastThreeBarPrice > sma70Price && lastTwoBarsClosePrice > sma21Price && lastOneBarClosePrice > sma21Price) { result = true; Log.DebugFormat("Can open ASC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Sma21Price={0}, Sma70Price={1}, lastOneBarClosePrice={2}, lastTwoBarsClosePrice={3}, lastThreeBarPrice={4} ", sma21Price, sma70Price, lastOneBarClosePrice, lastTwoBarsClosePrice, lastThreeBarPrice); } } if (trendType == TREND_TYPE.DESC) { if (lastThreeBarPrice > sma21Price && lastThreeBarPrice < sma70Price && lastTwoBarsClosePrice < sma21Price && lastOneBarClosePrice < sma21Price) { result = true; Log.DebugFormat("Can open DESC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Sma21Price={0}, Sma70Price={1}, lastOneBarClosePrice={2}, lastTwoBarsClosePrice={3}, lastThreeBarPrice={4} ", sma21Price, sma70Price, lastOneBarClosePrice, lastTwoBarsClosePrice, lastThreeBarPrice); } } return(result); }
protected override bool CanOpenOffer(TREND_TYPE trendType) { var result = false; var timeFrame = GetCurrentTimeFrame(); var ema25Price = TechnicalIndicatiorsWrapper.iMA(this,_symbol, timeFrame, 25, 0, MA_METHOD.MODE_EMA, APPLY_PRICE.PRICE_CLOSE, 0); var lastTwoBarsClosePrice = PredefinedVariablesWrapper.Close(this,2); var lastOneBarClosePrice = PredefinedVariablesWrapper.Close(this,1); if (trendType == TREND_TYPE.ASC) { if (ema25Price > lastTwoBarsClosePrice && ema25Price < lastOneBarClosePrice) { result = true; Log.DebugFormat("Can open ASC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Ema25Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}", ema25Price, lastOneBarClosePrice, lastTwoBarsClosePrice); } } if (trendType == TREND_TYPE.DESC) { if (lastTwoBarsClosePrice > ema25Price && lastOneBarClosePrice < ema25Price) { result = true; Log.DebugFormat("Can open DESC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Ema25Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}", ema25Price, lastOneBarClosePrice, lastTwoBarsClosePrice); } } if (!result)// try to check if bar was touched near MA { var lastOneBarHighPrice = PredefinedVariablesWrapper.High(this, 1); var lastOneBarLowPrice = PredefinedVariablesWrapper.Low(this, 1); if (trendType == TREND_TYPE.ASC) { if (lastOneBarLowPrice == ema25Price ||(lastOneBarHighPrice > ema25Price && lastOneBarLowPrice < ema25Price) || (lastOneBarClosePrice == ema25Price)) { result = true; Log.DebugFormat("LastBar are on ema25 or near ema25. Can open ASC Offer"); Log.DebugFormat("Symbol={0}, Ema25Price={1},LastOneBarClosePrice={2}, TrendType={3}", _symbol, ema25Price, lastOneBarClosePrice, trendType); } } if (trendType == TREND_TYPE.DESC) { if (lastOneBarHighPrice == ema25Price || (lastOneBarLowPrice > ema25Price && lastOneBarHighPrice < ema25Price) || (lastOneBarClosePrice == ema25Price)) { result = true; Log.DebugFormat("LastBar are on ema25Price or near. Can open DESC Offer"); Log.DebugFormat("Symbol={0}, Ema25Price={1},LastOneBarClosePrice={2}, TrendType={3}", _symbol, ema25Price, lastOneBarClosePrice, trendType); } } } return result; }
protected override bool CanOpenOffer(TREND_TYPE trendType) { var result = false; var timeFrame = GetCurrentTimeFrame(); var ema25Price = TechnicalIndicatiorsWrapper.iMA(this, _symbol, timeFrame, 25, 0, MA_METHOD.MODE_EMA, APPLY_PRICE.PRICE_CLOSE, 0); var lastTwoBarsClosePrice = PredefinedVariablesWrapper.Close(this, 2); var lastOneBarClosePrice = PredefinedVariablesWrapper.Close(this, 1); if (trendType == TREND_TYPE.ASC) { if (ema25Price > lastTwoBarsClosePrice && ema25Price < lastOneBarClosePrice) { result = true; Log.DebugFormat("Can open ASC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Ema25Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}", ema25Price, lastOneBarClosePrice, lastTwoBarsClosePrice); } } if (trendType == TREND_TYPE.DESC) { if (lastTwoBarsClosePrice > ema25Price && lastOneBarClosePrice < ema25Price) { result = true; Log.DebugFormat("Can open DESC offer. TrendType={0}, Symbol={1}", GetTrendType(), _symbol); Log.DebugFormat("Ema25Price={0}, LastClosedBarPrice={1}, lastTwoBarsClosePrice={2}", ema25Price, lastOneBarClosePrice, lastTwoBarsClosePrice); } } if (!result)// try to check if bar was touched near MA { var lastOneBarHighPrice = PredefinedVariablesWrapper.High(this, 1); var lastOneBarLowPrice = PredefinedVariablesWrapper.Low(this, 1); if (trendType == TREND_TYPE.ASC) { if (lastOneBarLowPrice == ema25Price || (lastOneBarHighPrice > ema25Price && lastOneBarLowPrice < ema25Price) || (lastOneBarClosePrice == ema25Price)) { result = true; Log.DebugFormat("LastBar are on ema25 or near ema25. Can open ASC Offer"); Log.DebugFormat("Symbol={0}, Ema25Price={1},LastOneBarClosePrice={2}, TrendType={3}", _symbol, ema25Price, lastOneBarClosePrice, trendType); } } if (trendType == TREND_TYPE.DESC) { if (lastOneBarHighPrice == ema25Price || (lastOneBarLowPrice > ema25Price && lastOneBarHighPrice < ema25Price) || (lastOneBarClosePrice == ema25Price)) { result = true; Log.DebugFormat("LastBar are on ema25Price or near. Can open DESC Offer"); Log.DebugFormat("Symbol={0}, Ema25Price={1},LastOneBarClosePrice={2}, TrendType={3}", _symbol, ema25Price, lastOneBarClosePrice, trendType); } } } return(result); }
private void AddActiveExpertDetail(TREND_TYPE trendType, double accountBalance, int result, double stopLoss, double takeProfit) { var expertDetailRecord = new ExpertDetails { State = State.Active.ToString(), CreatedOn = DateTime.Now, Pair = _symbol, TimeFrame = GetCurrentTimeFrame(), TrendType = trendType.ToString(), BalanceOnCreate = accountBalance, ExpertName = GetType().Name, OrderId = result, StopLoss = stopLoss, TakeProfit = takeProfit }; ExpertDetailsRepository.Save(expertDetailRecord); Log.DebugFormat("New expertDetail Record was added. Id={0}. Pair={1}, TrendType={2}", expertDetailRecord.Id, expertDetailRecord.Pair, expertDetailRecord.TrendType); }
public void OpenOffer(TREND_TYPE trendType) { var point = PredefinedVariablesWrapper.Point(this); var accountBalance = AccoutInformationWrapper.AccountEquity(this); var result = -1; double ask = PredefinedVariablesWrapper.Ask(this); double bid = PredefinedVariablesWrapper.Bid(this); double stopLoss = 0; double takeProfit = 0; if (trendType == TREND_TYPE.ASC) { takeProfit = bid + int.Parse(_config.TakeProfit) * point; stopLoss = bid - int.Parse(_config.StopLoss) * point; result = OrderOperations.OpenOffer(this, _symbol, ORDER_TYPE.OP_BUY, double.Parse(_config.OrderAmount), ask, 0, stopLoss, takeProfit); } if (trendType == TREND_TYPE.DESC) { takeProfit = ask - int.Parse(_config.TakeProfit) * point; stopLoss = ask + int.Parse(_config.StopLoss) * point; result = OrderOperations.OpenOffer(this, _symbol, ORDER_TYPE.OP_SELL, double.Parse(_config.OrderAmount), bid, 0, stopLoss, takeProfit); } var isOrderSelected = TradingFunctionsWrapper.OrderSelect(this, result, SELECT_BY.SELECT_BY_TICKET); if (isOrderSelected) { Log.DebugFormat("Order was opened"); AddActiveExpertDetail(trendType, accountBalance, result, stopLoss, takeProfit); } else { Log.DebugFormat("Order was not opened. OrderId={0}", result); } }
abstract protected bool CanOpenOffer(TREND_TYPE trendType);
public void OpenOffer(TREND_TYPE trendType) { var point = PredefinedVariablesWrapper.Point(this); var accountBalance = AccoutInformationWrapper.AccountEquity(this); var result = -1; double ask = PredefinedVariablesWrapper.Ask(this); double bid = PredefinedVariablesWrapper.Bid(this); double stopLoss = 0; double takeProfit = 0; if (trendType == TREND_TYPE.ASC) { takeProfit = bid + int.Parse(_config.TakeProfit)*point; stopLoss = bid - int.Parse(_config.StopLoss)*point; result = OrderOperations.OpenOffer(this, _symbol, ORDER_TYPE.OP_BUY, double.Parse(_config.OrderAmount), ask, 0, stopLoss, takeProfit); } if (trendType == TREND_TYPE.DESC) { takeProfit = ask - int.Parse(_config.TakeProfit)*point; stopLoss = ask + int.Parse(_config.StopLoss)*point; result = OrderOperations.OpenOffer(this, _symbol, ORDER_TYPE.OP_SELL, double.Parse(_config.OrderAmount), bid, 0, stopLoss, takeProfit); } var isOrderSelected = TradingFunctionsWrapper.OrderSelect(this, result, SELECT_BY.SELECT_BY_TICKET); if (isOrderSelected) { Log.DebugFormat("Order was opened"); AddActiveExpertDetail(trendType, accountBalance, result, stopLoss, takeProfit); } else { Log.DebugFormat("Order was not opened. OrderId={0}", result); } }