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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X