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

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 barsInProgressIndexstring signalNameint 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.
            Chris L.NinjaTrader Customer Service

            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.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by GussJ, 03-04-2020, 03:11 PM
                16 responses
                3,279 views
                0 likes
                Last Post Leafcutter  
                Started by WHICKED, Today, 12:45 PM
                2 responses
                19 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by Tim-c, Today, 02:10 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Taddypole, Today, 02:47 PM
                0 responses
                5 views
                0 likes
                Last Post Taddypole  
                Started by chbruno, 04-24-2024, 04:10 PM
                4 responses
                51 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Working...
                X