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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X