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

BarsSinceExit

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

    BarsSinceExit

    Hi,

    I am trying to add bars since exit condition to my trade logic, the code compiles however I am unable to enable the strategy with the line added. Can someone explain where I am going wrong? I am using Renko blocks could this be the issue, I'm guessing so. if this is the case how would I go about this?

    if (BarsSinceExit() >= 5
    && XavTrend1 == -5
    && ScalpTrader == 2
    && adxshort_in > ADXshort)

    )

    {

    {

    EnterShort(lots, "DT+DT");
    if (printtolog == true) Print("SHORT TRADE-----------RGAuto:");

    }

    #2
    Hello Gille1983,

    Thanks for your post.

    It looks like you are using BarsSinceExit() as part of your entry conditions. If there is no previous exit then the condition will never be true.

    You would need to check for either an exit (as you are now) or for the method to return a -1 value indicating there is no previous exit.

    Please see the example in the help guide that demonstrates checking for a number of bars or a -1 value: https://ninjatrader.com/support/help...ssinceexit.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      OK so looking at the example this would be the correct way ?

      if ((BarsSinceExit() > 5 || BarsSinceExit() == -1)
      && XavTrend1 == -5
      && XavTrend2 == -5)

      Comment


        #4
        Hello Gille1983,

        Thanks for your reply.

        Yes, if there was no previous exit the BarsSinceExit() method will return -1 allowing the entry to occur (assuming the other conditions were also true).

        After the first exit, the method will always return the number of bars since the last exit.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          ok and this should work on renko is that correct? I am still unable to enable the strategy with that line of code added

          Comment


            #6
            Hello Gille1983,

            Thanks for your reply.

            After adding the line of code, did you compile the strategy without errors?

            If successful, when you apply the strategy to a chart, are you connected to a live data feed, and did you set "Enabled" to true in the strategy parameters?

            If so, and the strategy does not run, please check the "log" tab of the control center for any error messages related to the strategy.


            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,403 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by Shai Samuel, 07-02-2022, 02:46 PM
            4 responses
            94 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Started by DJ888, Yesterday, 10:57 PM
            0 responses
            6 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by MacDad, 02-25-2024, 11:48 PM
            7 responses
            158 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Yesterday, 09:29 PM
            0 responses
            8 views
            0 likes
            Last Post Belfortbucks  
            Working...
            X