• 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

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

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

  • alex_bbfg
    started a topic How can I get Highs an Lows of bars on the chart?

    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

  • 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:

Latest Posts

Collapse

Topics Statistics Last Post
Started by TazoTodua, Today, 12:21 AM
0 responses
7 views
0 likes
Last Post TazoTodua  
Started by U0000999, Today, 12:20 AM
0 responses
7 views
0 likes
Last Post U0000999  
Started by sidviciousX, Yesterday, 06:47 AM
1 response
21 views
0 likes
Last Post bltdavid  
Started by Mykro, Yesterday, 10:22 PM
0 responses
10 views
0 likes
Last Post Mykro
by Mykro
 
Started by rudccv, Yesterday, 08:42 PM
0 responses
6 views
0 likes
Last Post rudccv
by rudccv
 
Working...
X