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

How do I get 'barsAgo" info for a variable I create?

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

    How do I get 'barsAgo" info for a variable I create?


    ((EMA(
    20)[0] - EMA(20)[3]) / (EMA(20)[0])) gives me a ROC of a EMA20. How do I get that value from a preceding bar? If I try to apply the 'barsAgo' to the formula I get the following error:

    Cannot apply indexing with[] to an expression of type 'double'.

    Creating a variable to hold the above formula gives the same error.

    Can I compile a custom indicator using the formula and then reference it with a 'barsAgo'?





    #2
    imported post

    Two things -

    If you want to store user generated calculations, create a variable of type DataSeries. See documentation on this class. It would look something like:


    private DataSeries myRoc = null;

    protected override void Initialize()
    {
    myRoc = new DataSeries(this);
    }

    protected override void OnBarUpdate()
    {
    myRoc.Set(calculatedValue);
    Print("Current myRoc value is: " + myRoc[0]);
    }
    or you could do something like the following instead:

    protected override void OnBarUpdate()
    {
    Print("ROC of EMA20 is: " + ROC(EMA(20), periodValue, smoothValue)[0]);
    }


    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      THat's what I needed, thanks!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 05-06-2023, 09:03 PM
      9 responses
      258 views
      0 likes
      Last Post ender_wiggum  
      Started by Mizzouman1, Today, 07:35 AM
      4 responses
      18 views
      0 likes
      Last Post Mizzouman1  
      Started by philmg, Today, 01:17 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_ChristopherJ  
      Started by cre8able, Today, 01:01 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by manitshah915, Today, 12:59 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Erick  
      Working...
      X