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

Problem with order execution

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

    Problem with order execution

    Hi guys,
    I have written a very simple strategy to test the accuracy of order execution, because in some of our automated strategies I can see on chart, that it should working, but NT executes sometimes at undefined points (see on picture) or doesn't execute not at all, although the trigger has been touched.



    On the picture you can see on the right side the execution point. The position should be opened after a "cross below red line (Low[1]) - Go Short" or "cross above blue line (Median[1]) - Go Long". As you can see on the picture, the blue line wasn't triggered at all but NT has opened a long position.



    This is only one example. The test program runs on a simulation account live, the most orders are not executed on the trigger points and often - that's also great - executed contrary. On a "cross above green line (High[1])", where program shoud enter Long, it enters Short...? Here is the code, I don't know what could be the reason for this. The code is generated by the strategy builder.


    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // set 1
    if ((BlokLong != Median[1])
    && (Times[0][0].TimeOfDay >= new TimeSpan(8, 0, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(22, 0, 0))
    // Konditionsgruppe 1
    && ((CrossAbove(Close, High, 1))
    || (CrossAbove(Close, Median, 1))))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    BlokLong = Median[1];
    }

    // set 2
    if ((BlokLong != Median[1])
    && (Times[0][0].TimeOfDay >= new TimeSpan(8, 0, 0))
    && (Times[0][0].TimeOfDay <= new TimeSpan(22, 0, 0))
    // Konditionsgruppe 2
    && ((CrossBelow(Close, Low, 1))
    || (CrossBelow(Close, Median, 1))))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    BlokLong = Median[1];
    }


    Calculation mode is OnPriceChange
    Attached Files
    Last edited by Uwe1981; 09-28-2018, 02:23 AM.

    #2
    Hello Uwe1981,

    Thanks for your post.

    Considering that we see execution markers being placed at price levels outside of the bar, I may suspect that the PC clock is out of sync and the executions are being placed at price levels in consistent with what is displayed on the chart.

    You may follow the steps below to resync the PC clock.
    • Shutdown NinjaTrader
    • Right-click the clock in the lower right corner of your desktop
    • Select Adjust date/time
    • For Windows 10 click 'Additional date, time, & regional settings' -> then click 'Set the time and date'
    • Select the 'Internet Time' tab at the top
    • Set the server to time.nist.gov and then click Update.
    • If the message that appears says successful your PC clock should now be updated.
    • If not, select a different server from the Server: drop-down and try again (repeat until one of the servers is successful)


    After re-syncing the PC clock, please restart NinjaTrader and Reload All Historical Data before testing again.

    As a tip to further examine what is happening with a strategy, we advise to use debugging prints to monitor the logic as it is executing. This way you can see the values that are being used to evaluate each condition in your strategy. This can also make clock issues apparent if you see values that are evaluating in the strategy that are not consistent with what is being displayed on a chart. I've included a video showing how debugging prints can be used in the Strategy Builder.

    Debugging with the Strategy Builder - https://www.screencast.com/t/8uvjfM8h

    If you are still encountering this issue after re-syncing the PC clock, could you provide the debug output from the NinjaScript Output window with prints added to your strategy similar to those described in the video?

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    151 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Working...
    X