Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExitExecution() for MTF Strategy

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

    BarsSinceExitExecution() for MTF Strategy

    I would like to add the BarsSinceExitExecution() method to my strategy as is included in the help guide...

    PHP Code:
    protected override void OnBarUpdate()
    { 
      if (CurrentBar < BarsRequiredToTrade) 
          return; 
     
      // Only enter if at least 10 bars has passed since our last exit or if we have never traded yet
      if ((BarsSinceExitExecution() > 10 || BarsSinceExitExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
          EnterLong();
    } 
    
    ...however I want it to refer to the primary data series only (Minutes) and not to the secondary data series (Daily). The method signature in the help guide says this:

    PHP Code:
    BarsSinceExitExecution(int barsInProgressIndex, string signalName, int exitExecutionsAgo) 
    
    But how does the below statement need to look like then?

    PHP Code:
    if ((BarsSinceExitExecution() > 10 || BarsSinceExitExecution() == -1) 
    

    #2
    Hello sagetrade,

    Thank you for writing in.

    You could modify your script like the following,

    Using the last syntax at the following link,


    Add a Signal Name and BarsInProgress Index,

    Code:
    EnterLong(0, 1, “MyLong”);
    Then your BarsSinceExitExecution would look like the following for the primary series,

    Code:
    if ((BarsSinceExitExecution(0, “MyLong”, 0)
    > 10 || BarsSinceExitExecution(0, “MyLong”, 0)
    == -1)
    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you. Do I need to specify the signal name or can I leave that blank?

      PHP Code:
      if ((BarsSinceExitExecution(0, "", 0) > 10 || BarsSinceExitExecution(0, "", 0) == -1) 
      

      Comment


        #4
        Hello sagetrade,

        With the multi series script you should specify the signal name.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          How can I make sure this not only works for "MyLong" but also for "Stopp loss"?

          Comment


            #6
            Hello sagetrade,

            Thanks for the reply.

            If you need the BarsSinceExitExecution method to consider any exit, just leave the signal name as an empty string. For targeting specific executions specifying a signal name is required.

            Please let me know if I can assist further.

            Comment


              #7
              Originally posted by NinjaTrader_ChrisL View Post
              If you need the BarsSinceExitExecution method to consider any exit, just leave the signal name as an empty string. For targeting specific executions specifying a signal name is required.
              The method would consequently look like the below, then?
              PHP Code:
              if ((BarsSinceExitExecution(0, "", 0) > 10 || BarsSinceExitExecution(0, "", 0) == -1) 
              
              Are the exits triggered by below methods considered "any exit":

              ExitLongStopMarket()
              SetStopLoss()

              Comment


                #8
                Hello sagetrade,

                Thank you for the reply.

                That is correct. Any execution that brings your position from long to flat or short to flat is considered an exit execution.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                39 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                124 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                64 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                41 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X