Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Occurrence Counter for testing in Strategy Builder - Counts when conditions are met

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

    Occurrence Counter for testing in Strategy Builder - Counts when conditions are met

    I'm creating a simple utility in Strategy Builder which will accumulate and report the total number of times indicator conditions were met over a given period.

    For ease of explanation let's consider a one min. chart (any symbol) with one week of data. For indicators place a SMA34 (fast) and SMA50 (slow) on the chart. The occurrence counter needs to report how many times the SMA34 crossed above the SMA50 one bar ago. A running total would be placed on the chart at each occurrence.

    I have a solution partially working using Strategy Builder however I'm missing one piece of the puzzle. A numeral appears where it should, however it is not an accurate count. I don't think the existing total number of occurrences is being sustained bar by bar until the next occurrence, then added to.

    The strategy uses a Custom Series array labelled "Counter" (int). Using a variable does not work since we cannot attribute a bar offset in the action settings. I've attached the zip file in case anyone would like to test it out.

    Counter[0] = (Counter[1] + 1); This should add 1 to the existing total. It does but only sometimes. If you try the test strategy and scroll through the chart you will see what I mean.

    Draw.Text(this, @"Text_1 " +Convert.ToString(CurrentBars[0]), Convert.ToString(Counter[0]), 1, (Low[0] - 1) ); This text drawing does place the numeral in the correct location.

    Thanks for the help.
    Attached Files

    #2
    Hello culpepper,

    Thanks for your post.

    Since the code you shared was exported as an assembly (dll), I am unable to view the code of the script to determine exactly how the counter is being used.

    That said, you should add prints to the script if you have not already done so to understand exactly how the logic in the script is behaving. Once you understand how the script is behaving and how the counter is incrementing values, you could modify the strategy to better suit your overall goal.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    I have also attached a link below to a forum thread that contains an EventCounterExample script which you might find helpful.
    https://forum.ninjatrader.com/forum/...86#post1099186

    Let us know if we may assist further.​
    <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
      Hi BrandonH,

      Your reply is appreicated. The EventCounterExample posted by PaulH is precisely what I needed to see.

      I was missing other declarations in the additional Sets.

      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      56 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      132 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X