Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating using stock data from different timezones.

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

    Calculating using stock data from different timezones.

    Hi,


    I would like to backtest a strategy using instruments based in Australia and the UK.

    I have daily data for the Australian stock index and minute data for UK stock, and want to use the daily change, i.e. Closes[(0)][0] > Opens[(0)][0], in the Australian index to decide whether to buy a stock at the start of the UK session.

    Unfortunately when I try this, the values of the Closes[(0)][0] and Opens[(0)][0] are for the PREVIOUS day. So if it is Tuesday morning in the UK, we should already have the value for the Tuesday Close and Open for the Australian index. However, the values that NinjaTrader uses are for the day before, i.e. Monday.

    Could someone let me know what is the best way around this issue?


    Thanks

    ST10


    Code:
    #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>
        
        /// </summary>
        [Description("")]
        public class DLv1vDATATEST1 : Strategy
        {
            #region Variables
            // Wizard generated variables
            #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("GSK", PeriodType.Minute, 1);
    
    
                CalculateOnBarClose = true;
                ExitOnClose = true;
                
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
    
                if (BarsInProgress == 1)
                {
    
    
                    if (Bars.FirstBarOfSession)
                    {
    
                        if (Position.MarketPosition == MarketPosition.Flat)
                        {
    
                            Print(Time[0] + " : " + Closes[0][0]  + " : " + Opens[0]);
                            
                            if (Closes[(0)][0] > Opens[(0)][0])
                            {
                                
                                EnterLong();
    
                            }
                            
                            
                            else if (Closes[(0)][0] < Opens[(0)][0])
                            {
    
                                EnterShort();
    
                            }
    
    
                        }
    
    
                    }
    
                }
            }
      
    
            #region Properties
    
            #endregion
    
        }
    }

    #2
    Hello systemtrader10,

    Thank you for your post.

    The Strategy is set to CaculateOnBarClose = true, which means the strategy will not calculate on the current day bar but only the previous bar (i.e. yesterday's bar). You would want to set CalculateOnBarClose to false.

    If you need to have the minute data as CalculateOnBarClose = true you can look into the use of FirstTickOfBar with CalculateOnBarClose = false. For an example of this please visit the following link: http://www.ninjatrader.com/support/f...ad.php?t=19387

    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    67 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    36 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    60 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    62 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    53 views
    0 likes
    Last Post CarlTrading  
    Working...
    X