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 rocketman7, Today, 01:00 AM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by wzgy0920, 04-23-2024, 09:53 PM
            3 responses
            76 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            9 responses
            46 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by timko, Today, 06:45 AM
            1 response
            7 views
            0 likes
            Last Post gaz0001
            by gaz0001
             
            Started by Waxavi, 04-19-2024, 02:10 AM
            3 responses
            41 views
            0 likes
            Last Post gaz0001
            by gaz0001
             
            Working...
            X