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

Basic issue - How to get access to Price Series in multiple classes?

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

    Basic issue - How to get access to Price Series in multiple classes?

    Hello everybody,

    i want to use multiple classes in my strategy. Unfortunately i´m not able to use Price Series like High[], Low[], Open[] and close.

    Here is an basic example for my problem:


    Code:
    public class Thisismystrategy : Strategy
         {
         CompareClass CC1 = new CompareClass();
    
         CC1.CompareWithHigh(10, 123,12);
    
         // Now i have access in my main class / strategy to following values
         // CC1.ValueIsHigherThanHighs
         // CC1.LastBarWhatIsHigherThanValue
         // CC1.HighOfThisBar     
        }
    
    
    public class CompareClass : Strategy
         {
         private int i;
    
         public bool       ValueIsHigherThanHighs                = false
         public int          LastBarWhatIsHigherThanValue     = 0;
         public double    HighOfThisBar                              = 0; 
    
         public void CompareWithHigh (int AmountofBars, double PredefinedValue)
         {
         for(i = 1; i <= AmountofBars; i ++)
               {
                if(High[i] > PredefinedValue)
                       {
                       ValueIsHigherThanHighs            = false;
                       LastBarWhatIsHigherThanValue = i;
                       HighOfThisBar                          = High[i];
    
                       break;
                       }
    
               if(i == AmountofBars)
                      {
                       ValueIsHigherThanHighs = true;
    
                       break;
                       }
                }
            }
      }

    It seems like CompareClass has no access to Price Series like the High[] in this case. How can i solve this problem?


    #2
    Hi debleded, thanks for posting.

    Your custom class needs the StrategyBase context to access the price series from the strategy. E.g.

    Code:
    public class CompareClass : Strategy
    {
        private StrategyBase StrategyContext;
    
       CompareClass(StrategyBase _sb)
        {
            StrategyContext = _sb;
        }
    
        public double ReturnClose()
        {
            return StrategyContext.High[0];
        }
    }
    
    //from the Strategy:
    
    new CompareClass(this); //passing in the StrategyBase context.
    I also discuss including the class as a partial class here:
    I have class called Logger... I want to use this class inside indicator or strategy (ninjatrader objects). This Logger class should write text using Time[0],


    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by PaulMohn, Today, 05:00 AM
    0 responses
    7 views
    0 likes
    Last Post PaulMohn  
    Started by ZenCortexAuCost, Today, 04:24 AM
    0 responses
    6 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by ZenCortexAuCost, Today, 04:22 AM
    0 responses
    3 views
    0 likes
    Last Post ZenCortexAuCost  
    Started by SantoshXX, Today, 03:09 AM
    0 responses
    16 views
    0 likes
    Last Post SantoshXX  
    Started by DanielTynera, Today, 01:14 AM
    0 responses
    5 views
    0 likes
    Last Post DanielTynera  
    Working...
    X