Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different Periods in an Indicator

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

    Different Periods in an Indicator

    Hello,

    I am wondering if when using an indicator within another indicator, if I need to put the period of the imported indicator if it is already correct in the original indicator. To clarify:

    Indicator A is the main indicator - it is set at a period of say 20

    IndicatorB to be imported is set at period 14
    IndicatorC to be imported is set at period 6

    Within indicator A, can I just use:
    if (IndicatorB[0] > IndicatorC[0])
    {result}
    And IndicatorB will be set to 14 periods and IndicatorC to 6 periods, or do they default to the 20 periods for IndicatorA, so I need to code as follows:
    if (IndicatorB(14)[0] > IndicatorC(6)[0])
    {result}

    Thank you.

    #2
    Hello,

    Thank you for your note.

    When using an indicator within another indicator you would always need to fix the period to the desired period.

    The correct way to write the code would be,

    if (IndicatorB(14)[0] > IndicatorC(6)[0]) {result}

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      The thing with doing it that way is that it wants all 20 odd arguments of the indicator between the () which makes the code far too long, as there are several indicators with many arguments. I am sure I have seen a way of doing it by calling the indicator in the Variables and OnStartUp regions like so:

      Variables Region:
      private IndicatorB myB;

      protected override void OnStartUp()
      {
      myB = IndicatorB(argument1, argument2, etc);
      }

      Then when I use myB in the code, it picks up the period from the OnStartUp section of the code. I suppose if I want a different period than the one in the original indicator, I would just substitute the number for "period" in the arguments in the OnStartUp section.

      I think it's all working. I just got confused because there are a number of indicators with different periods in the code.

      Thanks.

      Comment


        #4
        Hello GeorgeW,

        You are correct. If you wanted to use several variations of the original indicator, you would declare additional variables of object type IndicatorB, for example;

        private IndicatorB myB;
        private IndicatorB myB1;
        private IndicatorB myB2;

        Then assign these under OnStartUp() with different parameters, for example different periods. You could then use myB, myB1, myB2, in your code.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by manueldecastro, Yesterday, 10:59 PM
        2 responses
        7 views
        0 likes
        Last Post manueldecastro  
        Started by ttodua, 05-03-2019, 04:54 AM
        2 responses
        126 views
        0 likes
        Last Post ninZa
        by ninZa
         
        Started by szferi, Today, 02:04 AM
        0 responses
        6 views
        0 likes
        Last Post szferi
        by szferi
         
        Started by Rosario, Today, 12:50 AM
        0 responses
        4 views
        0 likes
        Last Post Rosario
        by Rosario
         
        Started by MartynBashi, Yesterday, 11:01 PM
        0 responses
        4 views
        0 likes
        Last Post MartynBashi  
        Working...
        X