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

using idicators within indicators

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

    using idicators within indicators

    i have a custom indicator, "AveRange" which calculates the SMA of daily range. I have another, "SDRange" that calculates the Stddev of range.

    I would like to create an indicator, "RangeRatio" which calculates "AveRange" / "SDRange"

    I tried to create 3 DataSeries (one for Range, one for Averange, and one for SDRange) because i wasnt sure how to call an indicator within an indicator.

    i then tried to ...

    Code:
    protected override void OnBarUpdate()
            {
    		
    			
    			myRange.Set(Close[0] - Open[0]);
    			myAveRange.Set(SMA(myRange,Period));
    			mySDRange.Set(StdDev(myRange,Period));
    			
    			
                AvgRatio.Set(myAveRange/mySDRange)[0];
            }
    but couldnt use the divide operator on a DataSeries

    i would like to know the easier way to do this but i would also like to know why this way wouldnt work. Thanks. BB

    #2
    Hello BB,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    You can actually use divide, but you need to use the barsAgo index for the Data Series here:
    Code:
    AvgRatio.Set(myAveRange[0]/mySDRange[0]);

    Comment


      #3
      Originally posted by wlblount View Post
      i have a custom indicator, "AveRange" which calculates the SMA of daily range. I have another, "SDRange" that calculates the Stddev of range.

      I would like to create an indicator, "RangeRatio" which calculates "AveRange" / "SDRange"

      I tried to create 3 DataSeries (one for Range, one for Averange, and one for SDRange) because i wasnt sure how to call an indicator within an indicator.

      i then tried to ...

      Code:
      protected override void OnBarUpdate()
              {
              
                  
                  myRange.Set(Close[0] - Open[0]);
                  myAveRange.Set(SMA(myRange,Period));
                  mySDRange.Set(StdDev(myRange,Period));
                  
                  
                  AvgRatio.Set(myAveRange/mySDRange)[0];
              }
      but couldnt use the divide operator on a DataSeries

      i would like to know the easier way to do this but i would also like to know why this way wouldnt work. Thanks. BB
      You are missing the indices on your DataSeries invocations, and a spurious index on your last Set statement.
      Code:
      myRange.Set(Close[0] - Open[0]);
                  myAveRange.Set(SMA(myRange,Period)[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE]);
                  mySDRange.Set(StdDev(myRange,Period)[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE]);
                  
                  
                  AvgRatio.Set(myAveRange[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE]/mySDRange[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE])[B][COLOR=Red][0][/COLOR][/B];
      The index marked in bold red should not be there. In other words, your last line should read:
      Code:
                  AvgRatio.Set(myAveRange[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE]/mySDRange[SIZE=3][COLOR=Blue][B][0][/B][/COLOR][/SIZE])[B][COLOR=Red][/COLOR][/B];

      Comment


        #4
        Thank you Gentleman - that worked perfectly. The "SampleCustomDataSeries" is a great template. I had a bunch of simple, "Market Analyzer" type indicators on TOS and at day 3 with NT, I have been able to reproduce almost all of them. BB

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        31 views
        0 likes
        Last Post love2code2trade  
        Started by cls71, Today, 04:45 AM
        2 responses
        10 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Started by proptrade13, Today, 11:06 AM
        0 responses
        4 views
        0 likes
        Last Post proptrade13  
        Started by kulwinder73, Today, 10:31 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by RookieTrader, Today, 09:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X