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 r68cervera, Today, 05:29 AM
            0 responses
            3 views
            0 likes
            Last Post r68cervera  
            Started by geddyisodin, Today, 05:20 AM
            0 responses
            6 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            35 views
            0 likes
            Last Post JonesJoker  
            Started by GussJ, 03-04-2020, 03:11 PM
            12 responses
            3,241 views
            0 likes
            Last Post Leafcutter  
            Started by AveryFlynn, Today, 04:57 AM
            0 responses
            7 views
            0 likes
            Last Post AveryFlynn  
            Working...
            X