Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry() - multi-timeframe strategy

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

    BarsSinceEntry() - multi-timeframe strategy

    Could someone please help me?

    I am trying to use BarsSinceEntry() to manage a scaled into position in a multi-timeframe strategy on NT 6.5. I’m having some problems with the relevant positioning of the entriesAgo in the BarsSinceEntry() function.

    I am trying to track the number of bars the “original” position has been in for. The strategy could scale into a number of positions. What is the right way to do this? When I get a number of positions in, there appears to be a referencing problem with BarsSinceEntry(). I do suspect it is my logic in that I’m not using the function correctly.

    The code is as follows:


    Code:
    int tempbars;
                        int numPos = 0;
                            
                        if (pos_counter > 1)
                            numPos = pos_counter - 1;
                        
                        if (pos_counter > 1) {
                            
                            tempbars = BarsSinceEntry(0, "Short Entry", numPos);
                            
                        } else {
                        
                            tempbars = BarsSinceEntry(0, "Short Entry", 0);
                        }
    The problem I’m seeing is that as soon as the second trade is entered, the position is exited because the a previous short position is referenced and returned by BarsSinceEntry; these values are out of range of the current day (e.g. 2024 or 33 hours with 1 min bars - the timeframe I'm working against). The previous position in the case I’m working to is within the day.

    Thanks in advance.

    Dan

    #2
    Hello Dan,

    There may be an easier solution here: Scale in with different signal names.

    You can then get the BarsSinceEntry value just for that signal. The next entry won't update the "EntriesAgo" value.

    Another approach is to manager the entry bar on your own. Capture the CurrentBar at the time of entry, and then subtract that value from CurrentBar later on.

    PseudoCode below;
    if (entryConditions)
    myEntryBar = CurrentBar;


    Later on:
    myBarsSinceEntry = CurrentBar - myEntryBar;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      Thanks very much for your reply.

      Thank you very much for the workaround solutions. The entrybar option looks like it could work. The other one (naming conventions) doesn’t really work. We could have a number of positions in a single direction, namely each one of the them probably isn’t feasible.

      Am I to understand that there is some sort of problem with BarsSinceEntry()? Is there a known error with this function with multi-timeframe strategies? Is my code incorrect?

      Thanks and regards,

      Dan

      Comment


        #4
        The issue here is that the EntriesAgo value will change as entries are scaled in. This makes it difficult to attach it to a specific entry unless you use unique names. It's not an issue with the function, just the way it behaves. You could probably adapt the logic to work for you, but the level of customization needed may prove more than writing your own tools to track the value.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan,

          Thanks again for your help.

          As per your recommendation, I’ll use the firstentrybar solution.

          Thanks and regards,

          Dan

          Comment

          Latest Posts

          Collapse

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