Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on Add() method for indicators

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

    Question on Add() method for indicators

    I see the following code example, and I am wondering if it is adding the SMA to the primary time frame only, or it is adding to all time frames? Later in OnBarUpdate(), it is using SMA there as SMA(BarsArray[1], 5). I am wondering if in Initialize(), we don't Add() this indicator, then can we still use it in OnBarUpdate()?

    protected override void Initialize()
    {
    // Add a 5 minute Bars object to the strategy
    Add(PeriodType.Minute, 5);

    // Add a 15 minute Bars object to the strategy
    Add(PeriodType.Minute, 15);

    // Note: Bars are added to the BarsArray and can be accessed via an index value
    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

    // Add simple moving averages to the chart for display
    // This only displays the SMA's for the primary Bars object on the chart
    Add(SMA(5));
    Add(SMA(50));

    CalculateOnBarClose = true;
    }

    #2
    zehua,

    Yes, if you don't add this indicator you can still use it later by calling it the normal way.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      I see. So Adding an indicator in Initialze() is just to make the chart look better, and easier for programmers to see in the chart whether the entries and exits are as expected?

      Comment


        #4
        zehua,

        Yes, you are correct.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          on the same note... can you add an indicator from the initialize section from another time frame by adding an index value? i.e.
          // Add 1597 Broadview Tick Chart
          Add(PeriodType.Tick, 1597);

          // Add the 9 WMA from the 1597 Tick Chart to your primary bars (4 Tick Range) chart.
          Add(WMA(9)[1]);

          Comment


            #6
            Solomon,

            Are you looking to access these indicators using a BarsInProgress filter or are you just wanting to add them to your chart?

            This : Add(WMA(9)[1]); wouldn't work unfortunately, because the Add method for this override requires an indicator object, not the value at [1].

            Are you wanting to add the WMA of this second data series to the chart?
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              sorry, I didn't see your reply so fast!
              Yes, I want to add them to my chart using (I have the calculateonbarclose = false) because I wanted a more frequent indicator on my 4 range chart from the 9WMA of the broader 1597 tick chart. Otherwise, it'd be all step ladder like. Thanks for your help btw

              Comment


                #8
                Solomon,

                Is this an indicator or a strategy you are creating?

                Also, please note its possible to add a EMA for example of a separate dataseries on 1 chart without coding at all.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Oh yeah, I completely forgot about overlaying a chart. thanks for the reminder!

                  BTW, I'm creating a strategy on the 4 range chart comparing it to indicators on the 1597 tick chart. One of the conditions is WMA 9 rising from index [1] chart (the 1597 tick chart). All the other charts allow me to refer to index bars 1, except for that condition. is there a reason?

                  Thanks again

                  Comment


                    #10
                    ps, when I overlay the chart, the primary bars are no longer equidistant. Is there a way to make the primary bars spaced equidistantly and not the 1597? It seems it's setting the equidistance based on the 1597 tick chart, which I set to transparent...

                    Comment


                      #11
                      Solomon,

                      I am happy to assist.

                      Did you set the other data series to transparent color?

                      As far as your other question, could you possibly post a code example of what you tried and didnt work?
                      Adam P.NinjaTrader Customer Service

                      Comment


                        #12
                        This is a picture of the non equidistant bars when I try to use the transparent tick chart with the range chart. I understand both can't be aligned at the same time, but is there a way to make it align by the 4 tick range chart? Thanks
                        Attached Files
                        Last edited by Solomon; 05-08-2012, 11:12 AM.

                        Comment


                          #13
                          && Close[0] > WMA(9)[1]
                          && Close[0] > SMA(200)[1] + 12 * TickSize
                          && Close[0] > SMA(55)[1] + 12 * TickSize
                          && SMA(200)[1] > SMA(55)[1]
                          && Rising(WMA(9)) == true)
                          {
                          BackColor = Color.DarkGreen;
                          Alert("MyAlert0", Priority.High, "Check for Long!", @"C:\Program Files (x86)\NinjaTrader 7\sounds\Alert3.wav", 10, Color.DarkGreen, Color.White);
                          }

                          Comment


                            #14
                            From the conditions listed, I want the rising WMA9 to come from the 1597 Broadview chart. It appears the way I have it, it is using the primary bars of the barsarray. When I try adding it "&& Rising(WMA(9)[1])" an error pops up.

                            Comment


                              #15
                              I found the answer to my multitimeframe chart strategy. So don't worry about the rising WMA condition, and if you can't find how to keep the 4range chart equidistant with the 200SMA from the transparent 1597 chart overlayed, don't sweat it. I'll just have two charts open. The big one was the strategy, thanks!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              167 responses
                              2,260 views
                              0 likes
                              Last Post jeronymite  
                              Started by warreng86, 11-10-2020, 02:04 PM
                              7 responses
                              1,362 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Working...
                              X