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 ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          44 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          180 views
          0 likes
          Last Post jeronymite  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Working...
          X