Order management logic/programming

Okay, I’ve gotten myself to the point where all that’s left is to get the proper orders to execute when the prescribed conditions exist. This is proving to be something of an issue.

The first Entry order executes fine. I’ve tried using

NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy(atm, entryorder);

and

theAccount.Submit(new[] { entryorder });

They both work, in terms of generating orders, but neither one is suitable for management once I am in a position. The ATM method is problematic because I want to reverse on stop, but then you can never exit a trade without your targets getting hit, because you’re trapped in this neverending loop of reversing positions.

The other method would be preferable, if I could get the SetStopLoss to work, but I always get “does not exist in the current context.” ExitLongStopMarket gives the same error.

So, I am trying to figure out how to get the orders that I can place to execute properly and provide the behavior that I am seeking.

Basically, I want the first order to go in with targets and stops. Then, when price has moved far enough in my direction, move the stop to breakeven.

Simultaneously, I need it to monitor for price moving against me, and then reverse my position if it goes too far.

The reversed position should then behave just like the original entry, minus the stop-and-reverse. I’ve tried doing it by creating multiple orders initially, using a different ATM strategy for each one, but then I end up having to create two orders for the stop-and-reverse, and then I end up with a dozen different orders on my chart.

The main problem with starting with the ATM is that it only sets the stops at a certain distance from the entry, based on what’s specified in the ATM Strategy, but I need to set my initial stop at a particular price, based on market structure. That is where the SetStopLoss or ExitLongStopMarket would come in handy, but they don’t work.

Any suggestions would be greatly appreciated. Thank you!

The other method would be preferable, if I could get the SetStopLoss to work, but I always get “does not exist in the current context.” ExitLongStopMarket gives the same error.

Again, these are Strategy functions that don’t work in an indicator.

I realise you don’t want this answer hence the fact you’ve created another thread about basically the same topic but the fact of the matter is you need to use OnExecutionUpdate/OnOrderUpdate and Account.Submit() / Account.Change().

You need to learn these functions because that is the answer to doing everything order related from an indicator.

1 Like

Okay, so I found some information about Account.Change(), and I also did some research into Account.Submit() as it relates to SLs and TPs. I have now gotten it to the point where it creates the SL at the appropriate price level when the entry order fills.

Now, I have to work out the stop-and-reverse methodology. It seems to be kind-of working, but I am getting a little burned out for today, so I have to look at it again tomorrow.

Thank you!