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 Javierw.ok, Today, 04:12 PM
        0 responses
        2 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        40 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X