Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by judysamnt7, 03-13-2023, 09:11 AM
    4 responses
    53 views
    0 likes
    Last Post DynamicTest  
    Started by ScottWalsh, Today, 06:52 PM
    4 responses
    32 views
    0 likes
    Last Post ScottWalsh  
    Started by olisav57, Today, 07:39 PM
    0 responses
    5 views
    0 likes
    Last Post olisav57  
    Started by trilliantrader, Today, 03:01 PM
    2 responses
    19 views
    0 likes
    Last Post helpwanted  
    Started by cre8able, Today, 07:24 PM
    0 responses
    6 views
    0 likes
    Last Post cre8able  
    Working...
    X