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

OnExecutionUpdate() not triggering

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

    OnExecutionUpdate() not triggering

    Hello,

    I am trying to create a bot that sends screenshots to Telegram every time I place an order manually (OrderState == Filled).
    However, I have tried to do it with the method OnExecutionUpdate() but seems like, even If I place an order, the code does nothing:

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    // Remember to check the underlying Order object for null before trying to access its properties
    Print(execution.Order.OrderState.ToString());
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)

    Print(execution.Order.OrderState.ToString());
    sendCombiMessage();

    }

    Even If I try to print the OrderStatus, it doesn´t work as much as I place orders.
    SendCombiMessage() is the function to send screenshots to Telegram.
    Is there anything I'm doing wrong? Do I need something more so the function triggers when I place orders manually?

    Thanks in advance

    #2
    Hi mrcma, instead of this:
    Code:
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
    Print(execution.Order.OrderState.ToString());
    sendCombiMessage();
    try something like this:
    Code:
    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled)
    [COLOR=#e74c3c][B]{[/B][/COLOR]
       Print(execution.Order.OrderState.ToString());
       sendCombiMessage();
    [COLOR=#e74c3c][B]}[/B][/COLOR]
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    Comment


      #3
      Hello mrcma,

      Thank you for your post.

      It looks like you've got this within a Strategy, is that correct?

      OnExecutionUpdate() as you're calling it would not see orders placed manually - only the orders from the strategy would be recognized. For that, you would need to utilize the Add-on approach.



      Note the difference in the method parameters and that you need to get the overall account first.

      sidlercom80 is also correct in noting you're missing brackets to trigger the prints and send a message if the order variable is not null and the state is filled.

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

      Comment


        #4
        Hello, thank you so much for your answer.

        Even using the curly brackets in the if statement doesn't work.
        It prints nothing when I submit orders.

        Thanks in advance

        Comment


          #5
          Hello mrcma,

          Thank you for your reply.

          To clarify, when a strategy order fills you're not seeing the print statement printing to the NinjaScript Output window, nor is it sending the message to Telegram, is that correct? Or do you see that print when the order fills, but not see the Telegram message sent?

          Thanks in advance; I look forward to assisting you further.

          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hello!

            Thank you so much for all your replies.
            Yes, I'm trying to implement it in a Strategy; but it doesn't matter either is an indicator tr a strategy.
            To summarize: I need to send a message and a screenshot to Telegram (using Telegram API, I already have this code) every time I click to buy or sell something (place an order).
            At this moment, I got an indicator that sends a message to Telegram every time I double-click on the chart,
            So I thought the next step would be to make it a strategy that captures the order.state but, thanks to NinjaTrader_Kate I realize I need to use the Add-On approach (I'm having problems with it).
            And to answer Kate,, I'm not seeing neither the print in the Output nor the Telegram Message when I tried the Strategy approach.


            So I guess, I need a function that triggers every time I place an order manually so I can place my sendCombiMessage() into it.

            Thank you so much

            Comment


              #7
              Hello mrcma,

              Thank you for your reply.

              We've got an example of monitoring the account that you could look at and modify. I'm attaching one my colleague made below that prints order information to the NinjaScript Output window you could try modifying to trigger your sendCombiMessage().

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

              Comment


                #8
                Hello,

                Thanks for your reply. I have used the template you sent and it outputs nothing, I tried it without adding anything to see if it works but it didn't output the info even when I placed an order.
                I have also tried to modify it so it sends the message when a condition is met but didn't work.
                I guess, unless I get to Output the info, so I can check it works, I won't be able to solve it.
                Code:
                private void OnExecutionUpdate(object sender, ExecutionEventArgs e)
                {
                // Output the execution
                NinjaTrader.Code.Output.Process(string.Format("Ins trument: {0} Quantity: {1} Price: {2}",
                e.Execution.Instrument.FullName, e.Quantity, e.Price), PrintTo.OutputTab1);
                if (e.Execution.Order != null && e.Execution.Order.OrderState == OrderState.Filled)
                {
                sendCombiMessage();
                }
                
                }
                Thank you so much for all your help

                Comment


                  #9
                  Hello mrcma,

                  Thank you for your reply.

                  To confirm, you are not seeing the original example script provided in my previous reply print information to the NinjaScript Output window (New > NinjaScript Output) when the indicator is applied to a chart, the account being used is selected in the indicator parameters window, and a manual trade is made on that account?

                  Please make sure you are testing the original, unchanged script and that the Output window is open prior to making a trade once the indicator is applied to the chart.

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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by SugarDefHealth, Today, 03:30 AM
                  0 responses
                  2 views
                  0 likes
                  Last Post SugarDefHealth  
                  Started by ETFVoyageur, Today, 02:08 AM
                  1 response
                  7 views
                  0 likes
                  Last Post ETFVoyageur  
                  Started by kujista, 04-22-2024, 07:46 AM
                  3 responses
                  12 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by kujista, 04-23-2024, 06:23 AM
                  7 responses
                  57 views
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by SentientDavid, Today, 01:34 AM
                  0 responses
                  8 views
                  0 likes
                  Last Post SentientDavid  
                  Working...
                  X