Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Critical Issue in Order.LimitPrice

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

    Critical Issue in Order.LimitPrice

    It looks Order class does not return the limitPrice that entered EnterLongLimit properly.

    Step to reproduce the problem

    1) I have a method to calculate price by Tick. TickSize is 0.1 in M2K instrument

    private double CalcPrice(int tick) { return tick * TickSize; }

    2) I call EnterLongLimit
    var limitPrice = CalcPrice(tick); // 1575.6
    var order EnterLongLimit(0, true, quantity, limitPrice, signalName);
    Print(limitPrice); //1575.6
    Print(order.LimitPrice); //1575.6
    Print(price==order.limitPrice); false !!!

    My work has been cut out to grab the bug. it looks the result have some decimal To fix that I need to Round the result in every compare. It doesn't happen on any numbers and very difficult to reproduce.



    #2
    Hello ManTrader,

    Thank you for the post.

    I can see a couple of problems in the sample provided.

    The first is that you are testing for equality on double numbers which will not often equate to true. This is a part of C# and how floating point numbers are stored.

    Code:
    Print(price==order.limitPrice);
    It is not suggested to use == for floating point numbers, instead you can do floating point comparisons as described here: https://ninjatrader.com/support/help...arithmetic.htm

    The second problem is that you are checking the order directly after submitting the order, it is generally suggested to collect the order instance from the OnOrderUpdate or OnExecutionUpdate overrides before accessing the values of the order to make sure it was successful. The prices you set should be fine to check however if you are looking for other values such as the fill price, you will need to start using the overrides. It is generally good practice to form your orders as variables as shown in the following sample rather than assigning the variable directly as you have: https://ninjatrader.com/support/help...and_onexec.htm

    In reference to the above sample, placement for your print could be in OnOrderUpdate after the line:
    Code:
    entryOrder = order;
    Please let me know if I may be of additional assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X