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

Create indicator

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

    Create indicator

    How to create an indicator that would count the number of consecutive candles for a specified period. Consecutive means several times in a row Open> Close or Close> Open.

    Regards!

    #2
    Hello U0000999,

    Thanks for your post.

    You would need to use an integer variable as a counter (one for each type, up/down bar). In coding, you would check to see if the Close is greater than open and if so to increment the Up counter as well as "reset" the down counter to zero. If the Open is greater than the close then increment the down counter and reset the Up counter.

    Or if you don't want to reset the counters you could just increment the counters.

    Here is a simple example where upCounter and downCounter are created as int at the class level.:

    if (Close[0] > Open[0])
    {
    upCounter++; // increment the up bar counter
    }
    else if (Close[0] < Open[0])
    {
    downCounter++; // incrementg the down bar counter
    }
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by percy3687, Today, 12:28 AM
    0 responses
    4 views
    0 likes
    Last Post percy3687  
    Started by sofortune, Yesterday, 11:45 PM
    1 response
    4 views
    0 likes
    Last Post sofortune  
    Started by zzeric, Yesterday, 11:23 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Pep de lou, Yesterday, 08:14 PM
    2 responses
    20 views
    0 likes
    Last Post bltdavid  
    Started by fingers, 12-15-2023, 08:44 AM
    6 responses
    140 views
    0 likes
    Last Post bltdavid  
    Working...
    X