Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting price data of specific bar

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

    Getting price data of specific bar

    Hi,

    How should I write a code to get O,H,L,C of specific bar, for example, 9:35AM 5 min bar?

    Thank you very much for help in advance

    #2
    You use GetBar() to find the bar number of the time you want. Then you use Open[x] where x is the bar number you just got.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      GetBar number based on price

      Originally posted by NinjaTrader_JoshP View Post
      You use GetBar() to find the bar number of the time you want. Then you use Open[x] where x is the bar number you just got.
      In my code my primary timeframe is a renko chart and an additional bar series is added on say a one tick timeframe.

      In OnBarUpdate() we have something like

      double startpriceofsignal;
      double stopriceofsignal;

      //one tick chart
      if(BarsInProgress == 1)
      {
      startpriceofsignal = GetStartPriceSignal();
      stopriceofsignal = GetStopPriceSignal();

      }

      //main timeframe (renko chart)
      if(BarsInProgress == 0)
      {
      int startbarsignal = GetStartBar(startpriceofsignal);
      int stopbarssignal = GetStopBar(stopriceofsignal);
      }

      How would I implement GetStartBar(), GetStopBar() methods? So I'm trying to get bar numbers on the primary timeframe based on prices calculated from a signal on the lower timeframe 1 tick chart. Is there a way to map price to time on the lowertimeframe chart so I can then use GetBar(timevalue)?

      Comment


        #4
        Hello mballagan, and thank you for your question. If you are only interested in the most recent occurrences of a price, you can use this code,

        Code:
        [FONT=Courier New]private Dictionary<double, DateTime> mostRecentTimes;
        
        protected override void Initialize()
        {
            mostRecentTimes = new Dictionary<double, DateTime>();
        }
        
        protected override void OnBarUpdate()
        {
            mostRecentTimes[Close[0]] = Time[0];
        }[/FONT]
        You will then be able to use mostRecentTimes[Price] to retrieve the time that price was most recently reached, or 0 if that price point had not yet been reached.
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X