NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-18-2012, 04:54 PM   #1
Serac
Member
 
Join Date: Feb 2011
Posts: 58
Thanks: 34
Thanked 0 times in 0 posts
Default OnBarUpdate, OnMarketData, and Rejected Orders

After being plagued by "Buy stop or buy stop limit orders can't be placed below the market" rejection orders, I am coming to the realization that I need a robust solution.

As I understand, this error is occuring because I am attempting to place a stoploss on the wrong side of the market (stop above price if long). Is this correct? These errors seem to be happening later in the trade, as price action is approaching my stop (which I update).

Questions:

1. What is the difference between OnBarUpdate with COBC=false, and OnMarketData?

2. Before placing my stop, I want to compare my desired stop to price action, and if my desired stop is on the wrong side of price, exit via some other means (so as to avoid the rejected order). Might this work? Would this best be done via OnMarketData?

3. Do you have links to non-trivial examples of OnMarketData?

Thanks!
Serac is offline  
Reply With Quote
Old 06-19-2012, 05:14 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Serac, you're correct in understanding - this can occur if you try modifying to a stop price that would make the order invalid.

OnBarUpdate() is called for incoming ticks / barupdates, OnMarketData() is called on each each Level 1 data event - http://www.ninjatrader.com/support/h...aeventargs.htm

For Last price you can either use COBC false and Close[0] in OnBarUpdate() or the OnMarketData() - you would need to keep in mind though there's no guaranteed call sequence for both methods as those act generally multi-threaded.

For your stop order issue you would need to check against the current bid / ask prices, this could be done via GetCurrentAsk() / GetCurrentBid() in OnBarUpdate().
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Old 06-20-2012, 10:56 PM   #3
Serac
Member
 
Join Date: Feb 2011
Posts: 58
Thanks: 34
Thanked 0 times in 0 posts
Default

Bertrand et al,

I guess I am going to hijack my own thread. This is the same problem. But, after Bertrand's help, different symptoms.

After further investigation (and a foray into unmanaged orders and back again), I see that my strategy works, but then falls apart as it does not exit when it should exit.

Setting TraceOrders = True, the Output window is yielding a "SignalName does not have a matching FromEntrySignal to exit" error. I guess I do not understand this error, because tracing upwards, I can see that that FromEntrySignal is still in an active position.

In the reply below, I am copying the first instance of this error. The error repeats many, many times (1000+?). The strategy is COBC = false.

I'm not sure how to go about debugging this. Usually TraceOrders is illustrative. This confused me. A search through past NT support shows scant information.

Thanks for any help!
Serac is offline  
Reply With Quote
Old 06-20-2012, 11:02 PM   #4
Serac
Member
 
Join Date: Feb 2011
Posts: 58
Thanks: 34
Thanked 0 times in 0 posts
Default

1/4/2012 11:11:58 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Cont Short B' Mode=Price Value=1.29255136293263 Currency=0 Simulated=False

1/4/2012 11:11:58 PM Amended stop order: Order='ac8fe2f05dba45be8e3e867352945b3e/Replay101' Name='Stop loss' State=Accepted Instrument='$EURUSD' Action=BuyToCover Limit price=0 Stop price=1.29255 Quantity=0.1M Strategy='ShadowSniper17' Type=Stop Tif=Gtc Oco='c0a0425611884cb4afdb2a442a8f525b-567' Filled=0 Fill price=0 Token='ac8fe2f05dba45be8e3e867352945b3e' Gtd='12/1/2099 12:00:00 AM'

1/4/2012 11:13:38 PM Entered internal PlaceOrder() method at 1/4/2012 11:13:38 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0.1M LimitPrice=0 StopPrice=0 SignalName='MACD Exit' FromEntrySignal='Cont Short B'

1/4/2012 11:13:38 PM Ignored PlaceOrder() method at 1/4/2012 11:13:38 PM: Action=BuyToCover OrderType=Market Quantity=0.1M LimitPrice=0 StopPrice=0 SignalName='MACD Exit' FromEntrySignal='Cont Short B' Reason='SignalName does not have a matching FromEntrySignal to exit'

1/4/2012 11:13:38 PM Entered internal PlaceOrder() method at 1/4/2012 11:13:38 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0.1M LimitPrice=0 StopPrice=0 SignalName='MACD Exit' FromEntrySignal='Cont Short B'

1/4/2012 11:13:38 PM Ignored PlaceOrder() method at 1/4/2012 11:13:38 PM: Action=BuyToCover OrderType=Market Quantity=0.1M LimitPrice=0 StopPrice=0 SignalName='MACD Exit' FromEntrySignal='Cont Short B' Reason='SignalName does not have a matching FromEntrySignal to exit'

The Enter-internalPlaceOrder -> Ignore PlaceOrder() cycle repeats many times after this...
Serac is offline  
Reply With Quote
Old 06-21-2012, 06:58 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Hi Serac, could you please send me the full TraceOrders output from the strategy along with a description of the methods you use in it to my attn to support at ninjatrader dot com?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-21-2012, 10:55 AM   #6
Serac
Member
 
Join Date: Feb 2011
Posts: 58
Thanks: 34
Thanked 0 times in 0 posts
Default

Bertrand,

E-mail sent. Let me know if you do not get it.
Serac is offline  
Reply With Quote
Old 06-21-2012, 10:57 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Thanks, I just got it and will look into matters.
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Tags
onmarketdata reject

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
onBarUpdate vs onMarketData danilam General Programming 7 11-17-2011 06:08 AM
OnMarketData and OnBarUpdate telbentel General Programming 5 12-20-2010 08:15 AM
OnMarketData vs OnBarUpdate RJay General Programming 23 07-28-2010 02:40 PM
OnMarketData vs OnBarUpdate kjackson Indicator Development 7 01-12-2010 10:11 AM
OnMarketData and OnBarUpdate svrz Indicator Development 6 12-23-2008 09:17 AM


All times are GMT -6. The time now is 08:32 AM.