Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceExitExecution not functioning

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

    BarsSinceExitExecution not functioning

    For some reason I cannot get BarSinceExitExecution to function properly in one of my strategies.

    The strategy does have a secondary time frame AddDataSeries(Data.BarsPeriodType.Tick, 1);
    Wondering if there might be an issue with which data series is being referenced?

    My code..

    ((BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) == -1)
    || (BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) >= ReEntryBars))

    ReEntryBars being a user variable.

    **

    I tried to remove the entry name and user variable and print to the output window...

    if (

    ((BarsSinceExitExecution(0, "", 0) == -1))
    || (BarsSinceExitExecution(0, "", 0) >= 100))
    {
    reEntryState = 1;
    }
    else
    {
    reEntryState = 0;
    }

    reEntryState output is always 1 and the strategy just enters a trade on the next bar after the previous trade closes.
    from output window reEntryState = 1**Time 10:22:08.3590000



    Any ideas how to track this issue down?




    #2
    Hello sdauteuil, thanks for writing in.

    You are using the primary data series for the BarsInProgressIndex, so this method is working on the correct bar series. What do you get when printing out the value of BarsSinceExitExecution? e.g.

    Print(BarsSinceExitExecution(0, "", 0));
    ((BarsSinceExitExecution(0, "", 0) == -1))
    || (BarsSinceExitExecution(0, "", 0) >= 100))
    { ... }

    I am assuming it's always -1. So a few things to check are
    1. That your entry method does not have a signal name applied, or that the signal name is also "".
    2. Are you calling this when Position == MarketPosition.Flat?

    I look forward to hearing of your results.

    Comment


      #3
      You are correct the output is -1

      I have tried it with the signal name blank as well as with the signal name from the entry.

      At this point the strategy is just getting into another trade even if the entry logic isn't met. Close[0]>Close[1]




      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 20)
      return;

      Print("exit bars before entry logic" + BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0));

      // Entry trigger
      if (

      ((BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) == -1)
      || (BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) >= ReEntryBars))
      && (Close[0] > Close[1]))

      Print("exit bars under logic" + BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0));
      Print("close " + Close[0] + "**Time " + Convert.ToString(Times[0][0].TimeOfDay));

      {
      EnterLong(Convert.ToInt32(Contracts), Convert.ToString(EntryNameDr));
      Print("exit bars with entry" + BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0));

      }

      Comment


        #4
        Hello sdauteuil, thanks for your reply.

        The entry is happening because you are losing the condition check by placing the Print statements there. You need to place the condition bracket directly below the if statement e.g.

        if (

        ((BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) == -1)
        || (BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0) >= ReEntryBars))
        && (Close[0] > Close[1]))
        {
        EnterLong(Convert.ToInt32(Contracts), Convert.ToString(EntryNameDr));
        Print("exit bars with entry" + BarsSinceExitExecution(0, Convert.ToString(EntryNameDr), 0));

        }

        Comment


          #5
          Lesson Learned!

          That fixed the condition issue but the BarsSinceExitExecution() is still not working.

          Comment


            #6
            Hello sdauteuil, thanks for your reply.

            I would need a test script for the full context. Could you export what you have and send it to me at platformsupport at ninjatrader.com? Please reference "Attn ChrisL 2820064" in the body of the email.

            I look forward to hearing from you.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            65 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            139 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            75 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            50 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X