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

How can I get Highs an Lows of bars on the chart?

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

  • NinjaTrader_ZacharyG
    replied
    Hello alex_bbfg,

    Printing out values across a certain period of bars can be done as below, using your example of starting at bar 12 and ending at bar 38:
    Code:
    private int startBar = 12;
    private int endBar = 38;
    
    protected override void OnBarUpdate()
    {
         if (CurrentBar >= startBar && CurrentBar <= endBar)
              Print("Bar " + CurrentBar + " High: " + High[0] + " Low: " + Low[0]);
    }
    CurrentBar outputs the value of the bar that the script is currently evaluating, starting at 0 (the left-most bar on the chart).

    Leave a comment:


  • alex_bbfg
    replied
    Hello ZacharyG,

    Thank you for the reply. Your code works, but I did not get the logic of CurrentBar.

    I would like compare bars' data with each other not from begining to end region but on some spethified region of the chart, So, how can I set the region of the bars fore example from bar 12 to bar 38 and compare bars' highs of that region?

    Regards.

    Leave a comment:


  • NinjaTrader_ZacharyG
    replied
    Hello alex_bbfg,

    Thank you for writing in.

    The reason why you are getting a run-time error is because you are attempting to access non-existent values.

    An indicator will run its logic on every historical bar. On the first bar, a previous bar does not exist. You are trying to check for High[i] and Low[i] for barsAgo values of 1 - 99. A barsAgo value of 1 would be the previous bar. 2 would be the one previous to that. So on and so forth.

    So, when you try to print High[1] on the first bar, you're going to get an error because no previous bar exists.

    You can simply use the code below to print the Highs and Low of each bar as your indicator evaluates over them:
    Code:
    protected override void OnBarUpdate()
    {
         Print(CurrentBar + " " + High[0] + " " + Low[0]);
    }
    A CurrentBar value of 0 would be the first bar on your chart. 1 the second, so on and so forth.

    Please, let us know if we may be of further assistance.

    Leave a comment:


  • How can I get Highs an Lows of bars on the chart?

    Hello Support,

    I'm developing the screept and need Highs and Lows of the bars on the 5 minutes chart.
    I use the following code but it gives incorrect data.

    int bars = 100;
    bool print = false;

    protected override void OnBarUpdate()
    {
    if (print == false)
    {
    for (int index = 0; index < bars; index++)
    {
    Print(index.ToString() + " " + High[index].ToString() + " " + Low[index].ToString());
    }

    print = true;
    }
    }

    The screen with the chart and output window attached. How can I get the correct values?

    Regards.
    Attached Files

Latest Posts

Collapse

Topics Statistics Last Post
Started by Brevo, Today, 01:45 AM
0 responses
6 views
0 likes
Last Post Brevo
by Brevo
 
Started by aussugardefender, Today, 01:07 AM
0 responses
3 views
0 likes
Last Post aussugardefender  
Started by pvincent, 06-23-2022, 12:53 PM
14 responses
242 views
0 likes
Last Post Nyman
by Nyman
 
Started by TraderG23, 12-08-2023, 07:56 AM
9 responses
384 views
1 like
Last Post Gavini
by Gavini
 
Started by oviejo, Today, 12:28 AM
0 responses
6 views
0 likes
Last Post oviejo
by oviejo
 
Working...
X