Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Position.MarketPosition Shows Long when I'm not

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

    Position.MarketPosition Shows Long when I'm not

    Hi, can anyone help me figure out why the code below immediately returns Long and shows a profit or loss before a position is taken? I'm trying this in Simulation on Forex right now.


    if (Position.MarketPosition != MarketPosition.Flat)
    {
    Print("Open PnL: " + Position.GetProfitLoss(Close[0], PerformanceUnit.Currency));
    Print(Position.MarketPosition.ToString());
    }

    #2
    Hello,

    Welcome to our forums!

    We'd need to see more code without guessing, but to help isolate this for you, I'd suggest adding a check to see if this is returning in real-time data, or historical

    Print(Historical);

    This will return True when the bars/position calculated are historical, and false when they're real-time.

    If you would only like to run on real-time bars, you can add the following to the beginning of your OnBarUpdate():

    Code:
    if(Historical)
    return;
    MatthewNinjaTrader Product Management

    Comment


      #3
      Mathew, thank you very much, saved me from pulling the rest of my hair out.

      Can you tell me, is there any reason why I would not want that Historical code in any strategy I intend to run in real time?

      Comment


        #4
        If you plan on doing any backtesting, this will prevent it from running.
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        595 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        554 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X