Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        541 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Working...
        X