Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          571 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          549 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          549 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X