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

NT Error Msg Box interrupts trading script

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

    NT Error Msg Box interrupts trading script

    Hi,
    I am trying to send stoplimit order on open tick of a new bar. It works 90% of the time. But sometimes NT tells me stoplimit buy orders cannot be created below last traded price.
    So it seems though the code condition is Close[0]<entryPrice, when the order gets to the broker, the new most recent close moved above entryPrice, so the order fails. Is there a way to check for this error without it giving a pop up and interrupt the script? Thanks

    int previousBar=-1;
    protected override void OnBarUpdate() //Calculate = Calculate.OnEachTick;
    {

    if (CurrentBar>previousBar)
    {

    if (Close[0]<entryPrice)
    {
    Order entryOrder = xAccount.CreateOrder(
    Instrument,
    OrderAction.Buy,
    OrderType.StopLimit,
    OrderEntry.Manual,
    TimeInForce.Day,
    1,
    entryPrice,
    entryPrice,
    "",
    "xEntryBuy" + CurrentBar,
    DateTime.MaxValue,
    null);
    }

    }

    previoiusBar=CurrentBar;
    }

    Also similiarly,
    I want to cancel existing not-filled entry orders on first tick of new bar, and send in new orders
    It works most of the time.
    But once a whlie NT will pop up message: cannot cancel filled order. So I guess that order got filled between the OrderStatus check and the Account.Cancel line. Would be great if there is a way to handle this without having a pop up window.

    protected override void OnBarUpdate() //Calculate = Calculate.OnEachTick;
    {

    for (int i=entries.count-1;i>=0;i--)
    {

    if (entries[i].OrderStatus==OrderStatus.Accepted)
    {
    xAccount.Cancel(new[] {entries[i]);
    }

    }

    }


    --edit:
    I think maybe to make the question more clear,
    is there a way to send in a buy order that is stoplimit by default, but if the exchange rejects it because price already moved above the desired entry price then automatically fall back to a limit buy order at the same entry price, all without having NT give a pop up error window and potentially stopping the script? - Thank you!
    Last edited by xxzbill; 10-22-2020, 08:07 AM.

    #2
    Hello xxzbill,

    Thank you for your post.

    There are no supported or documented means for suppressing error messages in NinjaTrader.

    In your script, I see you are using the Close price to offset your stop-limit order. Something you could do to reduce the chance of getting an order error is to use the most recent Bid/Ask price instead of the Close price to offset the stop-limit order. This could be done by using GetCurrentBid to get the most recent Bid price or GetCurrentAsk to get the most recent Ask price. GetCurrentBid/GetCurrentAsk skips NinjaTrader's data processing events and gets the most recent Bid/Ask price from the level 1 data feed.

    Here are some help guide links for more information.

    GetCurrentBid - https://ninjatrader.com/support/help...currentbid.htm

    GetCurrentAsk - https://ninjatrader.com/support/help...currentask.htm

    Please let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply.

      Since there is no certain way to suppress order execution error messages, does this pause the script?
      The script could be managing other existing orders, and it becomes very vulnerable if everything coded could be stopped by a exchange order execution error.
      Is there any way to control this risk when I want to leave an algo on overngiht?

      Comment


        #4
        Hello xxzbill,

        Thank you for your note.

        No, the error message does not pause the script. The script will continue running when the error message displays.

        Please let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by xxzbill View Post
          Thanks for the reply.

          Since there is no certain way to suppress order execution error messages, does this pause the script?
          The script could be managing other existing orders, and it becomes very vulnerable if everything coded could be stopped by a exchange order execution error.
          Is there any way to control this risk when I want to leave an algo on overngiht?
          Hi bill,

          Please, how and where do you define entryPrice in your StopLimit script ? Is this hard/manually coded ? I'm having challenges in my script for placing Limit and StopLimit orders just because of how the entryPrices are handled in the script and which I expect to be automatically submitted via button click actions.

          Best Regards.

          Omololu

          Comment


            #6
            Hi Omolulu,

            I run the script in onBarUpdate on each tick. entryPrice for me is High[1]+TickSize for a buy, if other conditions are met.

            double entryPrice=High[1]+TickSize;
            (then create order and so on)

            Hope it helps. It's always nice to have someone to discuss coding with.

            Comment


              #7
              Originally posted by xxzbill View Post
              Hi Omolulu,

              I run the script in onBarUpdate on each tick. entryPrice for me is High[1]+TickSize for a buy, if other conditions are met.

              double entryPrice=High[1]+TickSize;
              (then create order and so on)

              Hope it helps. It's always nice to have someone to discuss coding with.
              bill,

              Thank you very GREATLY.

              Omololu

              Comment


                #8
                Originally posted by xxzbill View Post
                Hi Omolulu,

                I run the script in onBarUpdate on each tick. entryPrice for me is High[1]+TickSize for a buy, if other conditions are met.

                double entryPrice=High[1]+TickSize;
                (then create order and so on)

                Hope it helps. It's always nice to have someone to discuss coding with.
                bill,

                Forgot to ask if you use ATM in your scripts. If Yes, could you please share the code snippets ?

                Regards.

                Omololu
                Last edited by omololu; 10-22-2020, 10:37 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by elirion, Today, 01:36 AM
                0 responses
                3 views
                0 likes
                Last Post elirion
                by elirion
                 
                Started by gentlebenthebear, Today, 01:30 AM
                0 responses
                4 views
                0 likes
                Last Post gentlebenthebear  
                Started by samish18, Yesterday, 08:31 AM
                2 responses
                9 views
                0 likes
                Last Post elirion
                by elirion
                 
                Started by Mestor, 03-10-2023, 01:50 AM
                16 responses
                391 views
                0 likes
                Last Post z.franck  
                Started by rtwave, 04-12-2024, 09:30 AM
                4 responses
                34 views
                0 likes
                Last Post rtwave
                by rtwave
                 
                Working...
                X