Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access to Previous Bar MarketPosition

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

    Access to Previous Bar MarketPosition

    Hi

    I need to access the MarketPosition in previous bars directly from the OnBarUpdate() method.

    Any hint as to what is the best way to accomplish it?

    Thanks

    #2
    Hello zerosum666,

    Unfortunately MarketPosition is not available for prior bars, only its current state. You could consider building this into a 3-state data series with something like the below. You could then reference prior bars of your data series.

    Please see here for help working with custom data series.

    Code:
    if(Position.MarketPosition == MarketPosition.Flat)
    myDataSeries.Set(0);
    
    else if (Position.MarketPosition == MarketPosition.Long)
    myDataSeries.Set(1);
    
    else if (Position.MarketPosition == MarketPosition.Short)
    myDataSeries.Set(-1);
    Ryan M.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    81 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    46 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    29 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    32 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    66 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X