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 frslvr, 04-11-2024, 07:26 AM
            9 responses
            120 views
            1 like
            Last Post caryc123  
            Started by rocketman7, Today, 09:41 AM
            4 responses
            15 views
            0 likes
            Last Post rocketman7  
            Started by selu72, Today, 02:01 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by WHICKED, Today, 02:02 PM
            2 responses
            14 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by f.saeidi, Today, 12:14 PM
            8 responses
            21 views
            0 likes
            Last Post f.saeidi  
            Working...
            X