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

Set value for data series

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

    Set value for data series

    I want to calculate relative strength in 30 bars, and smooth that value.
    I try a recursive way to smooth the value, then set it to the same data series.
    But it can't work.
    Is there something wrong with the value setting of data series?

    Code:
    public class AATest : Indicator
        {
        
    		#region Variables
        	private DataSeries myDataSeries;
    		#endregion
    		
    		protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay				= false;
    			
    			myDataSeries = new DataSeries(this);
    			
            }
     
            protected override void OnBarUpdate()
            {
                
    			
    			double strValue = (Close[0]-Low[LowestBar(Low,30)])/(High[HighestBar(High,30)]-Low[LowestBar(Low,30)])*100;
    						
    			myDataSeries.Set((strValue+15*myDataSeries[1])/16);
    					
                Plot0.Set(myDataSeries[0]);
            }
    
            #region Properties
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
    
            #endregion
        }

    #2
    Originally posted by stnvs View Post
    I want to calculate relative strength in 30 bars, and smooth that value.
    I try a recursive way to smooth the value, then set it to the same data series.
    But it can't work.
    Is there something wrong with the value setting of data series?

    Code:
    public class AATest : Indicator
        {
     
            #region Variables
            private DataSeries myDataSeries;
            #endregion
     
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                Overlay                = false;
     
                myDataSeries = new DataSeries(this);
     
            }
     
            protected override void OnBarUpdate()
            {
     
     
                double strValue = (Close[0]-Low[LowestBar(Low,30)])/(High[HighestBar(High,30)]-Low[LowestBar(Low,30)])*100;
     
                myDataSeries.Set((strValue+15*myDataSeries[1])/16);
     
                Plot0.Set(myDataSeries[0]);
            }
     
            #region Properties
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
     
            #endregion
        }
    What is the error, if any, in your log?

    Comment


      #3
      Originally posted by koganam View Post
      What is the error, if any, in your log?
      I just compiled it without any error.
      The problem is that the only plot "Plot0" should show the value of myDataSeries[0], but it shows nothing.
      I opened the data box in the chart to check the value of the plot, and it doesn't show any value, even doesn't show "N/A".

      I tried to set the value of myDataSeries[0] to simpler value, something like the value of strValue or myDataSeries[1], and the Plot0 can work well. The value of Plot0 was correct, and also correct in the chart.
      Then I tried to add multiplicators or divisors into the calculation such like "(strValue+15*DataSeries[1])/16", the Plot0 and its value disappeared in the chart again.
      I am not sure where the problem is.
      Last edited by stnvs; 11-20-2012, 02:36 AM.

      Comment


        #4
        stnvs, the issue seems to be that your calculated values are 'blowing' up so could not be plotted anymore - if you directly print the values, what values would be given?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          stnvs, the issue seems to be that your calculated values are 'blowing' up so could not be plotted anymore - if you directly print the values, what values would be given?

          Hi, Bertrand
          Thanks for your help.

          I use "Print(myDataSeries[0]);", and get "not a number" in the output window.
          Is it means that the values of the calculation are blowing up?

          The value of "strValue" which I use in the indicator should be a double number ranged from 0-100, and the values of myDataSeries are calculated in simple(?) procedure with strValue.

          Have any idea what's wrong in these calculations?
          Any advice will be appreciated!

          Comment


            #6
            For the (Stoch?) calculations of strValue below I would look into our Stochastics indicator implementation and how it ensures stability and simpler calcs.

            double strValue = (Close[0]-Low[LowestBar(Low,30)])/(High[HighestBar(High,30)]-Low[LowestBar(Low,30)])*100;
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              For the (Stoch?) calculations of strValue below I would look into our Stochastics indicator implementation and how it ensures stability and simpler calcs.

              double strValue = (Close[0]-Low[LowestBar(Low,30)])/(High[HighestBar(High,30)]-Low[LowestBar(Low,30)])*100;
              Thank you, Bertrand.

              I'll try to use Stochastics indicator to implement my custom indicators, and see if it can work well.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by cre8able, Today, 01:16 PM
              2 responses
              9 views
              0 likes
              Last Post cre8able  
              Started by chbruno, 04-24-2024, 04:10 PM
              3 responses
              48 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by samish18, Today, 01:01 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by WHICKED, Today, 12:56 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by WHICKED, Today, 12:45 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Working...
              X