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

Math Between Indicators

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

    Math Between Indicators

    Hi,

    Does anyone know how to calculate indicators such as:

    SMA of (Close[n] * Volume[n])


    Thanks

    #2
    Hello rs123456,

    Thank you for your post.

    You can create a custom indicator for this purpose. Using a Series<T> to hold the calculation of the Close * Volume per bar. Then pass the Series<T> as the input of the SMA and set that as your plot.

    For example:
    Code:
    		private Series<double> smaInput;
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Indicator here.";
    				Name										= "SMACloseTimesVolume";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= true;
    				DrawVerticalGridLines						= true;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    				
    				AddPlot(Brushes.Orange, "SMA");
    				
    				Period						= 14;
    			}
    			else if (State == State.DataLoaded)
    			{
    				smaInput = new Series<double>(this);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			// Set our Series<T> to Close times Volume.
    			smaInput[0] = Close[0] * Volume[0];
    			
    			// Pass our Series<T> as the input for the SMA
    			Values[0][0] = SMA(smaInput, Period)[0];
    		}
    		
    		[Range(1, int.MaxValue), NinjaScriptProperty]
    		[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 0)]
    		public int Period
    		{ get; set; }
    Please let me know if you have any questions.

    Comment


      #3
      For information on Series<T> please visit the following link: http://ninjatrader.com/support/helpG...us/seriest.htm

      Comment


        #4
        Many thanks Patrick. I've gotten some indicators work based on the info you've provided [see screenshot]

        Please could you also tell me how to change the number formatting from e.g. 1000000 to 1M?
        Attached Files

        Comment


          #5
          Hello rs123456,

          Thank you for your response.

          The decimals are the reason it is not showing K or M. You would need to round the values to the nearest whole value before setting the plot.

          Please let me know if you have any questions.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ScottWalsh, Today, 06:52 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ScottW, Today, 06:09 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by ftsc2022, 10-25-2022, 12:03 PM
          5 responses
          256 views
          0 likes
          Last Post KeyonMatthews  
          Started by Board game geek, 10-29-2023, 12:00 PM
          14 responses
          244 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Waxavi, 04-19-2024, 02:10 AM
          4 responses
          56 views
          0 likes
          Last Post sonia0101  
          Working...
          X