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

Real time vs Market Replay differences

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

    Real time vs Market Replay differences

    I have this block of code that changes shortsallowed and longsallowed flags depending on the last entry direction. The EnterShortPositiosnIfAllowed() is the function that enters the positions, and ShortsAlowed have to be true for that condition to trigger. It works fine in market replay, but in real time it is not working correctly. Based on my debugging i feel like it is flipping the flag before it runs EnterShortPositionsIfAllowed() which i could see is possible as it will run everything in the statement at the same time. But i just want to confirm this as it is working in market replay, would the two behave differently?

    // Close Longs and enter Shorts
    else if (Close[0] < emaLow)
    {

    Print("LongsAllowed/ShortsAllowed: " + longsAllowed + "/" + shortsAllowed);
    if (!(Position.MarketPosition == MarketPosition.Short))
    {
    ExitLong();
    foreach (var order in Orders)
    {
    if ((order.OrderState == OrderState.Accepted) || (order.OrderState == OrderState.Working))
    {
    CancelOrder(order);
    }
    }
    EnterShortPositionsIfAllowed();
    shortsAllowed = false;
    longsAllowed = true;
    }
    }​

    #2
    Its very odd why i am getting totally different behaviour between the two. Actually i thought the only differences should be minor differences in prices and fills?

    Comment


      #3
      Hello sofortune,

      using the Orders collection is generally not expected so that may be part of the problem. If you are trying to store orders as variables you would usually do that by using OnOrderUpdate or OnExecutionUpdate which maintains the order of operations to store variables. Outside of using prints there is not really anything we could say just by observing this code, you would need to run the code in both use cases and see if some part of that is executing differently. You can see an example of using the order events in the following link: https://ninjatrader.com/support/help...and_onexec.htm

      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      16 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      4 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,785 views
      0 likes
      Last Post Leafcutter  
      Started by poplagelu, Today, 05:00 AM
      0 responses
      3 views
      0 likes
      Last Post poplagelu  
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,407 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X