/// <summary> /// Strategy enter/exit/filtering rules /// </summary> public override void OnNewBar() { // Sell signal: the price has crossed above the lower Bollinger band if (this.Bars.Close[1] >= bollingerBandsIndicator.GetLowerBand()[1] && this.Bars.Close[0] < bollingerBandsIndicator.GetLowerBand()[0] && this.GetOpenPosition() == 0) { // Entering short and placing a profit target 3 standard deviations below the current market price this.Sell(OrderType.Market, 1, 0.0, "Enter short position"); this.ExitShort(OrderType.Limit, this.Bars.Close[0] - standardDeviationIndicator.GetStdDev()[0], "Exit short position (profit target)"); } else if (this.GetOpenPosition() == -1) { // In Simple Order Management mode, Stop and Limit orders must be placed at every bar this.ExitShort(OrderType.Limit, this.GetFilledOrders()[0].FillPrice - standardDeviationIndicator.GetStdDev()[0], "Exit short position (profit target)"); } }
/// <summary> /// Strategy enter/exit/filtering rules /// </summary> public override void OnNewBar() { if (this.GetOpenPosition() == 0) { int buySignal = (int)this.GetInputParameter("Stochastic %D Buy signal trigger level"); if (stochasticIndicator.GetD()[1] <= buySignal && stochasticIndicator.GetD()[0] > buySignal) { Order buyOrder = new MarketOrder(OrderSide.Buy, 1, "Entry long"); limitTakeProfitOrder = new LimitOrder(OrderSide.Sell, 1, Bars.Close[0] + stdDevIndicator.GetStdDev()[0], "Exit long (take profit stop)"); this.InsertOrder(buyOrder); this.InsertOrder(limitTakeProfitOrder); } } }