well, this strategy does compile and it would indeed execute, but i would like to know how to make a series of improvements to this strategy and it is not apparent how to best proceed.
#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> /// Enter the description of your strategy here /// </summary> [Description("samplesmaemahma")] public class samplesmaemahma : Strategy { #region Variables // Wizard generated variables private int myInput0 = 1; // Default setting for MyInput0 // User defined variables (add any user defined variables below) private int smalength = 200; private int emalength = 200; private int hmalength = 200; private int target1 = 12; private int target2 = 12; private int target3 = 12; private int stop = 12; private bool be2 = false; private bool be3 = false; #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() { CalculateOnBarClose = true; EntryHandling = EntryHandling.UniqueEntries; } private void GoLong() { SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false); SetStopLoss("target2", CalculationMode.Price, Close[0] - (Stop*TickSize), false); SetStopLoss("target3", CalculationMode.Price, Close[0] - (Stop*TickSize), false); SetProfitTarget("target1", CalculationMode.Price, Close[0] + (Target1*TickSize)); SetProfitTarget("target2", CalculationMode.Price, Close[0] + ((Target1+Target2)*TickSize)); SetProfitTarget("target3", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize)); EnterLong("target1"); EnterLong("target2"); EnterLong("target3"); } private void GoShort() { SetStopLoss("target1", CalculationMode.Price, Close[0] + (Stop*TickSize), false); SetStopLoss("target2", CalculationMode.Price, Close[0] + (Stop*TickSize), false); SetStopLoss("target3", CalculationMode.Price, Close[0] + (Stop*TickSize), false); SetProfitTarget("target1", CalculationMode.Price, Close[0] - (Target1*TickSize)); SetProfitTarget("target2", CalculationMode.Price, Close[0] - ((Target1+Target2)*TickSize)); SetProfitTarget("target3", CalculationMode.Price, Close[0] - ((Target1+Target2+Target3)*TickSize)); EnterShort("target1"); EnterShort("target2"); EnterShort("target3"); } private void ManageOrders() { if (Position.MarketPosition == MarketPosition.Long) { if (BE2 && High[0] > Position.AvgPrice + (Target1*TickSize)) SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false); if (BE3 && High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize)) SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false); } if (Position.MarketPosition == MarketPosition.Short) { if (BE2 && Low[0] < Position.AvgPrice - (Target1*TickSize)) SetStopLoss("target2", CalculationMode.Price, Position.AvgPrice, false); if (BE3 && Low[0] < Position.AvgPrice - ((Target1+Target2)*TickSize)) SetStopLoss("target3", CalculationMode.Price, Position.AvgPrice, false); } } protected override void OnBarUpdate() { EntryHandling = EntryHandling.UniqueEntries; SMA smav = SMA(smalength); EMA emav = EMA(smalength); HMA hmav = HMA(smalength); ManageOrders(); if (Position.MarketPosition != MarketPosition.Flat) return; if (Rising(smav) && Rising(emav) && Rising(hmav)) GoLong(); else if (Falling(smav) && Falling(emav) && Falling(hmav)) GoShort(); } #region Properties [Description("")] [GridCategory("Parameters")] public int SMAlength { get { return smalength; } set { smalength = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int EMAlength { get { return emalength; } set { emalength = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int HMAlength { get { return hmalength; } set { hmalength = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Target1 { get { return target1; } set { target1 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Target2 { get { return target2; } set { target2 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Target3 { get { return target3; } set { target3 = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public int Stop { get { return stop; } set { stop = Math.Max(1, value); } } [Description("")] [GridCategory("Parameters")] public bool BE2 { get { return be2; } set { be2 = value; } } [Description("")] [GridCategory("Parameters")] public bool BE3 { get { return be3; } set { be3 = value; } } #endregion } }
1) i can't see where the number of contracts for every possible entry / order is determined. how could i make the strategy take 2 contracts on every order? how could we make the strategy take 2 contracts for entry 1, 4 contracts for entry 2 and 8 contracts for entry 3?
2) another thing i would like to know is how to change this strategy which apparently works with market orders to now use limit orders? is it possible to use limit "join" and stop limit "join" (buy at the bid, sell at the ask) orders on every order the strategy generates? what about "hit / take" limit and stop limit (buy at the ask, sell at the bid) orders?
Comment