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

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 WHICKED, Today, 12:56 PM
        2 responses
        15 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Felix Reichert, Today, 02:12 PM
        0 responses
        1 view
        0 likes
        Last Post Felix Reichert  
        Started by Tim-c, Today, 02:10 PM
        0 responses
        1 view
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        49 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X