Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars since exit & Market position is flat

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

    Bars since exit & Market position is flat

    Hi there,

    Is there a way to build a simple working strategy where the strategy waits X Bars (let’s say 3 bars) before it’s allowed to execute next entry?

    I intended to use this way the BarsSinceExitExecution to do that as in the following logic:

    {
    If
    (
    my conditions are met
    && (BarsSinceExitExecution() == -1)
    )
    {Enterlong}

    Else if
    (
    my conditions are met
    && (BarsSinceExitExecution() >=3)
    )
    &&(BarsSinceExitExecution() == -1)
    {Enterlong}
    }

    However, it seems something wrong with it and it automatically disables my strategy. Is there anyway around it?

    Another question: what’s the difference between (BarsSinceExitExecution) vs. (MarketPosition.long == MarketPosition.Flat)? I tried using it but the same results

    #2
    Hello Abdullah_KSA,

    Thanks for your post.

    Anytime your strategy becomes disabled, check the "Log" tab of the NinjaTrader control center for any related error messages as when a strategy is disabled there will be a message.

    Regarding BasrSinceExitExecution(), On the first time through, if there was no previous execution, BarSinceExitExecution() will return a -1. After the first exit execution, the method will return the bars ago of the last exit.

    So you may want to write it like:

    if (your entry conditions && (BasrSinceExitExecution() == -1 || BarsSinceExitExecution() >= 3))
    {
    EnterLong();
    }


    The Long order will be placed if your entry condition are true AND there was no previous entry (-1) OR there are at least 3 bars since the last exit.

    If you have added a data series, you would need to use the method signature shown in the help guide (link below).

    Reference: https://ninjatrader.com/support/help...texecution.htm


    Regarding, "what’s the difference between (BarsSinceExitExecution) vs. (MarketPosition.long == MarketPosition.Flat)?". BarsSinceExitExecution() will return a value. The position condition is incorrectly written and would always be false. This should be written as Position.MarketPosition == MarketPosition.Flat or Position.MarketPosition == MarketPosition.Long. For example:

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    // do something when in a flat position
    }
    if (Position.MarketPosition == MarketPosition.Long)
    {
    // do something when in a long position
    }


    Reference: https://ninjatrader.com/support/help...etposition.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul,
      I tried what you highlighted on disabling the Strategy, below is the scribbled message I got from my log:

      Time Category Message 7/13/2020 8:43:54 PM Default Strategy 'TestTwo': Error on calling 'OnBarUpdate' method on bar 591: Strategy 'TestTwo/199539162': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceExitExecution() method in the context of a multi-time frame and instrument strategy

      How do I fix that?

      Comment


        #4
        Hello Abdullah_KSA,

        Thanks for your post.

        With reference to my previous post, I advised you to review the help guide if you are using added data series in your script. Based on the error message it sounds like you are.

        Here is the method signature needed: BarsSinceExitExecution(int barsInProgressIndex, string signalName, int exitExecutionsAgo).

        It may be as simple as BarsSinceExitExecution(0,"",0) if you are placing your orders to the primary (chart) bars.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by wjadevries, Today, 12:04 PM
        2 responses
        16 views
        0 likes
        Last Post wjadevries  
        Started by PhineasPhred, Today, 11:52 AM
        2 responses
        14 views
        0 likes
        Last Post PhineasPhred  
        Started by kenbun, Yesterday, 12:21 PM
        2 responses
        21 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Started by patricia70, Today, 11:26 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Spencer  
        Started by pdennis, Today, 11:42 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X