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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    72 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    39 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X