Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 Kensonprib, 04-28-2021, 10:11 AM
        5 responses
        191 views
        0 likes
        Last Post Hasadafa  
        Started by GussJ, 03-04-2020, 03:11 PM
        11 responses
        3,230 views
        0 likes
        Last Post xiinteractive  
        Started by andrewtrades, Today, 04:57 PM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        7 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        441 views
        0 likes
        Last Post Delerium  
        Working...
        X