Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pb Open in a loop... entered other

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

    Pb Open in a loop... entered other

    Hello

    I loop from the bar previous to the current bar to the origin of the chart to detect the first change in trend but it doesn't work as expected...
    My code
    Code:
    for (index = 0; index < Count-1; index++)
    {
    if ( Open[index] ==Close[index+2] && Close[index] < Open[index] && Open[index] == Open[index+1] && Close[index+1]>Close[0])
    {
    TP = index+1;
    break;
    }
    
    }
    Click image for larger version

Name:	loop.png
Views:	155
Size:	10.2 KB
ID:	1271751
    In the image you can see that the two rightmost green peaks display the necessary decline to reach the last peak where the change in trend took place while the two peaks on the left are false.
    However, when I extract the data from the chart to test it in an app that I developed in Delphi, everything is correct.

    Furthermore, when I want to add a configuration to my test to only detect peaks where the Close is > close of the current bar, nothing is displayed and I get the following error message:
    Error on calling 'OnBarUpdate' method on bar 16: You are accessing an index with a value that is invalid since it is out-of-range. accessing a series [barsAgo] with a value.
    However, I have enough bars on my graph
    My condition is
    Code:
    if ( Open[index] ==Close[index+2] && Close[index] < Open[index] && Open[index] == Open[index+1] && Close[index+1]>Close[ 0])
    Finally I would like to extract this logic to make a function which would return the closed value of the detected bar but I don't know where to put it in my in order to have access to the Close value.​

    Thank you for your help, your advice, finally anything that will allow me to solve my problem ;-)
    Last edited by bicou; 10-06-2023, 06:06 AM.

    #2
    Hello bicou,

    You should loop through the number of processed bars with CurrentBar.

    for (index = 0; index < CurrentBar; index++)

    For any barsAgo index, this must be less than CurrentBar or it will be an invalid index.

    For example Close[index+2] will cause an invalid index if the index variable is greater than CurrentBar minus 2.

    Your loop could loop through until that bar.

    for (index = 0; index < CurrentBar - 2; index++)

    Below is a link to a forum post on index errors.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I was able to get my loop working "properly", although I can't explain why sometimes the loop doesn't stop at the first reversal but at the next one on the same levels...
      Strange.
      One last thing that I think is more C# but I dare it anyway.
      I'd like to put this loop in a function, but is there a space to be privileged so that the closes/Prices values are accessible?
      Thanks for this last clarification because I've been using Pascal since 1984 and even though I use delphi as much as possible for procedural functions, I have a lot of trouble with OOP.​

      Comment


        #4
        Hello bicou,

        If the method is called from OnBarUpdate() the price series will be available.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        636 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        366 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        107 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        568 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        571 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X