• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 hobah99, Today, 04:12 PM
      0 responses
      3 views
      0 likes
      Last Post hobah99
      by hobah99
       
      Started by arguru, Today, 04:07 PM
      0 responses
      6 views
      0 likes
      Last Post arguru
      by arguru
       
      Started by Abdullah_KSA, Yesterday, 12:52 PM
      6 responses
      41 views
      0 likes
      Last Post NinjaTrader_ChristopherD  
      Started by ZivGillat, 06-29-2020, 11:47 AM
      4 responses
      29 views
      0 likes
      Last Post ZivGillat  
      Started by NinjaTrader_PaulH, Today, 01:48 PM
      0 responses
      9 views
      0 likes
      Last Post NinjaTrader_PaulH  
      Working...
      X