Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Since Exit on Higher Time Frames

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

    Bars Since Exit on Higher Time Frames

    Hello All-

    I have bounced around the forums trying to find the missing piece of code I need but I can't quite narrow it down.

    A brief summary of the strategy. It will enter a trade either long or short following a candlestick 1 bar ago that does not take out the high and the low of the candlestick 2 bars ago. I trade this pattern on the 15, 30, and 60 minute charts. See the code below, this section of code is for a short trade that is taken once the bid of the current bar goes below the Low [1] on the 30 minute data series.

    Trades made on the 15 minute timeframe work perfectly, but when the code enters trades on the 30 and 60 minute I run into issues with Condition group 1. For context, when a successful trade runs its course and I am stopped out for a profit, I don't want to reenter a trade on that same candlestick. I want to wait for a new candlestick to open/form.

    From what I have gathered, the issue is that the BarsSinceExitExecution is being applied on the 15 minute data series even though the trade is based on the 30 and 60 minute candlestick patterns.

    How can I get the BarsSinceExitExecution to apply on the 30 minutes bars?



    if ((Highs[1][1] <= Highs[1][2])
    && (Lows[1][1] >= Lows[1][2])
    && (GetCurrentBid(1) < Lows[1][1])

    // Condition group 1

    && ((BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) > 0)
    || (BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) == -1)))


    {
    EnterShort();
    }


    If there is additional information you need me to provide just let me know. I've tried to keep the post brief but also allow you to get a handle on what I am trying to do with the strategy.

    Thank you,

    Nick

    #2
    My idea would be to add this condition after Exit command:
    Code:
    int ExitBar = CurrentBar;
    And then:
    Code:
    If (CurrentBar > ExitBar)
    {
     // Perform your entry logic 
    }

    Comment


      #3
      I would like to add, that my idea was for single data series, and you have to adjust it to fit to multiseries.

      Comment


        #4
        UltraNIX,

        Thank you for your response. Is this where I would put your suggested code?

        if ((Highs[1][1] <= Highs[1][2])
        && (Lows[1][1] >= Lows[1][2])
        && (GetCurrentBid(1) < Lows[1][1])

        // Condition group 1

        && ((BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) > 0)
        || (BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) == -1)))

        int ExitBar = CurrentBar;


        If (CurrentBar > ExitBar)

        {
        EnterShort();
        }


        Also my strategy is a multiseries ones, so I'll have to adjust it.

        Thank you,

        Nick

        Comment


          #5
          You should go back to Strategy Builder, then click on View Code button at the bottom, and the code should be within protected override void OnBarUpdate(), after your Exit condition.

          However, if you use multidata series, you should adjust CurrentBar to CurrentBars[1], if you use secondary series.

          Comment


            #6
            Ok so I created a variable named ExitBar.

            The Set where I exit the trade I added ExitBar = CurrentBars[Default input];

            Good so far?

            If so, do I need to go back to the entry conditions listed above and delete condition group 1?

            // Condition group 1

            && ((BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) > 0)
            || (BarsSinceExitExecution(0, @"30RunnerBreakeven", 0) == -1)))


            Then would I add the

            If CurrentBar > ExitBar

            correct?


            If I am correct so far, then I need to go to the Exit Set on the 30 and 60 minute and add

            ExitBar = CurrentBars[<Primary> (30 Minute)];


            Thank you again for the help. I really appreciate it.

            Nick

            Comment


              #7
              From what I read it seems correct, however, you should test it yourself and see if it works the way you'd like it to.

              Comment


                #8
                Hello njmeyer713,

                From what I have gathered, the issue is that the BarsSinceExitExecution is being applied on the 15 minute data series even though the trade is based on the 30 and 60 minute candlestick patterns.

                How can I get the BarsSinceExitExecution to apply on the 30 minutes bars?
                BarsSinceExitExecution has a BarsInProgress index parameter

                BarsSinceExitExecution(int barsInProgressIndex, string signalName, int exitExecutionsAgo)



                If the 30 minute series is BarsInProgress 1, then use a 1 for the barsInProgressIndex.

                BarsSinceExitExecution(1, "30RunnerBreakeven", 0) > 0

                You can check this during any BarsInProgress

                if (BarsInProgress == 0 && BarsSinceExitExecution(1, "30RunnerBreakeven", 0) > 0)
                if (BarsInProgress == 1 && BarsSinceExitExecution(1, "30RunnerBreakeven", 0) > 0)
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                55 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                132 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 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
                49 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X