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

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 kevinenergy, 02-17-2023, 12:42 PM
            118 responses
            2,778 views
            1 like
            Last Post kevinenergy  
            Started by briansaul, Today, 05:31 AM
            0 responses
            9 views
            0 likes
            Last Post briansaul  
            Started by traderqz, Yesterday, 12:06 AM
            11 responses
            28 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by PaulMohn, Today, 03:49 AM
            0 responses
            9 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Jason  
            Working...
            X