Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing BarsArray[0] information.

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

    Accessing BarsArray[0] information.

    Hi ,

    I need the following information to be available at Initialize for a strategy:
    • Primary instrument name
    • Its PeriodType (e.g. tick , range , renko)
    • Its period / brick size

    For getting this information on indicator , I used the following code:

    if ( ChartControl != null) !!! do not use in strategy !!! {
    sPr = ChartControl.BarsArray[0].ToString() ;
    // Parse sPr to get the information.
    // Use the information.
    ...................
    }

    It does not work for a strategy, as ChartControl is NULL.

    Also I'm aware that the code above is awfully brute force and probably there are better methods to get this information.

    Please help.

    #2
    xTrader1, you can work with the Instrument class and BarsPeriod / Id for this -



    Comment


      #3
      Instrument name / period type / period.

      Essentially, my question is the same as Mike Winfrey's question here :


      The help information states it is not possible to access this information during Initialize().
      Exactly as Mike I want to know properties of my primary instrument and to add more instruments base on this infor,ation , for example if the primary instrument is Range/30 , I want to add Range/60 and if it is Renko/40 , I want to add Renko/80 .

      As I said above , I found a weird way to do it for an NT7 indicator , I cannot find neither a normal , nor a weird way to do it in a strategy. It's a pity , as my strategy is based on adding instruments dynamically, otherwise I should hard code X strategies , everyone for a different combination of PeriodType/Period of a primary instrument.

      Please help again.

      Comment


        #4
        xTrader, unfortunately adding those dynamically is not supported still. However I think you could setup string inputs and just use a default then entered so it's not empty...

        Comment


          #5
          I found it.

          Originally posted by NinjaTrader_Bertrand View Post
          xTrader, unfortunately adding those dynamically is not supported still.
          As for now I found PeriodType/Period information . It is simple :

          sPr = this.BarsPeriods[0].ToString() ;
          Print(sPr) ;

          Prints : 40 Renko

          I'll share my code if/when I'll find how to access primary instrument name in Initialize() .

          Comment


            #6
            I don't know if this will help you, but here a couple of things which have worked for me:

            // The following code works inside of Initialize() in strategies:

            Code:
            if ((Instruments != null) && (Instruments[0] != null))
            	{	
            		// BarsPeriod.Value can be referenced here
            		// BarsPeriod.Id can be referenced here		
            		// Instruments[0].FullName can be referenced here
            		
            		// You can add Bars objects here	
            		Add(PeriodType.Minute, IntradayPeriod);      		
            		Add(Symbol, PeriodType.Minute, IntradayPeriod); 
            	}

            For Indicators, I use the following code in the property Symbol2 which is callable from Initialize():

            Code:
            // in Initialize() for an indicator:
            
            // BarsPeriod.ID and BarsPeriod.Value can be referenced in Initialize()
            Add(Symbol2, BarsPeriod.Id, BarsPeriod.Value);
            
            //in the Properties region
            public string Symbol2
            {
                  get 
                  { 
            	   if ((symbol2 == "") && (ChartControl != null) && (Instruments != null)) 
            	   for(int i=0; i<ChartControl.BarsArray.Length; i++)
            		if (ChartControl.BarsArray[i].Instrument.FullName != Instruments[0].FullName)
            		{
            			symbol2 = ChartControl.BarsArray[i].Instrument.FullName;
            			break;
            		}
            		return symbol2; 
            	}
                  set { symbol2 = value.ToUpper(); }
            	}

            Comment


              #7
              Thank you ,

              Regarding indicators , now I remind I learned it from you.

              Regarding strategies , it helps either , as I don't need to know instrument name to use Add(...) on default instrument.

              Comment

              Latest Posts

              Collapse

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