I'm trying to close all orders with ExitLong() or ExitShort() but it's only closing one of my two orders. It's closing my EnterLong() but it's not closing an additional EnterLongStopMarket(); I have set. What I'm essentially looking for is the equivalent NinjaScript method for the Close Button that's on the UI. Ultimately I might want to open 4 or 5 orders (in the same directions) as scale-in orders as this is a trend following strategy. The goal is to just clean up everything and reset when the trend is over.
In the Managed Approach docs I see an ExitShort and ExitLong method but that's going to essentially create a stop which is not what I'm looking for. I just want to close everything if I hit a particular condition.
Here's a little sudo code below to illustrate what I'm up to.
public class Name : Strategy { private EMA EMA100; protected override void OnStateChange() { if (State == State.SetDefaults) { // A bunch of vars } else if (State == State.Configure) { } else if (State == State.DataLoaded) { // this get set when EnterLong() or Enter Short() is triggered SetProfitTarget("", CalculationMode.Ticks, ProfitTarget); } } } protected override void OnBarUpdate() { // LONG if ( Long Conditions ) { // Jump into market long EnterLong(Convert.ToInt32(NumOfContracts), ""); // Drop a "scale-in" order as well and let that sit until triggered. EnterLongStopMarket(0, true, 1, Close[0] + (TickSize * 16), "");. } // SHORT if ( ShortConditions ) { // Jump into market short EnterShort(Convert.ToInt32(NumOfContracts), ""); // Drop a "scale-in" order as well and let that sit until triggered. EnterShortStopMarket(0, true, 1, Close[0] - (TickSize * 16), ""); } // If the trend is over if (Position.MarketPosition == MarketPosition.Long && Close[0] < EMA100[0]) { ExitLong(); // close everything } // If the trend is over if (Position.MarketPosition == MarketPosition.Short && Close[0] > EMA100[0]) { ExitShort(); // close everything } }
Comment