• 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

Accessing BarsArray from add on script

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

    Accessing BarsArray from add on script

    Hi all,

    I am currently trying to put my calculation codes into an add on script so that I may use it for my other indicators and strategies. My current method is currently as such:

    Code:
    public IList<double> GetMaximas(int ChartID, int Limit, int NumberOfValues)
    {
          HighMaximas.Clear();
    
          for(int i = 0; i < Limit; i++)
          {  
                SlidingWindow[0] = Highs[ChartID][i];
                SlidingWindow[1] = Highs[ChartID][i+1];
                SlidingWindow[2] = Highs[ChartID][i+2];
    
                 if(Counter == 0)
                 {
                       if((SlidingWindow[1] > SlidingWindow[0]) && (SlidingWindow[1] > SlidingWindow[2]) && (SlidingWindow[1] >= Highs[ChartID][0]))
                       {    
                             HighMaximas.Add(SlidingWindow[1]);
                             HighMaximaIndices.Add(i+1);
                             Counter ++;
                        }
    
                       else
                       {    
                             ;
                       }
                   }
    
                   else if((Counter > 0) && (Counter < NumberOfValues))
                   {
                         if((SlidingWindow[1] > SlidingWindow[0]) && (SlidingWindow[1] > SlidingWindow[2]) && (SlidingWindow[1] > HighMaximas[Counter-1]))
                         {                
                               HighMaximas.Add(SlidingWindow[1]);
                               HighMaximaIndices.Add(i+1);
                               Counter ++;
                         }
    
                         else
                         {
                               ;
                         }
                   }
    
                   else
                   {
                         break;
                   }
               }
    
          Counter = 0;
    
          return HighMaximas;
    }
    But when I try to compile it, I'm getting a CS0103 message saying "The name 'Highs' does not exist in the current context.". Is it possible to create a method that relies on accessing the bars array within an AddOn script?

    Thanks and Regards,
    Somebody
    Last edited by MrSomebody; 03-29-2020, 07:00 AM.

    #2
    If you pass the indicator or strategy as a variable you will be able to access the data series.

    Code:
            private NinjaScriptBase indicator;
    
            public CandleRejectionCalculator(
                  NinjaScriptBase indicator
            ) {
                this.indicator = indicator;
    Code:
            public void OnBarUpdate() {
                double open = indicator.Open[0];

    Comment


      #3
      Hi Mojo,

      Thanks for the guidance but let's say that I have a scenario where I wanted to use this method in indicator 1 and indicator 2 and since I've passed only indicator 1 in the AddOn file, wouldn't I only be able to access the BarsArray of indicator 1? If this were the case, wouldn't it lead to erroneous BarsArray accessing when I attempt to use the same method for indicator 2?

      Comment


        #4
        Hi MrSomebody,

        If I understand your question correctly
        E.g. with my example
        Code:
        new  CandleRejectionCalculator(this);
        will creating a separate instance of the class with the shared code in indicator 1 and 2.
        This means that they are totally independent of each other and the calculation won't interfere with each other.


        Comment


          #5
          Hi MrSomebody, thanks for your note.

          The BarsArray belongs to the Indicator instance, so you would need to pass in either the indicator instance or the BarsArray into the method to be able to access it.

          This example might be helpful. It uses property changed events to that NinjaScript objects that subscribe to the even can be notified of a global property change
          https://ninjatrader.com/support/foru...dsaddonexample

          Please let me know if I can assist any further.
          Chris L.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by firstlanetech, Today, 11:24 AM
          2 responses
          27 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by grayfrog, Today, 09:29 PM
          0 responses
          2 views
          0 likes
          Last Post grayfrog  
          Started by alcorr247, Today, 12:04 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_EricB  
          Started by HiddenPhilosopher, Today, 11:08 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by HiddenPhilosopher, Today, 11:03 AM
          3 responses
          8 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X