#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// EMA RSI MACD /// </summary> [Description("EMA RSI MACD")] public class CMOSS : Strategy { #region Variables // Wizard generated variables private int quantity = 1; // Default setting for Quantity private double rSIbuy = 51.000; // Default setting for RSIbuy private double mACDbuy = 0.01; // Default setting for MACDbuy private int shortEMA = 5; // Default setting for ShortEMA private int longEMA = 12; // Default setting for LongEMA private double rSIsell = 49.000; // Default setting for RSIsell private double mACDsell = -0.5000; // Default setting for MACDsell // User defined variables (add any user defined variables below) #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { Add(EMA(Close, ShortEMA)); Add(EMA(Close, LongEMA)); Add(RSI(14, 1)); Add(MACD(12, 26, 9)); Add(EMA(Close, ShortEMA)); Add(EMA(Close, LongEMA)); Add(RSI(14, 1)); Add(MACD(12, 26, 9)); CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Condition set 1 if (CrossAbove(EMA(Close, ShortEMA), EMA(Close, LongEMA), 1) && RSI(14, 1).Avg[0] > RSIbuy && MACD(12, 26, 9).Avg[0] > MACDbuy) { EnterLong(Quantity, "long"); } // Condition set 2 if (CrossAbove(EMA(Close, ShortEMA), EMA(Close, LongEMA), 1) && RSI(14, 1).Avg[0] < RSIsell && MACD(12, 26, 9).Avg[0] < MACDsell) { EnterShort(Quantity, "short"); } } #region Properties [Description("quantity")] [GridCategory("Parameters")] public int Quantity { get { return quantity; } set { quantity = Math.Max(1, value); } } [Description("RSI threshold")] [GridCategory("Parameters")] public double RSIbuy { get { return rSIbuy; } set { rSIbuy = Math.Max(0.0000, value); } } [Description("MACD threshold")] [GridCategory("Parameters")] public double MACDbuy { get { return mACDbuy; } set { mACDbuy = Math.Max(-5, value); } } [Description("short EMA")] [GridCategory("Parameters")] public int ShortEMA { get { return shortEMA; } set { shortEMA = Math.Max(0, value); } } [Description("long EMA")] [GridCategory("Parameters")] public int LongEMA { get { return longEMA; } set { longEMA = Math.Max(0, value); } } [Description("RSI threshold")] [GridCategory("Parameters")] public double RSIsell { get { return rSIsell; } set { rSIsell = Math.Max(0.000, value); } } [Description("MACD threshold")] [GridCategory("Parameters")] public double MACDsell { get { return mACDsell; } set { mACDsell = Math.Max(-5.0, value); } } #endregion } }
What I coded above is pretty rudimentary, Ideally, you should always plan on exiting on the close. There is much more versatile technique but like anything, you need to come to your conclusions first based on the evolution of your trading insights. You need to test out different parameters and market conditions and 'learn' the code first. You may find through testing its not ideal. Then you will move on to other techniques. Its very hard for anyone to teach me anything. I needed to get there myself. Its the same way with most people on this path.
gotcha, i'll see if i can get this loaded into NT8 through the strategy builder so i can tinker. Thanks again
no problem. You need to look at every scenario. Don't 'curve fit'.. the pnl might look good but it could be from 'curve fitting'.. that's why a discretionary bias where you truly understand price action and what is going on is important. laterz, Chris