Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi instrument simulations

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

    Multi instrument simulations

    I define the variables:

    const int nSyms = 10;
    string[] symbols = {"$AUDUSD", "$EURUSD", "$GBPUSD", "$NZDUSD", "$USDCAD", "$USDCHF", "$USDHKD", "$USDJPY", "$USDNOK", "$USDSGD"};

    And then add the instruments in the Initialise() function as follows:

    Code:
           protected override void Initialize()
            {
                CalculateOnBarClose = true;
                
                Print("Instruments.GetLength(0) = " + Instruments.GetLength(0));
                for(int i=0; i < Instruments.GetLength(0);i++) {
                    Print("Instruments["+i+"].FullName = " + Instruments[i].FullName);
                }
                for (int i=0;i<nSyms;i++) {
                    // only add the non-primary series
                    Print("Attempting to add symbol " + symbols[i]);
                    Print("    primary is " +  Instruments[0].FullName);
                    if(0 != String.Compare(symbols[i], Instruments[0].FullName)){
                        Add(symbols[i], PeriodType.Minute, 5);
                        Print("    added " + symbols[i]);
                    }
                    else {
                        Print("    this is the primary series.");
                    }
                }
                Print("Number of instruments is " + Instruments.GetLength(0));
                for(int i=0; i < Instruments.GetLength(0);i++) {
                    Print("Instruments["+i+"].FullName = " + Instruments[i].FullName);
                }
    }
    When I do a backtest, I select an instrument from right pane of the strategy analyser window. I (incorrectly) expected that the instrument I select here would be the "primary data series" - but it is not.

    If I right click on "$AUDUSD" to bring up the backtest dialogue, the Initiase function runs, and the output is:

    Instruments.GetLength(0) = 1
    Instruments[0].FullName = $GBPUSD
    Attempting to add symbol $AUDUSD
    primary is $GBPUSD
    added $AUDUSD
    Attempting to add symbol $EURUSD
    primary is $GBPUSD
    added $EURUSD
    Attempting to add symbol $GBPUSD
    primary is $GBPUSD
    this is the primary series.
    Attempting to add symbol $NZDUSD
    primary is $GBPUSD
    added $NZDUSD
    Attempting to add symbol $USDCAD
    primary is $GBPUSD
    added $USDCAD
    Attempting to add symbol $USDCHF
    primary is $GBPUSD
    added $USDCHF
    Attempting to add symbol $USDHKD
    primary is $GBPUSD
    added $USDHKD
    Attempting to add symbol $USDJPY
    primary is $GBPUSD
    added $USDJPY
    Attempting to add symbol $USDNOK
    primary is $GBPUSD
    added $USDNOK
    Attempting to add symbol $USDSGD
    primary is $GBPUSD
    added $USDSGD
    Number of instruments is 10
    Instruments[0].FullName = $GBPUSD
    Instruments[1].FullName = $AUDUSD
    Instruments[2].FullName = $EURUSD
    Instruments[3].FullName = $NZDUSD
    Instruments[4].FullName = $USDCAD
    Instruments[5].FullName = $USDCHF
    Instruments[6].FullName = $USDHKD
    Instruments[7].FullName = $USDJPY
    Instruments[8].FullName = $USDNOK
    Instruments[9].FullName = $USDSGD
    Why is $GBPUSD the Instruments[0].FullName in this case?

    Thanks,
    Matthew.

    #2
    Matthew, there's no instrument set in the Initialize() as it will be set on the first OnBarUpdate() call - http://www.ninjatrader-support.com/H...tFullName.html

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    109 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    59 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    37 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    40 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    77 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X