Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
EnterLongLimit and EnterShortLimit fail
Collapse
X
-
Thanks for your patience. We are still looking into this but so far have not been able to get a consistent reproducible scenario. The output generated by so many trades and challenges with time zones because of the time conditions make this difficult to track. I will update this with any new information we find out.
-
Thanks for the update and glad to hear you found a work around. We are still looking into the strategy you submitted and will have more information on it tomorrow.
Leave a comment:
-
Hi Ryan,
Thanks again - as always your answers are real eye-openers! Hope to see some feedback on the issue. In the meantime I've found a workaround. I've added 1-minute EMD series in addition to the existing 1-day series. Now I'm still looking for limit order price on dailies but submit and cancel limit orders on the 1-minute TF. Everything works just fine this way.
The changes I've made in bold below.
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { [Description("")] public class TestStrategy : Strategy { private IOrder m_order = null; protected override void Initialize() { Add(PeriodType.Day, 1); Add("YM 09-11", PeriodType.Day, 1); Add("TF 09-11", PeriodType.Day, 1); Add("EMD 09-11", PeriodType.Day, 1); [B]Add("EMD 09-11", PeriodType.Minute, 1);[/B] CalculateOnBarClose = true; TraceOrders = true; } protected override void OnBarUpdate() { if( BarsInProgress != 0 ) return; if( Time[0].Hour == 8 && Time[0].Minute == 35 ) { m_order = EnterShortLimit([B]5[/B], true, 1, Closes[4][1], "short_4"); } else if( Time[0].Hour == 15 && Time[0].Minute == 55 ) { if( Positions[[B]5[/B]].MarketPosition == MarketPosition.Short ) { ExitShort([B]5[/B], 1, "short_4", ""); } if( m_order != null ) { CancelOrder(m_order); } } } } }
Leave a comment:
-
We support documented NinjaScript in our help guide and reference samples on these forums. There is a lot more you can do in C# than we can provide support for. There are also items like Position.Close() that may be available but are not documented/supported. Users are free to use but at their own risk as the exact behavior may not be described, may break with a future release, or may have unintended consequences. Basically, if it's not documented, we cannot offer support for it.
Thanks for including this updated snippet. I will attempt to reproduce what you were seeing and update tomorrow.
One item I would change here is assigning null to your IOrder within Initialize(). Initialize() is called for ALL scripts, when working in Right Click > indicators screen or any of the strategy interfaces. For this reason it's typically reserved for setting script level properties and instantiating data series objects. You can include an initial value in the variables declaration.
private IOrder m_order = null;
If there are certain parts of your script you want executed only once, there is OnStartUp() handler for this:
Leave a comment:
-
Originally posted by NinjaTrader_RyanM View PostThanks for the assistance isolating this. Almost there, but will need to hard code all added series, and Position.Close() is not supported. To exit a position by a market order, need to use ExitLong() or ExitShort().
Thanks again for your help!
Here's the code:
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { [Description("")] public class TestStrategy : Strategy { private IOrder m_order; protected override void Initialize() { Add(PeriodType.Day, 1); Add("YM 09-11", PeriodType.Day, 1); Add("TF 09-11", PeriodType.Day, 1); Add("EMD 09-11", PeriodType.Day, 1); m_order = null; CalculateOnBarClose = true; TraceOrders = true; } protected override void OnBarUpdate() { if( BarsInProgress != 0 ) return; if( Time[0].Hour == 8 && Time[0].Minute == 35 ) { m_order = EnterShortLimit(4, true, 1, Closes[4][1], "short_4"); } else if( Time[0].Hour == 15 && Time[0].Minute == 55 ) { if( Positions[4].MarketPosition == MarketPosition.Long ) { ExitLong(); } else if( Positions[4].MarketPosition == MarketPosition.Short ) { ExitShort(4, 1, "short_4", ""); } if( m_order != null ) { CancelOrder(m_order); } } } } }
Last edited by ipso33; 08-23-2011, 03:24 PM.
Leave a comment:
-
Thanks for the assistance isolating this. Almost there, but will need to hard code all added series, and Position.Close() is not supported. To exit a position by a market order, need to use ExitLong() or ExitShort().
Leave a comment:
-
Originally posted by NinjaTrader_RyanM View PostGreat, thanks for confirming. Next, will need to take the strategy and strip out anything that isn't critical in reproducing the issue, and verify using only supported properties.
Will need to hard code any added series in Initialize() as well.
You strategy has a lot of custom order management, so will need to see it simplified a good bit before we can investigate potential bug report with entry handling here. Strip out any switch statements, any random code, any custom methods, use only supported/documented techniques, and provide the steps so that we can see the same thing when running the strategy here.
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { [Description("")] public class TestStrategy : Strategy { private string contract2 = "YM 09-11"; private string contract3 = "TF 09-11"; private string contract4 = "EMD 09-11"; private IOrder m_order; protected override void Initialize() { Add(PeriodType.Day, 1); Add(contract2, PeriodType.Day, 1); Add(contract3, PeriodType.Day, 1); Add(contract4, PeriodType.Day, 1); m_order = null; CalculateOnBarClose = true; TraceOrders = true; } protected override void OnBarUpdate() { if( BarsInProgress != 0 ) return; if( Time[0].Hour == 8 && Time[0].Minute == 35 ) { m_order = EnterShortLimit(4, true, 1, Closes[4][1], "short_4"); } else if( Time[0].Hour == 15 && Time[0].Minute == 55 ) { if( Positions[4].MarketPosition != MarketPosition.Flat ) { Positions[4].Close(); } if( m_order != null ) { CancelOrder(m_order); } } } } }
Leave a comment:
-
As per my understanding it ignores a limit order when there are neither open positions nor other limit orders.
Will need to hard code any added series in Initialize() as well.
You strategy has a lot of custom order management, so will need to see it simplified a good bit before we can investigate potential bug report with entry handling here. Strip out any switch statements, any random code, any custom methods, use only supported/documented techniques, and provide the steps so that we can see the same thing when running the strategy here.Last edited by NinjaTrader_RyanM1; 08-23-2011, 02:07 PM.
Leave a comment:
-
Hi Ryan
Originally posted by NinjaTrader_RyanM View PostSorry, I'm not sure what you feel NinjaTrader is doing incorrectly.
Originally posted by NinjaTrader_RyanM View PostThe earlier message you posted is normal and expected when you try to submit an additional entry beyond what is allowed, depending on EntryHandling and EntriesPerDirection properties. You have it set to 1 EntryPerDirection and entry handling at AllEntries, which means only 1 entry per direction, regardless of signal name.
If I add this :
Code:foreach(Position p in Positions) { logInfo("position = " + p.MarketPosition); }
Given the code I sent, is there anything in it that would cause dangling positions or orders that are not visible using Ninja Trader API? The logic is pretty simple and IMHO there's really nothing that would allow such a situation.
Thanks for your help.
Edit:
some log entries that show this:
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 Positions at session start
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 08:35:00 Longlimit: 2, at: 951.8, name: long_4
23/08/2011 21:44:08|1|4|Execution='NT-00012' Instrument='EMD 09-11' Account='Backtest' Name='long_4' Exchange=Default Price=951.8 Quantity=2 Market position=Long Commission=0 Order='NT-00013' Time='11/02/2011 22:15:00'
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 Positions at session close
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 position = Long
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 Closing position at session close for instrumentIndex = 4
23/08/2011 21:44:08|1|4|11/02/2011 15:55:00 Cancelling remaining limit order at session close for index = 4
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 Positions at session start
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 08:35:00 Longlimit: 2, at: 955.3, name: long_4
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 Positions at session close
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 position = Flat
23/08/2011 21:44:08|1|4|14/02/2011 15:55:00 Cancelling remaining limit order at session close for index = 4
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 Positions at session start
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 position = Flat
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 Longlimit: 2, at: 966.2, name: long_4
23/08/2011 21:44:08|1|4|15/02/2011 08:35:00 **************** m_order == nullLast edited by ipso33; 08-23-2011, 01:46 PM.
Leave a comment:
-
Sorry, I'm not sure what you feel NinjaTrader is doing incorrectly. The earlier message you posted is normal and expected when you try to submit an additional entry beyond what is allowed, depending on EntryHandling and EntriesPerDirection properties.
You have it set to 1 EntryPerDirection and entry handling at AllEntries, which means only 1 entry per direction, regardless of signal name. What was the position at the time you submitted the order? Print (Position.MarketPosition);
If your position is long at the time you submit an additional buy entry order, then it ignores the order every time (with the properties set as they are).
Leave a comment:
-
Originally posted by NinjaTrader_RyanM View PostIf you feel there is a bug in NinjaTrader, please provide a simplified script and steps so that we can see the same on our end. Thank you.
I really hope it's my fault and it's easy to fix!
The primary instrument is ES 09-11
The settings are as here:
What I want to achieve is:
1) at 8.35 am submit a limit order
2) at 3:55 pm close a position if order filled, cancel the order otherwise.
3) repeat the next day
Please have a look at line 65 - it says what to do to see the erroneous behaviour . I do hope it's my fault and you'll be able to point it out!
Here's the code:
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { [Description("")] public class TestStrategy : Strategy { private string contract2 = "YM 09-11"; private string contract3 = "TF 09-11"; private string contract4 = "EMD 09-11"; #region Members private bool m_logEnabled; private IOrder m_order; private int m_lots; private int m_selectedInstrumentIndex; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { // add time series Add(PeriodType.Day, 1); Add(contract2, PeriodType.Day, 1); Add(contract3, PeriodType.Day, 1); Add(contract4, PeriodType.Day, 1); m_order = null; m_logEnabled = true; m_lots = 2; CalculateOnBarClose = true; TraceOrders = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if( BarsInProgress != 0 ) return; if( Time[0].Hour == 8 && Time[0].Minute == 35 ) { Random random = new Random(); // CHANGE THIS TO ANYTHING > 1 TO SEE ERRORS m_selectedInstrumentIndex = 1;//random.Next(1, 5); if( m_selectedInstrumentIndex != 0 ) { switch ( random.Next() % 2 ) { case 0 : double price = Closes[m_selectedInstrumentIndex][1]; logInfo("Longlimit: " + m_lots + ", at: " + price + ", name: long_" + m_selectedInstrumentIndex); m_order = EnterLongLimit(m_selectedInstrumentIndex, true, m_lots, price, "long_" + m_selectedInstrumentIndex); if( m_order == null ) logInfo("**************** m_order == null **********************"); break; case 1 : price = Closes[m_selectedInstrumentIndex][1]; logInfo("Shortlimit: " + m_lots + ", at: " + price + ", name: short_" + m_selectedInstrumentIndex); m_order = EnterShortLimit(m_selectedInstrumentIndex, true, m_lots, price, "short_" + m_selectedInstrumentIndex); if( m_order == null ) logInfo("**************** m_order == null **********************"); break; } } } else if( Time[0].Hour == 15 && Time[0].Minute == 55 ) { if( Positions[m_selectedInstrumentIndex].MarketPosition != MarketPosition.Flat ) { logInfo("Closing position at session close for instrumentIndex = " + m_selectedInstrumentIndex); Positions[m_selectedInstrumentIndex].Close(); } if( m_order != null ) { logInfo("Cancelling remaining limit order at session close for index = " + m_selectedInstrumentIndex); CancelOrder(m_order); } else { logInfo("m_order == null"); } } } protected override void OnExecution(IExecution execution) { if( m_order != null && execution.Order != null && m_order.Token == execution.Order.Token ) { Log(execution.ToString(), LogLevel.Information); } } private void logInfo(string text) { if(m_logEnabled) Log(Times[0][0].ToString() + " " + text, LogLevel.Information); } } }
Last edited by ipso33; 08-23-2011, 12:19 PM.
Leave a comment:
-
The message reported by TraceOrders for ignoring is:
Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
Have you checked these properties and feel NinjaTrader should be allowing these entries? If you feel there is a bug in NinjaTrader, please provide a simplified script and steps so that we can see the same on our end. Thank you.
Leave a comment:
-
Originally posted by NinjaTrader_RyanM View PostThere may be some C# techniques for this, but is beyond our scope of support.
11/02/2011 22:15:00 Entered internal PlaceOrder() method at 11/02/2011 22:15:00: BarsInProgress=4 Action=Buy OrderType=Limit Quantity=2 LimitPrice=955.3 StopPrice=0 SignalName='long_4' FromEntrySignal=''
Cancelled custom managed order at 14/02/2011 15:55:00: Order='NT-00015/Backtest' Name='long_4' State=Working Instrument='EMD 09-11' Action=Buy Limit price=955.3 Stop price=0 Quantity=2 Strategy='TestFill' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='17dfad8464184acb8e702681def67a52' Gtd='01/12/2099 00:00:00'
14/02/2011 22:15:00 Entered internal PlaceOrder() method at 14/02/2011 22:15:00: BarsInProgress=4 Action=Buy OrderType=Limit Quantity=2 LimitPrice=966.2 StopPrice=0 SignalName='long_4' FromEntrySignal=''
14/02/2011 22:15:00 Ignored PlaceOrder() method at 14/02/2011 22:15:00: Action=Buy OrderType=Limit Quantity=2 LimitPrice=966.2 StopPrice=0 SignalName='long_4' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
The sequence of events in my code is as follows:
1) at 8:30 am open a long limit for the 4th series:
m_order = EnterLongLimit(4, true, lots, price, "long_4");
2) at 3:55 pm cancel the limit order (if not filled)
CancelOrder(m_order);
3) repeat the same next day.
For me, it looks like the order for this instrument gets cancelled ("Cancelled custom managed order at ...") but somehow it still prevents a new long limit being accepted for this instrument. Could you shed some light as to what I might have done wrong here? May it be it's a NJ bug?? It's quite important to note that this behaviour doesn't occur for the 0th or 1st bar series.
Thanks a lot!
The timestamps may be a bit misleading. I'm logging all activities on the 1 min chart and there the timestamps are correct (i.e. all long limit submissions at 8:30 am and the cancel at 3:55 pm the same day)
Cheers,
Ipso
Leave a comment:
-
There may be some C# techniques for this, but is beyond our scope of support. A related thread on our forums is available here:
CancelOrder() is looking for an IOrder object passed in, and this sample can help with the approach to using it:
When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until
Leave a comment:
-
Originally posted by NinjaTrader_RyanM View PostHello ipso33,
Yes, you can enable TraceOrders = true; in the strategies Initialize() method, and view output related to this using Tools > Output window. You are likely running into internal order handling rules, detailed here:
http://www.ninjatrader.com/support/h...d_approach.htm
Cheers,
Ipso
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by maykingoh1, Today, 05:25 AM
|
0 responses
1 view
0 likes
|
Last Post
by maykingoh1
Today, 05:25 AM
|
||
Started by Human#102, Today, 05:18 AM
|
0 responses
4 views
0 likes
|
Last Post
by Human#102
Today, 05:18 AM
|
||
Started by ntram, 05-08-2024, 05:39 PM
|
3 responses
21 views
0 likes
|
Last Post Today, 05:17 AM | ||
Started by Zach55, 02-19-2024, 07:22 PM
|
3 responses
68 views
0 likes
|
Last Post Today, 05:16 AM | ||
Started by warpinator, 05-16-2024, 10:44 AM
|
3 responses
30 views
0 likes
|
Last Post Today, 05:14 AM |
Leave a comment: