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

about functions Bars.GetLow and Bars.GetHigh. They works bad

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

    about functions Bars.GetLow and Bars.GetHigh. They works bad

    Hello

    I `m trying to get Low price for Bar of current day by using function Bars.GetLow(Index). And Index = Bars.GetBar(Input_time).
    So, result is not the same that I see in Chart .
    Why? How I can read Low,High price of some historical bars of current day?

    #2
    Hello sergey_z,

    Thanks for your post.

    I have created a demonstration video showing how we can observe how these methods work. We are essentially looking at bar indexes and timestamps for those bar index which should not be confused with BarsAgo indexes. Using the Data Box to view Bar Indexes can also be helpful to identify what you are referencing from the script.

    Demo - https://drive.google.com/file/d/1f_L...w?usp=drivesdk

    Code:
        protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
        {
            base.OnRender(chartControl, chartScale);
            ClearOutputWindow();
            Print(String.Format("CurrentBar timestamp: {0} | Returned Index: {1} | CurrentBar low: {2} | CurrentBar low from Returned Index: {3}", 
            Time.GetValueAt(CurrentBar), Bars.GetBar(Time.GetValueAt(CurrentBar)), Bars.GetLow(CurrentBar), Bars.GetLow(Bars.GetBar(Time.GetValueAt(CurrentBar)))));
    
            // loop through only the rendered bars on the chart
            for(int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
            {
                // get the low price at the selected bar index value
                double lowPrice = Bars.GetLow(barIndex);
                Print("Bar #" + barIndex + " low price is " + lowPrice);
            }
        }
    Publicly available documentation on the items discussed can be found below.

    Bars.GetBar() - https://ninjatrader.com/support/help...-us/getbar.htm

    Bars.GetLow() - https://ninjatrader.com/support/help...-us/getlow.htm

    Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks but its doesn`t works. I have checked your method in MarketRaplay for CL02-19.

      I want to know Low,High,Open, Close values for Bar with specific timestamp. For example if now 10 AM , I need values for bar on 8AM or any other past Bar, time for request I will put like input parameter for some function.
      Attached Files

      Comment


        #4
        Hello sergey_z,

        We have enough information to see that this is an indexing issue. We can see that the returned index from the print shows 3, when the indexes for your chart show 804.

        I would suspect an indexing issue like this to come up if you are using a Multi Time Frame NinjaScript, since the example code simply uses CurrentBar and Bars in OnRender, instead of CurrentBars and BarsArray. Could you test the exported script I have attached which is a single time frame script?

        For more information on using CurrentBars and BarsArray for Multi Time Frame versions of CurrentBar and Bars.

        CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm

        BarsArray - https://ninjatrader.com/support/help...?barsarray.htm

        Please let me know if you are experiencing issues with the attached export. If you are, this would indicate a possible installation issue which we should troubleshoot.
        Attached Files
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks, but its works for Indicator. not for Strategy.
          I`m always have to use OnRender method?
          What is the simple way to read values from any bar,time for witch I will put like input parameter?

          Comment


            #6
            Hello sergey_z,

            Strategies and indicators follow the same indexing rules and there would not be a different testing the example as an indicator or strategy. The use of OnRender demonstrates that this approach can be taken outside of OnBarUpdate. You do not have to use OnRender. The approach you had noted in your first post should move you in the right direction. As mentioned in post #4, using CurrentBars and BarsArray will be important if you are using a multi time frame script so you can be sure you are referencing the right Bars object and associated index.

            Passing the appropriate BarsInProgress Index with BarsArray will be sure you are looking for the index on the right data series. You could consider the following where TIME is your input time variable and BIP is the BarsInProgress index for the data series you want to reference.

            Code:
            private double GetLowFromBar(int BIP, DateTime TIME)
            {
                return BarsArray[BIP].GetLow(BarsArray[BIP].GetBar(TIME));
            }
            BarsInProgress and some of these other multi time frame items are explained in the Multi Time Frame and NinjaScripts documentation. This guide provides a walkthrough for creating a Multi Series script and covers many nuances that should be considered when making such a script. If you have not reviewed this documentation its entirety, I would highly recommend doing so.

            Multi Time Frame and NinjaScripts - https://ninjatrader.com/support/help...nstruments.htm

            Let me know if you have any additional questions.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kempotrader, Today, 08:56 AM
            0 responses
            6 views
            0 likes
            Last Post kempotrader  
            Started by kempotrader, Today, 08:54 AM
            0 responses
            4 views
            0 likes
            Last Post kempotrader  
            Started by mmenigma, Today, 08:54 AM
            0 responses
            2 views
            0 likes
            Last Post mmenigma  
            Started by halgo_boulder, Today, 08:44 AM
            0 responses
            1 view
            0 likes
            Last Post halgo_boulder  
            Started by drewski1980, Today, 08:24 AM
            0 responses
            3 views
            0 likes
            Last Post drewski1980  
            Working...
            X