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 08-10-2009, 09:38 AM   #1
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default Errors Generated when moving stops

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/7/2009 8:35:28 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:28 AMAction=SellShort OrderType=Limit Quantity=1 LimitPrice=1005.50 StopPrice=0 SignalName='ShortA' FromEntrySignal=''
8/7/2009 8:35:28 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:28 AMAction=SellShort OrderType=Limit Quantity=1 LimitPrice=1005.50 StopPrice=0 SignalName='ShortB' FromEntrySignal=''
8/7/2009 8:35:35 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:35 AMAction=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1006.50 SignalName='ShortStopA' FromEntrySignal='ShortA'
8/7/2009 8:35:35 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:35 AMAction=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1003.50 StopPrice=0 SignalName='ShortTargetA' FromEntrySignal='ShortA'
8/7/2009 8:35:35 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:35 AMAction=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1006.50 SignalName='ShortStopB' FromEntrySignal='ShortB'
8/7/2009 8:35:35 AM Entered internal PlaceOrder() method at 8/7/2009 8:35:35 AMAction=BuyToCover OrderType=Limit Quantity=1 LimitPrice=1003.25 StopPrice=0 SignalName='ShortTargetB' FromEntrySignal='ShortB'
8/7/2009 8:36:31 AM Entered internal PlaceOrder() method at 8/7/2009 8:36:31 AMAction=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1005.50 SignalName='ShortStopB' FromEntrySignal='ShortB'
8/7/2009 8:36:31 AM Amended matching orderAction=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1005.50 SignalName=ShortStopB' FromEntrySignal='ShortB'
8/7/2009 8:37:56 AM Cancelled pending exit order, since associated position is closed: Order='
4856d51404d747ea9630d240d0984e2e/Replay101' Name='ShortStopA' State=Accepted Instrument='ES 09-09' Action=BuyToCover Limit price=0 Stop price=1005.5 Quantity=1 Strategy='SkeletonTest2' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4856d51404d747ea9630d240d0984e2e' Gtd='12/1/2099 12:00:00 AM'
8/7/2009 8:37:56 AM Entered internal PlaceOrder() method at 8/7/2009 8:37:56 AM: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1003.75 StopPrice=0 SignalName='
ShortA' FromEntrySignal=''
8/7/2009 8:37:56 AM Entered internal PlaceOrder() method at 8/7/2009 8:37:56 AM: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1005.50 SignalName='
ShortStopB' FromEntrySignal='ShortB'
8/7/2009 8:37:56 AM Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1005.50 SignalName=ShortStopB' 
FromEntrySignal='ShortB' Reason='There already is a matching order with same prices and quantity'
8/7/2009 8:37:56 AM Entered internal PlaceOrder() method at 8/7/2009 8:37:56 AMAction=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1005.50 SignalName='ShortStopB' FromEntrySignal='ShortB'
8/7/2009 8:37:56 AM Ignored PlaceOrder() methodAction=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1005.50 SignalName=ShortStopB' FromEntrySignal='ShortB' Reason='There already is a matching order with same prices and quantity'
Cancelled custom managed order at 8/7/2009 8:37:56 AM: Order='
50b68f7da0fd466b9c016aa2d44727b5/Replay101' Name='ShortA' State=Working Instrument='ES 09-09' Action=SellShort Limit price=1003.75 Stop price=0 Quantity=1 Strategy='SkeletonTest2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='50b68f7da0fd466b9c016aa2d44727b5' Gtd='12/1/2099 12:00:00 AM'
8/7/2009 8:37:56 AM Cancelled pending exit order, since associated position is closed: Order='
5ef40f3540d842d193ee2d46e93c2685/Replay101' Name='ShortStopB' State=Accepted Instrument='ES 09-09' Action=BuyToCover Limit price=0 Stop price=1005.5 Quantity=1 Strategy='SkeletonTest2' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='5ef40f3540d842d193ee2d46e93c2685' Gtd='12/1/2099 12:00:00 AM 
the error code is

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.
BigDog008 is offline  
Reply With Quote
Old 08-10-2009, 09:41 AM   #2
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

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");
                }
            }
BigDog008 is offline  
Reply With Quote
Old 08-10-2009, 09:51 AM   #3
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

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.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 08-10-2009, 11:44 AM   #4
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

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
BigDog008 is offline  
Reply With Quote
Old 08-10-2009, 11:47 AM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

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
NinjaTrader_Josh is offline  
Reply With Quote
Old 08-10-2009, 12:04 PM   #6
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
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

Hey Josh, that fixed the problem....

as usual you're tops!

BigDog008 is offline  
Reply With Quote
Reply

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
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


All times are GMT -6. The time now is 06:34 PM.