PDA

View Full Version : How to set a stop loss order manually in a RELIABLE way?


NetTecture
07-23-2009, 03:57 AM
Hello,

I now try to set my stop orders manually. This has issues, though. As you may know, orders expire with the bar.

Here is what happened. It is not funny...

...
20/07/2009 16:08:26 Entered internal PlaceOrder() method at 20/07/2009 16:08:26: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L1'
20/07/2009 16:08:26 Entered internal PlaceOrder() method at 20/07/2009 16:08:26: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L2'
20/07/2009 16:08:26 Entered internal PlaceOrder() method at 20/07/2009 16:08:26: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L3'
...
20/07/2009 16:08:27 Entered internal PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L1'
20/07/2009 16:08:27 Ignored PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName=Sell' FromEntrySignal='HA L1' Reason='Invalid order price, please see log tab'
20/07/2009 16:08:27 Entered internal PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L2'
20/07/2009 16:08:27 Ignored PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName=Sell' FromEntrySignal='HA L2' Reason='Invalid order price, please see log tab'
20/07/2009 16:08:27 Entered internal PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName='' FromEntrySignal='HA L3'
20/07/2009 16:08:27 Ignored PlaceOrder() method at 20/07/2009 16:08:27: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8757 SignalName=Sell' FromEntrySignal='HA L3' Reason='Invalid order price, please see log tab'

Basically at the end of the bar the price was very close to the stop, by the time i was moving the order, it was invalid.

How am I supposed to deal with this? Should I now move into orders that are valid GTC? Will a signal stop order be cancelled if the entry signal position is closed (not documented)? Or should I have to close the stop orders manually?

NinjaTrader_Bertrand
07-23-2009, 04:36 AM
NetTecture, which error do you get exactly in the Log tab as this occurs? Most likely you submit the stop at an incorrect price and this is the reason why it gets 'ignored'.

If you do not like orders to expire at the end of the bar (default), then please use the liveUntilCancelled option - http://www.ninjatrader-support.com/HelpGuideV6/Overview36.html

NetTecture
07-23-2009, 04:38 AM
Well, this is not the issue.

Problem is:

* I set stop losses.
* I sort of assume that when I do so every bar, that will be "valid".
* Sadly, as the price seems to jump, this error occurs.

This is sort of a non-nice thing to do (sorry). It means, basically, one has to work with GTC orders, as - the "submit stuff per bar" may not work.

I would suggest adding a paramter that "fixes the order" (i.e. - if that is a stop submitted, the price went through, sell market).

My order handling code gets more and more complicated for stuff like that ;) Now I have to move all things to GTC orders, simply because I loose stop orders between bars ;)

Slowly getting through, though ;)

NinjaTrader_Bertrand
07-23-2009, 05:29 AM
I'm not sure what you mean by 'loosing' stop orders, this would most likely depend on the conditions have in place to move the stops, printing out the actual stop value may help to debug this.

You also should reset your stop losses once flat to some default value as in this sample - http://www.ninjatrader-support2.com/vb/showthread.php?t=3222

NetTecture
07-23-2009, 05:31 AM
Well, as I said - and it is in the shown logs.

The problem basically is...

* Bar closes. Stop is pretty much "at the bar" (1 tick away).
* By the time my order gets entered, the price has moved - ergo the short is invalid.

As I dont get any feedback from the method, I am stuck with the price going down and down below my stop level.

I move my code now to GTC stops...
...SADLY this makes the whole API more complicated.

Why?

Because non-gtc I can just way "signal name".

With GTC I have to give MY signal name, the amount to be closed. This is a lot more info ;)

One overload with just a "gtc boolean" vaiable would be nice.

NinjaTrader_Bertrand
07-23-2009, 05:37 AM
Thanks for the suggestion NetTecture, have you tried selecting the GTC tif setting when starting up your strategy? - http://www.ninjatrader-support.com/HelpGuideV6/RunningANinjaScriptStrategyFromAChart.html