#region Using declarations using System; using System.ComponentModel; using System.Drawing; using System.Collections.Generic; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using NinjaTrader.Indicator; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// /// This strategy buys at the close of a green Renko bar and sells at the close of a red Renko bar. It includes a reversal feature where a long trade is closed and a short trade is opened if a red bar closes while in a long position, and vice versa for short trades. /// [Description("This strategy buys at the close of a green Renko bar and sells at the close of a red Renko bar. It includes a reversal feature where a long trade is closed and a short trade is opened if a red bar closes while in a long position, and vice versa for short trades.")] public class RenkoStrategy : Strategy { #region Variables private Renko renko; private bool longTrade = false; private bool shortTrade = false; #endregion protected override void OnBarUpdate() { if (CurrentBar < 1) return; if (renko == null) { renko = Renko(BrickType.Fixed, 2); renko.AddDataSeries(Data.BarsPeriodType.Tick, 1); } double close = renko.Close[0]; double open = renko.Open[0]; bool greenBar = close > open; bool redBar = close < open; if (Position.MarketPosition == MarketPosition.Long && redBar) { ExitLong(); shortTrade = true; } else if (Position.MarketPosition == MarketPosition.Short && greenBar) { ExitShort(); longTrade = true; } if (!longTrade && !shortTrade) { if (greenBar) { EnterLong(); longTrade = true; } else if (redBar) { EnterShort(); shortTrade = true; } } if (longTrade && Position.MarketPosition == MarketPosition.Flat) longTrade = false; if (shortTrade && Position.MarketPosition == MarketPosition.Flat) shortTrade = false; } } }