Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial Bar Calculation

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

    Partial Bar Calculation

    I'm trying to simulate entering before the close using a daily strategy. The strategy is structured as follows:

    Data Feed: IQFeed
    Symbol: TF
    BarType: 1440 Minute (to get the CME RTH session daily bar)

    I created a strategy that adds a secondary series (5 minute bars) so
    that I can enter 5 minutes before the close given calculations on the
    primary series being the 1440 minute bars.

    Is there a way to use the partial bar formed on the 1440 minute series
    5 minutes before the close of that bar for calculations?

    Or is there another way around this?

    The other idea I had is the ability to add a data series with a different session template applied. I was wondering if that could be supported in NT8?

    Thanks in advance!

    Code:
    public class TestStrategy : Strategy
    {
        private int smaLength = 200;
    
        protected override void Initialize()
        {
            Add(PeriodType.Minute, 5);
            CalculateOnBarClose = true;
        }
    
        protected override void OnBarUpdate()
        {
            if (CurrentBar < smaLength) return;
    
            if (BarsInProgress == 0)
            {
                double sma = SMA(Close, smaLength)[0];
    
                string msg = string.Format("BARS1 [Date] {0} [Time] {1} [sma] {2}",
                    Time[0].ToShortDateString(), Time[0].ToShortTimeString(), sma.ToString("N2"));
                Print(msg);
            }
            else if (BarsInProgress == 1 && Time[0].Hour == 15 && Time[0].Minute == 10)
            {
                double sma = SMA(BarsArray[0], smaLength)[0];
    
                //	EXITS
                if (sma < Close[0])
                    ExitLongLimit(1, false, 1, Close[0], "LX", "LE");
    
                //	ENTRIES
                if (IsFlat && Close[0] > sma)
                    EnterLongLimit(1, false, 1, Close[0], "LE");
    
                string msg = string.Format("BARS2 [Date] {0} [Time] {1} [sma] {2}",
                    Time[0].ToShortDateString(), Time[0].ToShortTimeString(), sma.ToString("N2"));
                Print(msg);
            }
            else
            {
                return;
            }
        }
    
        [Description("")]
        [GridCategory("Parameters")]
        public int SmaLength
        {
            get { return smaLength; }
            set { smaLength = Math.Max(1, value); }
        }
    }
    Last edited by GrumpyTrader; 05-28-2015, 08:16 AM.

    #2
    Hello GrumpyTrader,

    If I understand correctly, you are wanting a way around adding the secondary series and still achieving the same goal, correct?

    If so, using the OnMarketData method would give you triggers you can use for orders on every received piece of data. The downside is that this does not work historically and cannot be backtested with the Strategy Analyzer (instead the Market Replay would be used to test this script).

    You could also use the exit on close if you are exiting trades. Set this to 300 seconds for 5 minutes.

    Also, yes, NT8 does provide the ability to use a different session template for an added series.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,
      I really do want to be able to backtest, and the exit on close functionality doesn't solve the issue of me entering on close. So I was wondering if I could do the following:

      A way to calculate an indicator (in this case the 200 day SMA) using a partial bar of the 1440m series (not yet closed). Is there an easy way? or do I need to create a custom DataSeries of the 1440m daily closes with the last one being the close of the 15:10 bar of the 5m dataseries and use that for my calculation?
      Last edited by GrumpyTrader; 05-28-2015, 09:05 AM.

      Comment


        #4
        Hello GrumpyTrader,

        In NT7 the short answer is adding a data series is the only way if you plan to backtest.

        In NT8 you can add intra-bar granularity to any script when backtesting so this is not an issue.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X