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

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 gentlebenthebear, Today, 01:30 AM
        2 responses
        13 views
        0 likes
        Last Post gentlebenthebear  
        Started by Kaledus, Today, 01:29 PM
        2 responses
        7 views
        0 likes
        Last Post Kaledus
        by Kaledus
         
        Started by frankthearm, Yesterday, 09:08 AM
        13 responses
        45 views
        0 likes
        Last Post frankthearm  
        Started by PaulMohn, Today, 12:36 PM
        2 responses
        16 views
        0 likes
        Last Post PaulMohn  
        Started by Conceptzx, 10-11-2022, 06:38 AM
        2 responses
        56 views
        0 likes
        Last Post PhillT
        by PhillT
         
        Working...
        X