Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsSinceEntry in MTF-Strategy

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

    BarsSinceEntry in MTF-Strategy

    Hi!

    I simply want to print out the BarsSinceEntry-values of an different TimeFrame than the primary one, but it doesn't work!

    I've tried this with following setup:

    MarketReplay
    Primary Bar object -> 1min
    protectedoverridevoid Initialize()
    {
    Add(PeriodType.Second, 10);
    CalculateOnBarClose = false;
    }

    protectedoverridevoid OnBarUpdate()
    {
    if (Historical)
    return;

    if (BarsInProgress == 0)
    {
    if (Closes[1][0] > Highs[1][1])
    {
    EnterLong(DefaultQuantity, "ENTERLONG");
    Print(BarsSinceEntry(1, "ENTERLONG", 0));
    }
    }
    }
    The strategy enters a position like I want it to do, but the output window shows always value 0 for the BarsSinceEntry-Method each incoming tick.

    When I changed the code to
    "EnterLong(DefaultQuantity, "ENTERLONG");

    Print(BarsSinceEntry("ENTERLONG"));"
    the method returned the value for the primary Bars object, and when I changed the code again to
    EnterLong(DefaultQuantity, "ENTERLONG");
    Print(BarsSinceEntry(0, "ENTERLONG", 0));
    the method again returned the value for the primary Bars object, like it should according to the barinprogressindex parameter.

    I also tried following code:
    protectedoverridevoid OnBarUpdate()
    {
    if (Historical)
    return;
    if (BarsInProgress == 0)
    {
    if (Closes[1][0] > Highs[1][1])
    {
    EnterLong(DefaultQuantity, "ENTERLONG");

    }

    if (BarsInProgress == 1)
    {
    Print(BarsSinceEntry(1, "ENTERLONG", 0));
    }
    }
    ...but this returns no values in the output window at all.

    I was assuming that the BarsSinceEntry-method can also return values for other timeframes than the primary one because it takes an argument "barsinprogressindex".

    Is there any possibility to get the BarsSinceEntry-value for the 10sec-Timeframe, if this is not the primary one?

    Or ist this parameter reserved for multi-intrument-strategies?

    thx

    #2
    It is working as expected. It will only return a value against the series that the order was submitted against.

    In your example, when BarsInProgress == 1, you can only see how bars in BarsInProgress == 0 have elapsed.
    RayNinjaTrader Customer Service

    Comment


      #3
      I am using a MTF - just adding tick data to a renko chart for entry in order to make more accurate backtesting results. however for some reason whenever I add "bars since entry" - then no traders ever trigger.....?

      Comment


        #4
        Hello hifreq,

        Thank you for your post.

        In what context is the BarsSinceEntry() used? Can you provide the condition it is used in? Do any entries precede this condition?

        I look forward to your response.

        Comment


          #5
          yes there many entries. when i test without the condition set it works just fine. I simply want to get out after 17 bars.
          {
          // Condition set 1
          if (BOP(BopL)[0] >= Swing(BOP(BOPLL), 1).SwingHigh[1]
          && BarsSinceEntry() >= 17
          && Close[0] > Open[0])
          {
          ExitLong("long50close", "L");

          }

          Comment


            #6
            Hello hifreq,

            Thank you for your response.

            If you add a Print() statement to the condition do you see the print in the Output window (Tools > Output Window)?
            Code:
            if (BOP(BopL)[0] >= Swing(BOP(BOPLL), 1).SwingHigh[1]
            && BarsSinceEntry() >= 17
            && Close[0] > Open[0])
            {
            ExitLong("long50close", "L");
            Print("Exit for long50close called");

            Comment


              #7
              Once I put "BarsSinceEntry" - the strategy makes no trades. I take out that one line its fine....? Just to clarify the code is. Any ideas. I am using a Renko chart and submitting trades on a tick timeframe - again this is just for backtesting so that I can get accurate results.
              if (BarsSinceEntry() >= 17
              && Close[0] > Open[0]


              )


              {
              ExitLong(Position.Quantity,"S Long", "");
              Print("Exit for long50close called")

              Comment


                #8
                Hello hifreq,

                Thank you for your response.

                Do you see the Print in the Output Window when the condition returns true?

                When you say no trades are placed does this mean no trades are closed? Are you using BarsSinceEntry() in the conditions for your entries?

                I look forward to your response.

                Comment


                  #9
                  The strategy will not enter even one trade so there is nothing in the output window. No i am not using Barssinceentry on any entry condition

                  Comment


                    #10
                    Hello hifreq,

                    Thank you for your response.

                    As this condition only applies to the Exit() method I do not understand why that would prevent the entries.

                    Please attach your script to your response in the state that does not place any orders. If you prefer you can send the script to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 959682' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ead.php?t=5364

                    I look forward to your response.

                    Comment


                      #11
                      I just edited my entry so that i could paste in here. This should normally create some trades but it doesn't

                      #region Using declarations
                      using System;
                      using System.ComponentModel;
                      using System.Diagnostics;
                      using System.Drawing;
                      using System.Drawing.Drawing2D;
                      using System.Xml.Serialization;
                      using NinjaTrader.Cbi;
                      using NinjaTrader.Data;
                      using NinjaTrader.Indicator;
                      using NinjaTrader.Gui.Chart;
                      using NinjaTrader.Strategy;
                      #endregion

                      // This namespace holds all strategies and is required. Do not change it.
                      namespace NinjaTrader.Strategy
                      {
                      /// <summary>
                      /// Enter the description of your strategy here
                      /// </summary>
                      [Description("Enter the description of your strategy here")]
                      public class AugRenkoLongs : Strategy
                      {
                      #region Variables
                      // Wizard generated variables
                      int positionSize = 1;
                      // User defined variables (add any user defined variables below)

                      // presets
                      int tbip = 1;

                      #endregion

                      /// <summary>
                      /// This method is used to configure the strategy and is called once before any strategy method is called.
                      /// </summary>
                      protected override void Initialize()
                      {
                      Add(PeriodType.Tick,1); // the high granularity dataseries

                      RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;

                      SetStopLoss("", CalculationMode.Ticks, 26, true);

                      //SetStopLoss("L2 RT", CalculationMode.Ticks, 26, true);
                      //SetStopLoss("L3 RT", CalculationMode.Ticks, 26, true);
                      //SetStopLoss("S RT", CalculationMode.Ticks, 26, true);
                      //SetStopLoss("S2 RT", CalculationMode.Ticks, 26, true);
                      //SetStopLoss("S3 RT", CalculationMode.Ticks, 26, true);
                      CalculateOnBarClose = true;
                      TraceOrders = true;


                      // SetProfitTarget("L3", CalculationMode.Ticks, 50);
                      //SetProfitTarget("S3", CalculationMode.Ticks, 50);
                      }
                      protected override void OnTermination()
                      {
                      SendMail("[email protected]","[email protected]", "STR G OFF", "Disabled");


                      }

                      protected override void OnStartUp()
                      {
                      for (int a = 0; a< BarsArray.Length; a++)
                      Print(this.Name+" Bars data ["+a+"] contains "+BarsPeriods[a].ToString()+" of "+BarsArray[a].Count+" bars, commencing at "+BarsArray[a].Get(0).Time);
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {

                      // SetProfitTarget("", CalculationMode.Ticks, 75);


                      if (BarsInProgress > 0 || CurrentBar < BarsRequired)
                      return; // don't process anything directly on the high granularity timeframe, or early in the chart's data

                      // Condition set 1
                      if (BOP(15)[0] >= Swing(BOP(4), 1).SwingHigh[1]


                      )



                      {
                      EnterLong(tbip,positionSize, "L RT");



                      }
                      if (Close[0] < Open[0]
                      && Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) >= 0
                      && Position.MarketPosition == MarketPosition.Long)

                      {
                      ExitLong(tbip,PositionSize,"one candleL", "");
                      }
                      if (BarsSinceEntry() >= 17
                      && Close[0] > Open[0]


                      )


                      {
                      ExitLong(Position.Quantity,"S Long", "");

                      Comment


                        #12
                        Hello hifreq,

                        Thank you for your response.

                        You will need to reference the BarsInProgress index and the entry signal name for the BarsSinceEntry on multi-time frame and multi-instrument scripts. Please change your BarsSinceEntry() to the following:
                        Code:
                        BarsSinceEntry(tbip, "L RT", 0)
                        Please visit the following link for more information on BarsSinceEntry(): http://www.ninjatrader.com/support/h...sinceentry.htm

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        671 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        379 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        111 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        575 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        582 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X