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

Using BarsSinceExitExecution()

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

    Using BarsSinceExitExecution()

    Hello,

    I have read a couple other posts on this topic and it seems it is necessary to unlock the code in Strategy Builder and manually enter the code in NinjaScript in order to cause a strategy to not execute a new trade within (n) of bars since the exit of last trade.

    I see the example code give in the help section is...
    ///////////////////////////////
    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 || BarsSinceE xitExecution() == -1) && CrossAbove(SMA(10), SMA(20), 1))
    EnterLong();
    }
    ///////////////////////////////

    My question is just where in my unlocked code precisely should this be entered? Along with the other conditions that must be met before my strategy goes long?

    Here is the excerpt of my code for my current conditions...

    ///////////////////////////////////////////////
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;

    // Set 1
    if ((Close[0] > Close[1])
    && (Close[0] > Close[2])
    && (Momentum1[0] > MomentumInt)
    && (Close[1] > Close[2])
    && (Swing1.SwingHigh[0] < (Close[0] + (-8 * TickSize)) )
    && (ChoppinessIndex1[0] < ChoppyEntry))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }
    //////////////////////////////////

    Would I just add the "&& ((BarsSinceExitExecution() > 10 || BarsSinceE xitExecution() == -1)" after the other conditions in Set 1?

    I did try this example but I got errors so not sure if its my syntax or the placement of the code.
    If it is too much work to answer this, I understand. Just please direct me to a helpful link that I might learn to understand how to work with NinjaScript better.

    Thanks.
    Last edited by George21; 03-25-2021, 12:24 PM.

    #2
    Hello George21,

    Bars since exit execution can be used in the Strategy Builder and this would be found in the Misc section.

    You can have a group condition to compare this to -1 or greater the value of a variable.

    Yes, this would be added to the existing condition set, if that is the condition set you want to prevent from triggering unless that condition is also true.

    If you have errors, post a screenshot of the errors.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello George21,

      Bars since exit execution can be used in the Strategy Builder and this would be found in the Misc section.

      You can have a group condition to compare this to -1 or greater the value of a variable.

      Yes, this would be added to the existing condition set, if that is the condition set you want to prevent from triggering unless that condition is also true.

      If you have errors, post a screenshot of the errors.
      I've looked in Strategy Builder but I can't figure how to make "or" statements in there as in ​​​

      if (n) is -1 or (n) is greater than 3, go long.

      I've been figuring out a bunch of other things, just getting stuck on this one.

      Comment


        #4
        Hello George21,

        Below is a link to a forum post with helpful information about getting started with NinjaScript.


        Please watch the Strategy Builder 301 training video which teaches every tool in the Strategy Builder.
        The 'AND' (if all) and 'OR' (if any) is discussed at 3 minutes 43 seconds.

        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello George21,

          Below is a link to a forum post with helpful information about getting started with NinjaScript.


          Please watch the Strategy Builder 301 training video which teaches every tool in the Strategy Builder.
          The 'AND' (if all) and 'OR' (if any) is discussed at 3 minutes 43 seconds.
          Awesome, thanks. I gotta say, you guys have some amazing customer support here.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by PaulMohn, Today, 05:00 AM
          0 responses
          8 views
          0 likes
          Last Post PaulMohn  
          Started by ZenCortexAuCost, Today, 04:24 AM
          0 responses
          6 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by ZenCortexAuCost, Today, 04:22 AM
          0 responses
          3 views
          0 likes
          Last Post ZenCortexAuCost  
          Started by SantoshXX, Today, 03:09 AM
          0 responses
          16 views
          0 likes
          Last Post SantoshXX  
          Started by DanielTynera, Today, 01:14 AM
          0 responses
          5 views
          0 likes
          Last Post DanielTynera  
          Working...
          X