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

Sim and Live account giving different results than Market Replay

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

    Sim and Live account giving different results than Market Replay

    Hello.

    I have a strategy that works exactly as I intended when I run it in Market Replay. I went to put it on a live Sim account and it is not functioning anywhere near where it should be.

    if ((LongMarker != 1000000) && (State == State.Realtime) && (Mid >= LongMarker) && Position.MarketPosition != MarketPosition.Long)
    {
    CurrentOrder = EnterLong(Convert.ToInt32(DefaultQuantity), @"LONG");
    ATRReached = false;
    CurrentATR = ATR1[0] * ATRmulti;
    LongMarker = 1000000;
    EntryPrice = CurrentOrder.AverageFillPrice;
    ATRcheckpoint = EntryPrice + CurrentATR;
    Draw.Text(this, @"atrLine", @"ATR Checkpoint", 0, ATRcheckpoint);
    PositionHigh = EntryPrice + CurrentATR;
    RemoveDrawObject(@"Long1");
    RemoveDrawObject(@"Long1Text");
    Draw.HorizontalLine(this, @"checkpoint", false, ATRcheckpoint, Brushes.Green, DashStyleHelper.Solid, 2);
    }
    I'm fairly sure that this is the portion of code that is not working. It does get in long, but it appears to not execute ANY of the DrawObject code I have and it seems like ATRcheckpoint and PositionHigh do not get executed properly (or at all).

    What could be causing this? I dont even have the beginnings of a clue for whats going on here considering it works so well on Market Replay.

    #2
    Hello Plzwork123,

    Thank you for your note.

    I'm assuming all of this occurs in OnBarUpdate(), is that correct?

    First, we wouldn't recommend assigning an order to an order object in OnBarUpdate as it's pretty likely the order will not be filled yet if you try to access say, the Average Position price right after you've submitted it.

    I'd advise taking a look at this example from our help guide to see how to properly assign an order object to a variable which can then be accessed:



    Basically, I would advise trying the first part in OnBarUpdate and then the second part in OnOrderUpdate once you've assigned the processing order to your variable. So, something like this:

    Code:
    protected override void OnBarUpdate()
    {
    //other code goes here
    if ((LongMarker != 1000000) && (State == State.Realtime) && (Mid >= LongMarker) && Position.MarketPosition != MarketPosition.Long)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"LONG");
    ATRReached = false;
    CurrentATR = ATR1[0] * ATRmulti;
    LongMarker = 1000000;
    }
    }
    
    protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
    {
    // Handle entry orders here. The entryOrder object allows us to identify that the order that is calling the OnOrderUpdate() method is the entry order.
    // Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
    // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
    if (order.Name == "LONG")
    {
    CurrentOrder = order;
    EntryPrice = CurrentOrder.AverageFillPrice;
    ATRcheckpoint = EntryPrice + CurrentATR;
    Draw.Text(this, @"atrLine", @"ATR Checkpoint", 0, ATRcheckpoint);
    PositionHigh = EntryPrice + CurrentATR;
    RemoveDrawObject(@"Long1");
    RemoveDrawObject(@"Long1Text");
    Draw.HorizontalLine(this, @"checkpoint", false, ATRcheckpoint, Brushes.Green, DashStyleHelper.Solid, 2);
    
    // Reset the entryOrder object to null if order was cancelled without any fill
    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
    {
    CurrentOrder = null;
    sumFilled = 0;
    }
    }
    }
    If you draw the objects in OnOrderUpdate once the order is actually processing, do you see the objects drawn as you'd expect, or do they still not appear correctly?

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Kate,

      That did the trick.

      Thank you kindly for the help!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by selu72, Today, 02:01 PM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by WHICKED, Today, 02:02 PM
      2 responses
      7 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by f.saeidi, Today, 12:14 PM
      8 responses
      21 views
      0 likes
      Last Post f.saeidi  
      Started by Mikey_, 03-23-2024, 05:59 PM
      3 responses
      50 views
      0 likes
      Last Post Sam2515
      by Sam2515
       
      Started by Russ Moreland, Today, 12:54 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X