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 manueldecastro, Today, 10:26 AM
        0 responses
        2 views
        0 likes
        Last Post manueldecastro  
        Started by RaddiFX, Yesterday, 09:55 PM
        4 responses
        29 views
        0 likes
        Last Post RaddiFX
        by RaddiFX
         
        Started by geotrades1, Today, 08:33 AM
        5 responses
        16 views
        0 likes
        Last Post geotrades1  
        Started by Entwaze, 02-19-2024, 07:13 PM
        2 responses
        68 views
        0 likes
        Last Post MalachiHatfield  
        Started by tkaboris, Today, 08:32 AM
        5 responses
        13 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X