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

The name "order" does not exist in current context

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

    The name "order" does not exist in current context

    Hello,
    I'm trying to pull out the execution price for specific orders through OnExecutionUpdate and I pulled the code directly from the help guide.

    I'm receiving the "name "order" does not exist in current context" error.

    Code:
    private Order entryLongCeilingClose1A = null;
    
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (execution.Order.Name == "entryLongCeilingClose1A" && execution.Order.OrderState == OrderState.Filled)
    {
    entryLongCeilingClose1A = order; //this is where the error occurs
    }
    
    if (entryLongCeilingClose1A != null && entryLongCeilingClose1A == execution.Order)
    {
    exPriceClose1A = execution.Price;
    }
    }
    Also will my line
    Code:
     exPriceClose1A = execution.Price;
    work for storing the execution price for that specific order?

    Thanks

    #2
    Hello mlprice12,

    Thank you for your post.

    Looks like there might be an error in the example on the Executions page of the help guide that looks like where you got this code from.

    The following should work correctly:

    Code:
    private Order entryLongCeilingClose1A = null;
    
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (execution.Order.Name == "entryLongCeilingClose1A" && execution.Order.OrderState == OrderState.Filled)
    {
    entryLongCeilingClose1A = execution.Order; //there's no "order" available to this method, so you need to access the order stored in the execution with execution.Order
    
    if (entryLongCeilingClose1A != null && entryLongCeilingClose1A == execution.Order)
    {
    exPriceClose1A = execution.Price;
    }
    and yes, what you've got there should work for storing the execution.Price, assuming exPriceClose1A is initialized as a double variable somewhere in your script.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Great, thanks Kate. I'll give this code a try.

      Comment


        #4
        Hello Kate,

        I'm trying to add a custom Hotkey to change the order of an existing class level scope method.
        I'm getting these errors with the following snippet

        NinjaScript File Error Code Line Column
        myTestb.cs The name 'ChangeOrder' does not exist in the current context CS0103 6402 6
        NinjaScript File Error Code Line Column
        myTestbcs The name 'newStopLossPrice' does not exist in the current context CS0103 6402 18
        NinjaScript File Error Code Line Column
        myTestb.cs The name 'newStopLossPrice' does not exist in the current context CS0103 6402 36
        At Class Level (outside of the onBarUpdate)
        PHP Code:
            protected void ChartPanel_KeyDown(object senderKeyEventArgs e)
        {

              
        TriggerCustomEvent(=>
              {
                if (
        Keyboard.IsKeyDown(Key.NumPad1))
                {
                     
        ChangeOrder(newStopLossPricenewStopLossPrice.Quantity0Position.AveragePrice);
                }
              }, 
        null);
              
        e.Handled true;



        I don't understand why the ChangeOrder doesn't exist.
        I checked the doc and it seems to be correct (save for the class level scope location instead of the OnBarUpdate)
        https://ninjatrader.com/support/help...hangeorder.htm

        The newStopLossPrice refers to another private bool method also located at class level scope.

        What could be the reason and potential fix for these errors? Thanks!

        Comment


          #5
          Hello PaulMohn,

          Thank you for your reply.

          I'm not seeing compilation errors with the attached test script using your above code. Would you be able to provide a stripped down compilable example script demonstrating what you're trying that isn't working?

          Thanks in advance; I look forward to assisting you further.
          Attached Files
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thanks Kate for the request. Here's the complete code


            I commented line 6347 to export. The newStopLossPrice variable is not set at class level but within a method at line 2306.
            I see yours is at class level. How would you access it from the method instead? Thanks!

            Comment


              #7
              Hello PaulMohn,

              Thank you for your reply.

              ChangeOrder() is specific to the Strategy class. Since you're using an Indicator, ChangeOrder won't work, you need to use Addon code within the context of an indicator to place or change an order, for which you would want to use Change():



              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                All right thanks I'll try it now.

                Comment


                  #9
                  I've just checked the Change() doc and Addon doc and some related threads.
                  What's the Add On need about? How would I make use of it in my context (what's needed about it)?
                  How could I get the same result (changing the order) in an indicator without the Add On process (if possible I'd prefer not use an AddOn as I don't need it)? Thanks!

                  Comment


                    #10
                    Hello PaulMohn,

                    Thank you for your reply.

                    Indicators do not have the concept of an order in their class. You can use the add-on approach within the context of an indicator to access the account as you've already done and submit orders using Account.Submit() but you can't use Strategy specific methods like ChangeOrder(). There would not be a way around this, you're already using Add-on code within your indicator to create and submit orders. You have to use Change().

                    Note that add-on methods can be used within other script types so you don't have to create a whole add-on, you can use account.Change() within the indicator. You're already using Add-on methods to submit your orders initially:

                    Code:
                     if (Keyboard.IsKeyDown(Key.NumPad8))
                    {
                    sellMktOrder = account.CreateOrder(
                    Instrument,
                    OrderAction.Sell,
                    OrderType.Market,
                    OrderEntry.Manual,
                    TimeInForce.Day,
                    1,
                    0,
                    0,
                    "",
                    "sellMktOrder"+DateTime.Now.ToString(),
                    DateTime.MaxValue,
                    null);
                    }
                    
                    account.Submit(new[] { sellMktOrder });
                    Please let us know if we may be of further assistance to you.
                    Kate W.NinjaTrader Customer Service

                    Comment


                      #11
                      Ah, ok good news thanks! I didn't know the AddOn code was already in as the indicator is from the User Apps Share and I'm trying to add Hotkeys functionality (should have started by stating that ). I'll test adding Change(). Thanks again!

                      Comment


                        #12
                        Hello Kate,
                        I've modified the snippet but I'm not sure how to specify the order parameters from the doc example

                        PHP Code:
                        stopOrder.StopPriceChanged stopOrder.StopPrice stopOrder.Instrument.MasterInstrument.TickSize

                        I don't grasp what the StopPriceChanged and StopPrice refer to (there's no description in the doc)

                        It's different from the ChangeOrder() strategy one with identifiable parameters
                        ChangeOrder(Order order, int quantity, double limitPrice, double stopPrice)
                        PHP Code:
                        ChangeOrder(stopOrderstopOrder.Quantity0Position.AveragePrice); 

                        For example, how would you set the Position.AveragePrice as parameter for the stopPrice in the Change() code ?

                        I've tried this without result (it compiles but no result on the chart)
                        PHP Code:
                        TriggerCustomEvent(=>
                        {
                           
                        Order stopOrder null;

                           if (
                        Keyboard.IsKeyDown(Key.NumPad1))
                           {
                              
                        stopOrder.StopPriceChanged stopOrder.StopPrice stopOrder.Instrument.MasterInstrument.TickSize;
                           }

                           
                        account.Change(new[] { stopOrder });
                        }, 
                        null);
                        e.Handled true

                        How can we refer to the newStopLossPrice variable from an other method?

                        Would you know a working Change() sample close to my goal I could test and build from? Thanks!

                        Comment


                          #13
                          Hello PaulMohn,

                          Thank you for your reply.

                          I note you're creating a new Order object called stopOrder that you're setting to null before trying to change the stopPrice, but there's no actual order object held in that variable. The script you're trying to modify is extremely complex and I thus far have not seen a place where the actual stop losses are submitted, so I do not know what variable would hold a stop loss order object.

                          Orders submitted have a parameter called StopPriceChanged that, when updated, tells the system to change the StopPrice parameter to the new price. If the stopOrder variable contained an order and was not null, assigning a new value to the StopPriceChanged parameter then submitting the order using account.Change would change that price.

                          AddOn Framework NinjaScript Basic demonstrates changing an order price.

                          Please let us know if we may be of further assistance to you.
                          Kate W.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Kate and thanks for your advice (sorry for my late response, I was busy with some other project with Chelsea very helpful input).

                            So I've studied the Addon Framework Ninjascript Basic script you shared
                            and modified my snippet as
                            PHP Code:
                            TriggerCustomEvent(=>
                            {
                               
                            Order stopOrder null;

                               if (
                            Keyboard.IsKeyDown(Key.NumPad1)
                               && 
                            newStopLossPrice != null)
                               {
                                  
                            // stopOrder.StopPriceChanged = stopOrder.StopPrice - 4 * stopOrder.Instrument.MasterInstrument.TickSize;
                                  // moveOrder.StopPriceChanged = moveOrder.newStopLossPrice - 4 * moveOrder.Instrument.MasterInstrument.TickSize;
                                  
                            stopOrder.StopPriceChanged r.BarsSeries.GetClose() - Instrument.MasterInstrument.TickSize;
                                  
                            // stopOrder.Account.Change(new[] { stopOrder });
                            }

                            account.Change(new[] { stopOrder });
                            }, 
                            null);
                            e.Handled true
                            which I get the errors
                            The name 'newStopLossPrice' does not exist in the current context CS0103 6377 9

                            'object' does not contain a definition for 'BarsSeries' and no extension method 'BarsSeries' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) CS1061 6382 37

                            I note you're creating a new Order object called stopOrder that you're setting to null before trying to change the stopPrice, but there's no actual order object held in that variable.
                            With
                            PHP Code:
                            //    Order stopOrder = null; 
                            I get the error
                            The name 'stopOrder' does not exist in the current context CS0103 6382 6

                            The script you're trying to modify is extremely complex and I thus far have not seen a place where the actual stop losses are submitted, so I do not know what variable would hold a stop loss order object.
                            Ok. I found 2 hits for the stopOrder at lines 5484 and 5486.

                            Click image for larger version

Name:	notepad++_L6i8ZZ1ltg.png
Views:	220
Size:	1.01 MB
ID:	1193430

                            The control method starts at line 2302.

                            the newStopLossPrice declaration line and hits

                            Click image for larger version

Name:	notepad++_OOPun1aIfO.png
Views:	211
Size:	894.2 KB
ID:	1193429

                            Why are the errors thrown/it doesn't recognizes newStopLossPrice and stopOrder in spite of them being in the same class? Thanks for your insights!
                            Attached Files
                            Last edited by PaulMohn; 03-11-2022, 11:25 AM. Reason: set the images to full size

                            Comment


                              #15
                              Hello PaulMohn,

                              Thank you for your reply.

                              I will need to speak with my team leads about how best to proceed here. They are both out of the office today, so I will consult with them on Monday when they return.

                              Thanks in advance for your patience.
                              Kate W.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              384 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Started by oviejo, Today, 12:28 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post oviejo
                              by oviejo
                               
                              Working...
                              X