Announcement

Collapse
No announcement yet.

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X