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