Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData High[0] is previous high

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

    OnMarketData High[0] is previous high

    This writes out the previous bars high and not the building bars high. How do you get the high of the building bar?

    protected override void OnMarketData(MarketDataEventArgs e)
    {
    NinjaTrader.Code.Output.Process(High[0].ToString(), PrintTo.OutputTab1);




    #2
    Hello TradingDreamer,

    Thanks for your post.

    If you use the mode of Calculate.OnEachTick or Calculate.OnPriceChange, in OnBarUpdate() the bar index of [0] would point to the currently forming bar so High[0] would return high of the current bar. You would not need to use OnMarketData to find the current high.

    Comment


      #3
      That makes sense. However, my strategy is using Calculate.OnBarClose to separate out rules in BarClose and Market data. My workaround was to create a currentBarsHigh = new Series<double>(this, MaximumBarsLookBack.Infinite); and update the value in the OnMarketData if e.Last > currentBarsHigh[0] then currentBarsHigh[0] = e.Last. I think this is working to pass the values correctly to my custom indicator.

      Comment


        #4
        Hello TradingDreamer,

        Thanks for your reply.

        You might find it better to operate your code using Calculate.OnEachTick or CalculateOnPriceChange and then segment the code you want to run only once per bar to code that needs to access the current prices of the forming bar. This can be done by using a bool that is true once per bar. The system bool IsFirstTickOfBar can be used for that purpose. Reference: https://ninjatrader.com/support/help...ttickofbar.htm

        Here is a link to an example that demonstrates this: https://ninjatrader.com/support/help...either_cal.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        93 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        152 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        80 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        65 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X