• 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

Most Recent Occurence

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

    Most Recent Occurence

    To check for the most recent occurence of a particular condition you can write something like:

    private int occuredBarsAgo = -1;

    for (int barsAgo = 0; barsAgo < CurrentBar; barsAgo++)
    if (SMA(10)[barsAgo] > SMA(20)[barsAgo])
    {
    occuredBarsAgo = barsAgo;
    break;
    }

    Ray
    RayNinjaTrader Customer Service

    #2
    imported post

    Wouldn't this code snippet find the FIRST occurrence of the test case ... not the most recent. I believe you'd want to go backwards or count down from Current bar to 0 to find the most recent occurrence.

    Please advise if I am mistaken.

    Comment


      #3
      imported post

      You are mistaken.

      Do not confuse "CurrentBar" with an index value that represents the number of bars ago.

      Ray
      RayNinjaTrader Customer Service

      Comment


        #4
        imported post

        Sorry ... you are correct. I misread how the index was being used. I thought the code was just cycling through the bars on the chart starting at index 0.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by martyn73, Today, 05:27 PM
        0 responses
        5 views
        0 likes
        Last Post martyn73  
        Started by MichaelAlexander, 02-22-2017, 05:06 AM
        5 responses
        1,402 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by walter739, Today, 11:56 AM
        3 responses
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by kevinfloresz, Today, 09:46 AM
        4 responses
        29 views
        0 likes
        Last Post kevinfloresz  
        Started by digibob, 12-13-2019, 10:01 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X