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

GetBar Market Replay

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

    GetBar Market Replay

    Code:
    int intFirstBarOnChart = Times[1].Count - BarsArray[1].GetBar(Time[Time.Count - FirstBarIndexPainted]) -2;
    The code above does not execute correctly in market replay, however it works correctly normally. Is there any way to replicate the functionality of 'BarsArray[1].GetBar()' to get this to work correctly in market replay? i can't loop through the Times[1] dataseries either, it says the Count is 0.

    I have 2 data series in the chart. I generate the indicator in the 1 minute time frame, and display it on the chart, regardless of the original dataseries on the chart. The indicator uses the first painted bar and last painted bar on the chart and then finds the corresponding 1 minute timeframe bars to generate the data to display.

    #2
    habibalex, when you say it would not work for you, which prints would you get for your values / calcs vs. what would you expect to see? I gave the snippet a quick run replay vs regular from a chart and could not see an issue? Of you would need to call it on last bar of the chart to avoid running into referencing to many bars to the left at your chart 'start'.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Sorry I just looked at the code again and edited my previous response

      In market replay:
      Time[Time.Count - FirstBarIndexPainted] returns 5/8/2013 12:00:00 PM
      Time[Time.Count - LastBarIndexPainted] returns 5/30/2013 7:00:00 AM


      When not in market replay the same data:
      Time[Time.Count - FirstBarIndexPainted] returns 5/9/2013 11:30:00 AM
      Time[Time.Count - LastBarIndexPainted ] returns 5/30/2013 1:15:00 PM

      My chart according the databox says I am on:
      5/9/2013 12:00
      5/31/2013 7:00


      When I am at the right most edge of the chart (where market replay should be starting) in market replay I get:

      Time[Time.Count - FirstBarIndexPainted] 1/7/2013 11:39:00 AM
      Time[Time.Count - LastBarIndexPainted ] 1/8/2013 8:17:00 AM

      The data box says:
      5/13/13 13:15
      5/10/13 12:00
      When not in market replay:
      Time[Time.Count - FirstBarIndexPainted] 5/10/2013 11:00:00 AM
      Time[Time.Count - LastBarIndexPainted ] 5/31/2013 1:00:00 PM
      Last edited by habibalex; 02-17-2014, 06:36 PM.

      Comment


        #4
        habibalex, which symbol would you run on in your tests? Just printing for example those values directly out on the last bar of the chart I get consistent returns and what I would expect for historical data and replay going forward, i.e. seeing the current visible chart window moved bar by bar when doing the replay.

        if (Count - CurrentBar == 2)
        {
        int intFBOC = Times[1].Count - BarsArray[1].GetBar(Time[Time.Count - FirstBarIndexPainted]) -2;
        Print("Time[0]" + " " + Time.Count + " FB " + FirstBarIndexPainted + " FBOC " + intFBOC);
        }


        Does your outcome change if the internally added series is added manually to the chart in replay?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          This is the result I got when running your code
          Time[0] 17598 FB 17292 FBOC 1534
          Time[0] 17598 FB 17292 FBOC 1534

          I'm doin my calculations / drawing in the 'Plot' function on ES 03-14 and the date is 6/2/2013

          I edited your code to the following
          Code:
          intFirstBarOnChart = Times[1].Count - BarsArray[1].GetBar(Time[Time.Count - FirstBarIndexPainted]) -2;
          intLastBarOnChart = Times[1].Count - BarsArray[1].GetBar(Time[Time.Count - LastBarIndexPainted - 1]) -1;
          			
          int intFBOC = Times[1].Count - BarsArray[1].GetBar(Time[Time.Count - FirstBarIndexPainted]) -2;
          Print("Time[0]" + " " + Time.Count + " FB " + FirstBarIndexPainted + " FBOC " + intFBOC);
          Print(Times[1][intLastBarOnChart].ToString() + " " + Times[1][intFirstBarOnChart].ToString());
          When I am at the current most data I get (there is white space between the right margin and the last bar painted)
          Time[0] 87990 FB 17282 FBOC 70707
          3/20/2013 3:07:00 PM 3/20/2013 9:03:00 AM

          When I am scrolled a few bars back I get (there is no white space between the margin and the last bar painted)
          Time[0] 17598 FB 17282 FBOC 1634
          6/2/2013 6:19:00 PM 5/30/2013 3:55:00 PM

          The indicator appears to be working correctly when i am scrolled a few bars back. To get the indicator dates to come out correctly, I need to scroll back a few bars, and then refresh the chart (by pressing F5)
          Last edited by habibalex; 02-19-2014, 11:58 PM.

          Comment


            #6
            I figured it out, if anyone runs into this problem in the future the Time and Times array do not hold the same values for some reason when in market replay mode. Times has the correct value. Most likely a ninjatrader bug.

            I changed my code to the following
            Code:
            intFirstBarOnChart = Times[barNumber].Count - BarsArray[barNumber].GetBar(Times[0][Times[0].Count - FirstBarIndexPainted]) -2;
            intLastBarOnChart = Times[barNumber].Count - BarsArray[barNumber].GetBar(Times[0][Times[0].Count - LastBarIndexPainted - 1]) -1;

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Waxavi, Today, 02:10 AM
            0 responses
            3 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by TradeForge, Today, 02:09 AM
            0 responses
            9 views
            0 likes
            Last Post TradeForge  
            Started by Waxavi, Today, 02:00 AM
            0 responses
            2 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Started by elirion, Today, 01:36 AM
            0 responses
            4 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            4 views
            0 likes
            Last Post gentlebenthebear  
            Working...
            X