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 Waxavi, Today, 02:10 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by alifarahani, Today, 09:40 AM
          5 responses
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X