Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

execution.Order.FromEntrySignal.ToString() - Error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    execution.Order.FromEntrySignal.ToString() - Error

    Hi there!

    So, here is my code:

    Code:
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time){
                Logger("OnExecutionUpdate1:Execution of order: "+execution.Order.ToString());    
                Logger("OnExecutionUpdate2:"+execution.Order.FromEntrySignal.ToString());
            }
    Problem:
    Sometimes (I noticed this only with "name = 'Exit on session close'") I get the error "Object reference not set to an instance of an object".

    In the NinjaScript Output:
    HTML Code:
    ES 09-20 04.01.2020 0:59:00 OnExecutionUpdate1:Execution of order: orderId='NT-08694-3445' account='Backtest' name='Exit on session close' orderState=Filled instrument='ES 09-20' orderAction=BuyToCover orderType='Market' limitPrice=0 stopPrice=0 quantity=3 tif=Gtc oco='' filled=3 averageFillPrice=3214 onBehalfOf='' id=-1 time='2020-01-04 01:00:00' gtd='2099-12-01' statementDate='2020-06-12'
    Strategy 'strategy1v1/-1': Error on calling 'OnExecutionUpdate' method on bar 4080: Object reference not set to an instance of an object.
    So, I see "OnExecutionUpdate1:" line, and I does not see "OnExecutionUpdate2:".
    I assume that the error was caused by the line with "OnExecutionUpdate2:" .

    I do the following:

    Code:
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time){
                Logger("OnExecutionUpdate1:Execution of order: "+execution.Order.ToString());    
                //Logger("OnExecutionUpdate2:"+execution.Order.FromEntrySignal.ToString());
            }
    Result:
    The error does not appear.
    When I uncomment, it appears again.

    Questions:
    Why?
    What is the logical explanation?
    Why I can use "execution.Order.ToString()" and can not use "execution.Order.FromEntrySignal.ToString()"?
    More often it does not cause an error, but sometimes it causes - why?

    #2
    Hello webus,

    The error means the object you are using is null when you tried to use it. The FromEntrySignal would be null on an exit on session close order so calling a method on a null string is an error.

    If you are trying to just print the value you don't need to use .ToString() on a string object, you just need to print it and it will have no value. You can also check if the object is null:

    Code:
    if(string.IsNullOrEmpty(execution.Order.FromEntrySignal))
    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    43 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X