Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Count instances drawn dots per direction

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

    Count instances drawn dots per direction

    I have an indicator that draws a dot each time all of my conditions are true. And then a different color dot for when the reverse conditions are true. I'd like to be able to count the number of same color dot in a row. I have manually put text above the regions of dots to illustrate what I'm trying to count. This is not exactly what I'm trying to accomplish though.

    I've played around with the "Count" function but can't figure it out and I can't find any examples in the forum. It seems simple but I'm self taught in C# and haven't had to do anything like this in the past. My guess is I would set a variable and do a count of the number of times the conditions were true between the first instance of a color and the first instance of the next color. I just don't know the methods to use and where to start.

    Below I've included the basic logic of where I'm starting. Thanks in advance for any help!


    Code:
    if (
                    (BKADS1 > BKADS1_1
                    ||BKADS1 > MRange)
    
    
                    &&(BKADS2 > BKADS2_1
                    ||BKADS2 > LRange)
    
    
                    &&BKADS1 > -MRange
                    &&BKADS2 > -LRange
    
    
                    &&BKADS3_20 > BKADS3_21
                    &&BKADS3_30 > BKADS3_31
                    &&BKADS3_40 > BKADS3_41
                    &&BKADS3_50 > BKADS3_51
    
                    &&(
                    BKADS3_20 > BKADS3_21
                    &&BKADS3_21 < BKADS3_22
    
                    ||BKADS3_30 > BKADS3_31
                    &&BKADS3_31 < BKADS3_32
    
                    ||BKADS3_40 > BKADS3_41
                    &&BKADS3_41 < BKADS3_42
    
                    ||BKADS3_50 > BKADS3_51
                    &&BKADS3_51 < BKADS3_52
                    )
                    )
    
                    {
                        Draw.Dot(this,"Updot1"+CurrentBar,true,0,Close[0],Brushes.Blue);
                    }​
    
    else if (
                    (BKADS1 < BKADS1_1
                    ||BKADS1 < -MRange)
    
                    &&(BKADS2 < BKADS2_1
                    ||BKADS2 < -LRange)
    
                    &&BKADS1 < MRange
                    &&BKADS2 < LRange
    
                    &&BKADS3_20 < BKADS3_21
                    &&BKADS3_30 < BKADS3_31
                    &&BKADS3_40 < BKADS3_41
                    &&BKADS3_50 < BKADS3_51
    
                    &&(
                    BKADS3_20 < BKADS3_21
                    &&BKADS3_21 > BKADS3_22
    
                    ||BKADS3_30 < BKADS3_31
                    &&BKADS3_31 > BKADS3_32
    
                    ||BKADS3_40 < BKADS3_41
                    &&BKADS3_41 > BKADS3_42
    
                    ||BKADS3_50 < BKADS3_51
                    &&BKADS3_51 > BKADS3_52
                    )
                    )
    
                    {
                        Draw.Dot(this,"Downdot1"+CurrentBar,true,0,Close[0],Brushes.Orange);
                    }​
    Click image for larger version

Name:	B60XFD9.png
Views:	126
Size:	55.1 KB
ID:	1241634

    #2
    Hello BReal,

    Thanks for your post.

    This would require implementing counters in your script using custom C# logic to increment the counter when the Draw.Dot() method is called.

    You may create class-level int variables named something like dotUpCounter and dotDownCounter and increment the counter one line after the Draw.Dot() method is called.

    I have attached a simple example script that draws a dot when the SMA Fast plot crosses above the SMA Slow plot and draws a dot on the chart. A counter is incremented each time a dot is drawn and the script prints the count to the NinjaScript Output window. The script will also reset the counter to 0 on the first bar of a trading session.

    Please let me know if I may assist further.
    Attached Files
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      That's great! It was the "counter++" part that I couldn't figure out on my own. I know it's probably basic coding but I have huge gaps in my skills due to self teaching. Thanks again.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      559 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      546 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X