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 GussJ, 03-04-2020, 03:11 PM
          16 responses
          3,279 views
          0 likes
          Last Post Leafcutter  
          Started by WHICKED, Today, 12:45 PM
          2 responses
          19 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by Tim-c, Today, 02:10 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by Taddypole, Today, 02:47 PM
          0 responses
          5 views
          0 likes
          Last Post Taddypole  
          Started by chbruno, 04-24-2024, 04:10 PM
          4 responses
          51 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Working...
          X