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

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by nandhumca, Yesterday, 03:41 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by The_Sec, Yesterday, 03:37 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by vecnopus, Today, 06:15 AM
    0 responses
    1 view
    0 likes
    Last Post vecnopus  
    Started by Aviram Y, Today, 05:29 AM
    0 responses
    5 views
    0 likes
    Last Post Aviram Y  
    Started by quantismo, 04-17-2024, 05:13 PM
    3 responses
    27 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X