![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
I'm encountering issues where error codes are generated when I'm trying to move stops to breakeven... I've done TraceOrders == true;, and the following is the output.... but can't seem to figure out why it is giving an error....
PHP Code:
8/10/2009 10:32:30 AM Strategy Error on calling 'OnBarUpdate' method for strategy 'SkeletonTest2': Object reference not set to an instance of an object. This error is only generated when I have more than one contract
Last edited by BigDog008; 08-10-2009 at 09:42 AM.
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
my code is as follows:
Code:
// LONG ORDER A
if (longentryOrderA == null
&& golong == true
&& goshort == false
&& chop == false
&& Position.MarketPosition != MarketPosition.Short)
{
longentryOrderA = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 1 * TickSize, "LongA");
}
// BREAKEVEN STOPLOSS
if (longentryOrderA != null
&& longstopOrderA != null
&& longentryOrderA.OrderState == OrderState.Filled
&& GetCurrentBid() - longentryOrderA.AvgFillPrice >= 6 * TickSize)
{
longstopOrderA = ExitLongStop(0, true, longentryOrderA.Filled, longentryOrderA.AvgFillPrice, "LongStopA", "LongA");
}
// LONG ORDER B
if (longentryOrderB == null
&& golong == true
&& goshort == false
&& chop == false
&& Position.MarketPosition != MarketPosition.Short)
{
longentryOrderB = EnterLongLimit(0, true, DefaultQuantity, GetCurrentBid() - 1 * TickSize, "LongB");
}
// BREAKEVEN STOPLOSS
if (longentryOrderB != null
&& longstopOrderB != null
&& longentryOrderB.OrderState == OrderState.Filled
&& GetCurrentBid() - longentryOrderB.AvgFillPrice >= 4 * TickSize)
{
longstopOrderB = ExitLongStop(0, true, longentryOrderB.Filled, longentryOrderB.AvgFillPrice, "LongStopB", "LongB");
}
// SHORT ORDER A
if (shortentryOrderA == null
&& goshort == true
&& golong == false
&& chop == false
&& Position.MarketPosition != MarketPosition.Long)
{
shortentryOrderA = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 1 * TickSize, "ShortA");;
}
// BREAKEVEN STOPLOSS
if (shortentryOrderA != null
&& shortstopOrderA != null
&& shortentryOrderA.OrderState == OrderState.Filled
&& shortentryOrderA.AvgFillPrice - GetCurrentAsk() >= 6 * TickSize)
{
shortstopOrderA = ExitShortStop(0, true, shortentryOrderA.Filled, shortentryOrderA.AvgFillPrice, "ShortStopA", "ShortA");
}
// SHORT ORDER B
if (shortentryOrderB == null
&& goshort == true
&& golong == false
&& chop == false)
{
shortentryOrderB = EnterShortLimit(0, true, DefaultQuantity, GetCurrentAsk() + 1 * TickSize, "ShortB");
}
// BREAKEVEN STOPLOSS
if (shortentryOrderB != null
&& shortstopOrderB != null
&& shortentryOrderB.OrderState == OrderState.Filled
&& shortentryOrderB.AvgFillPrice - GetCurrentAsk() >= 4 * TickSize)
{
shortstopOrderB = ExitShortStop(0, true, shortentryOrderA.Filled, shortentryOrderB.AvgFillPrice, "ShortStopB", "ShortB");
}
protected override void OnExecution(IExecution execution)
// LONG ORDER A
if (longentryOrderA != null && longentryOrderA.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
longstopOrderA = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "LongStopA", "LongA");
longtargetOrderA = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 8 * TickSize, "LongTargetA", "LongA");
}
}
// LONG ORDER B
if (longentryOrderB != null && longentryOrderB.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
longstopOrderB = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 4 * TickSize, "LongStopB", "LongB");
longtargetOrderB = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 9 * TickSize, "LongTargetB", "LongB");
}
}
// SHORT ORDER A
if (shortentryOrderA != null && shortentryOrderA.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
shortstopOrderA = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 4 * TickSize, "ShortStopA", "ShortA");
shorttargetOrderA = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 8 * TickSize, "ShortTargetA", "ShortA");
}
}
// SHORT ORDER B
if (shortentryOrderB != null && shortentryOrderB.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
shortstopOrderB = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 4 * TickSize, "ShortStopB", "ShortB");
shorttargetOrderB = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 9 * TickSize, "ShortTargetB", "ShortB");
}
}
|
|
|
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
BigDog008, this error normally occurs when you try to access an empty object, the trace output you refer to just informs you the order is already placed and thus the next attempt to place it again is ignored.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
Bertrand,
I understand that, and I'm fine with that... the issue is, that once I start trying to manipulate more than one order at a time, I encounter an OnBarUpdate() Error as stated, and then the strategy ceases to place existing orders |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Likely has to do with trying to access a null IOrder object. Unfortunately the only thing to do would be to debug.
Please see this tip about null objects. http://www.ninjatrader-support2.com/...ead.php?t=4226
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Hey Josh, that fixed the problem.... as usual you're tops!
|
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Chart Trader - Moving Stops|Targets Above|Below Exposed Price of Market | TapeReader | Charting | 1 | 07-28-2009 01:14 PM |
| Manually moving/closing Strategy Stops/Targets | gg80108 | ATM Strategies (Discretionary Trading) | 1 | 03-14-2009 11:56 AM |
| Random generated as bar object? | geovani | General Programming | 6 | 01-26-2009 09:15 AM |
| Angle errors when moving lines | tobbe | Suggestions And Feedback | 5 | 09-08-2008 01:08 PM |
| Error generated by jumping stops | latkinso | Strategy Development | 5 | 01-03-2008 01:20 PM |