• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar first bar of the chart

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

    CurrentBar first bar of the chart

    Hello,

    CurrentBar is working only for on bar update? How do i get the first bar at the beginning of the chart, the one refreshing on update (right side of the chart)? I need the close of that bar in my OnRender calculation.

    I tried

    for(int barIndex =
    ChartBars.ToIndex -1
    ; barIndex <= ChartBars.ToIndex ; barIndex++)

    but no luck

    Thank you

    #2
    Hello frankduc,

    Thanks for your post.

    CurrentBar is the bar index of the current bar. The bar index for the first bar on a chart is 0. I suggest enabling Bar Indexes as well as BarsAgo indexes in your chart Data Box to better visualize these values.

    If you want CurrentBar to represent the developing bar in your indicator rather than the bar that had just closed, you will want to use Calculate.OnEachTick or Calculate.OnPriceChange.

    You may also test the snippet below.

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
        ClearOutputWindow();
        Print(string.Format("CurrentBar: {0} Close.GetValueAt(CurrentBar): {1} Close.GetValueAt(0): {2}", CurrentBar, Close.GetValueAt(CurrentBar), Close.GetValueAt(0)));
    }
    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      I have a strange problem.

      If i enter
      {
      ClearOutputWindow();
      Print(string.Format("CurrentBar: {0} Close.GetValueAt(CurrentBar): {1} Close.GetValueAt(0): {2}", CurrentBar, Close.GetValueAt(CurrentBar), Close.GetValueAt(0)));
      }

      The ouput window return close from bar 1 and bar 0 return 2833.25 when bar 1 return 2881.25.

      Where did he pick the 2833.25?

      It seem that this code is preventing or blocking any other Print().

      For exemple,



      Actually i just noticed that it block only Print() above the code. (edit)

      Last edited by frankduc; 06-12-2019, 01:24 PM.

      Comment


        #4
        Hello frankduc,

        To see the close value associated with Bar Index 0, please enable BarIndexes on your chart's Data Box and check the first bar on your chart. You will see that the Close value for Bar Index 0 in the Data Box matches the Close for Bar Index 0 in the output window. See attached screenshot.

        Other prints in the Output window are being cleared with ClearOutputWindow().

        I do not have enough information to provide input for your issue using your cmaave variable.

        If you are hitting a compiler error, I may encourage you to Google that error and look for external resources where others programming with C# have shared their experience. Further research on external resources is an absolute must for using any programming language.

        I may also encourage you to use the Strategy Builder to create some simple logic using variables created in the Inputs and Variables tab. When you click View Code, you can see the resulting NinjaScript syntax. I would suggest modelling after this if you are having issues using your own variables.

        I look forward to being of further assistance.
        Attached Files
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by akitenge, 06-14-2019, 02:54 PM
        4 responses
        27 views
        0 likes
        Last Post chartish  
        Started by siriusm, Today, 09:15 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by Duval, Today, 09:27 AM
        2 responses
        5 views
        0 likes
        Last Post Duval
        by Duval
         
        Started by chazyang, Today, 08:11 AM
        2 responses
        6 views
        0 likes
        Last Post chazyang  
        Started by Erwin Beckers, 11-04-2018, 02:39 AM
        6 responses
        79 views
        2 likes
        Last Post koganam
        by koganam
         
        Working...
        X