Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variables for real body average

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

    Variables for real body average

    Hi

    Can someone help me. I would like to prepare an average for real bodies on candles. with a user input period.

    Wizard can do the user input for me .

    Could I use a variable RealBody (Math.Abs(Open-Close)? and put it in the SMA method parameters (price series RealBody, period) and if yes where do I declare the variables sma and realbody?

    #2
    Hello fluke,

    Welcome to the forums! I'm glad you got the registration issue sorted.

    Yes, you could store the calculated values for Open[0] - Close[0] in a Series<double> and use that as input for an indicator. The SampleMACrossover strategy can be referenced to see how an indicator is added in a NinjaScript, and our documentation page on Series<T> provides a demonstration for how you can set a value to a Series<double> and feed that to an indicator. I'll include a more direct example, however, I would advise reviewing these other examples and the documentation pages in this post for further reference.

    Code:
    private SMA mySMA;
    private Series<double> mySeries;
    protected override void OnStateChange()
    {
    	if (State == State.SetDefaults)
    	{
    		...
    	}
    	else if (State == State.DataLoaded)
    	{
    		mySeries = new Series<double>(this);
    		mySMA = SMA(mySeries, 14);
    	}
    }
    
    protected override void OnBarUpdate()
    {
    	mySeries[0] = Math.Abs(Open[0] - Close[0]);
    	if(CurrentBar < 14)
    		return;
    	Print(mySMA[0]);
    	//Print(SMA(mySeries, 14)[0]);
    }
    Publicly available documentation on these items about can be found below.

    Working with Price Series - https://ninjatrader.com/support/help...ice_series.htm

    Series<T> - https://ninjatrader.com/support/help...us/seriest.htm

    Valid Input for System Indicator methods - https://ninjatrader.com/support/help..._indicator.htm

    Please let us know if we can be of further assistance.

    Comment


      #3
      Variables real body average

      Fantastic Jim

      Just what I was looking for.
      Thanks

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      595 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      554 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X