Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different instrument per run

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

    Different instrument per run

    Hi, I realise that this may not sound like the way things are done in NT, but I'm doing it because it's a real pain having to manually run for each instrument and maintain a list of them etc.

    So, to help improve my understanding of multi instrument, can you please explain to me what's happening here. I run this stragegy in the optimiser and supply two values - 1 and 2. Each value causes initialize to add a different instrument series, but the results are that each run gets the same prices (see output at end)

    Please don't just say the optimizer is not designed to work this way! I'd like to understand what's going on.

    [as an aside question, when you have multi instrument, and the primary instrument has no more bars available, will the strategy stop even if the secondary instrument has some more bars?]

    thanks
    Dave


    namespace NinjaTrader.Strategy
    {


    public class test2 : Strategy
    {

    private int instIndex;
    private string inst;

    protected override void Initialize()
    {
    if (instIndex == 1) {
    Add("6J 09-09", PeriodType.Minute, 1);
    }
    else {
    Add("FGBM 09-09", PeriodType.Minute, 1);
    }

    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1) {
    if (Close[0] == 116.76) {
    Print ("Index = "+InstIndex+" "+Time[0].ToString()+" "+Close[0].ToString("####.#####"));
    }
    }

    }

    [Description("InstIndex")]
    [Category("Parameters")]
    public int InstIndex
    {
    get { return instIndex; }
    set { instIndex = value; }
    }
    }
    }

    [output]

    Index = 1 04/09/2009 14:53:00 116.76
    Index = 1 04/09/2009 14:57:00 116.76
    Index = 1 04/09/2009 15:00:00 116.76
    Index = 1 04/09/2009 15:12:00 116.76
    Index = 1 04/09/2009 15:15:00 116.76
    Index = 1 04/09/2009 15:16:00 116.76
    Index = 1 04/09/2009 15:17:00 116.76
    Index = 1 04/09/2009 15:18:00 116.76
    Index = 1 04/09/2009 15:19:00 116.76
    Index = 1 04/09/2009 15:20:00 116.76
    Index = 1 04/09/2009 15:28:00 116.76
    Index = 1 04/09/2009 15:30:00 116.76
    Index = 1 04/09/2009 15:31:00 116.76
    Index = 1 04/09/2009 15:33:00 116.76
    Index = 1 04/09/2009 15:34:00 116.76
    Index = 2 04/09/2009 14:53:00 116.76
    Index = 2 04/09/2009 14:57:00 116.76
    Index = 2 04/09/2009 15:00:00 116.76
    Index = 2 04/09/2009 15:12:00 116.76
    Index = 2 04/09/2009 15:15:00 116.76
    Index = 2 04/09/2009 15:16:00 116.76
    Index = 2 04/09/2009 15:17:00 116.76
    Index = 2 04/09/2009 15:18:00 116.76
    Index = 2 04/09/2009 15:19:00 116.76
    Index = 2 04/09/2009 15:20:00 116.76
    Index = 2 04/09/2009 15:28:00 116.76
    Index = 2 04/09/2009 15:30:00 116.76
    Index = 2 04/09/2009 15:31:00 116.76
    Index = 2 04/09/2009 15:33:00 116.76

    #2
    dave1992, unfortunately it's not supported to dynamically Add an instrument as you have done in the Initialize(). The strategy will run for the time period where all used bars objects have data present.
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by smartromain, Today, 10:50 PM
    0 responses
    2 views
    0 likes
    Last Post smartromain  
    Started by popecapllc, 08-09-2023, 07:42 PM
    10 responses
    1,366 views
    0 likes
    Last Post BartMan
    by BartMan
     
    Started by jbays87, Today, 09:46 PM
    0 responses
    6 views
    0 likes
    Last Post jbays87
    by jbays87
     
    Started by ETFVoyageur, 04-30-2024, 02:04 PM
    11 responses
    101 views
    0 likes
    Last Post ETFVoyageur  
    Started by bubblegum, 03-18-2024, 10:41 AM
    3 responses
    48 views
    0 likes
    Last Post vjsworld  
    Working...
    X