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

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.
    Chris L.NinjaTrader Customer Service

    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));

        }
        Chris L.NinjaTrader Customer Service

        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.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mkouitra, 10-23-2021, 04:40 PM
            17 responses
            1,959 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
            4 responses
            27 views
            0 likes
            Last Post Vietanhnguyen2hotmailcom  
            Started by PhillT, 04-19-2024, 02:16 PM
            4 responses
            36 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Started by ageeholdings, 05-01-2024, 05:22 AM
            5 responses
            38 views
            0 likes
            Last Post ageeholdings  
            Started by reynoldsn, Yesterday, 02:34 PM
            0 responses
            15 views
            0 likes
            Last Post reynoldsn  
            Working...
            X