Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to use BarsSinceExitExecution as a condition

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

    How to use BarsSinceExitExecution as a condition

    // && (BarsSinceExitExecution(0, "", 0) > 0)
    // && (BarsSinceExitExecution() == 1)

    // && (BarsSinceExitExecution(0, "Stop loss", 0))
    // && (BarsSinceExitExecution(0,"TrendLongExit1",0) > 0)
    // || (BarsSinceExitExecution(0,"TrendLongExit2",0) > 0)


    I have tried multiple methods to achieve this without success

    I just want No entry until the next bar after exit of last position (i know that if there have been NO trades today that has to be also addressed

    #2
    Hello DTSSTS,

    Use prints to understand why the condition is not evaluating as true.

    Print the time of the bar and print all values used in the entire condition and also enable TraceOrders so we can see when the exit order is filling. Include labels so we can see what is being compared.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.


    Then include the output from the output window with your reply.

    Is BarsSinceExitExecution() returning a negative -1?

    Does the signalName supplied to BarsSinceExitExecution() match the signal name of the entry?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks I am looking for a User Actually using successfully

      Comment


        #4
        Hello DTSSTS

        I found it necessary to do a lot of housekeeping when my strategy position goes flat, so I record CurrentBar to a variable in OnPositionUpdate.

        Code:
                protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
                {
                    // Housekeep when position is flat
                    if (marketPosition == MarketPosition.Flat)
                    {
                        LastExitBarL = CurrentBar;
                        // Add other housekeeping
                    }
                }
        If you wanted to track the exit of multiple exit names, you could probably do something similar in OnExecutionUpdate (using execution.Order.Name and marketPosition).

        Hope this helps. Cheers!

        Comment


          #5
          Thanks I will give that some thought as well, good idea

          i am currently took from my first post and added to it (When i tried the first section it would not allow trades if i posted to my Long conditions and my Short conditions BUT would work if I only used on 1 directional condition (which i did ask support what might be the issue) but of course no direct answer

          Here is what I added, so far today no repeating intrabar trades, see what happens tomorrow, the issue seems to be something had to allow the first trade and the latter part did that

          && (BarsSinceExitExecution(0,"",0) > 0 || BarsSinceExitExecution(0,"",0) == -1)

          Comment


            #6
            In morning testing Live Real Time Data so far this has worked (amazed support did not mention i need to add the second part) which allows the first trade

            && (BarsSinceExitExecution(0,"",0) > 0 || BarsSinceExitExecution(0,"",0) == -1)

            Hope this saves someone the hours i spent

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            47 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            23 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            33 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            51 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Working...
            X