If price goes up enough I get stopped in long. If price goes down enough I get stopped in short.
However, it appears that the internal order handling rules are preventing this.
This page seems to discuss this under "Internal Order Handling Rules to Reduce Unwanted Positions."I've included my code sample below.
Is it possible to achieve what I'm wanting to do with a managed approach or does it require the unmanaged approach? Is there a way to tie the orders together ala OCO?
I'm testing on DAY bars, though I'm not sure that matters.
Thanks,
Steve
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion Using declarations //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies.Barz { public class TestEntryStopsStrategy : Strategy { protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) { return; } if (Position.MarketPosition == MarketPosition.Flat) { if (Range()[1] > Range()[2] && ADX(15)[0] > 20) { EnterLongStopMarket(MAX(High, 10)[0]); EnterShortStopMarket(MIN(Low, 10)[0]); } } else { if (BarsSinceEntryExecution() > 10) { ExitLong(); ExitShort(); } } } protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Test simultaneous EnterLongStopMarket and EnterShortStopMarket."; Name = "Test - Entry Stops"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 10; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = false; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 50; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; TraceOrders = true; } else if (State == State.Configure) { } } } }
Comment