Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I access CurrentBar from a Custom Class?

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

    How do I access CurrentBar from a Custom Class?

    Hello!

    I had to create a custom class since I need to implement interfaces for comparison of my custom object. In the comparison method inside myCustomClass() I need to access CurrentBar. But then I get this error message:
    Code:
    [SIZE=2]Compiler Error CS0120[/SIZE][SIZE=2] An object reference is required for the nonstatic field, method, or property '[I]member[/I][/SIZE][B]'[/B]
    What is the best way to access CurrentBar form myCustomClass()?

    I would prefer to put the myCustomClass witin the partial Class inside the myUserDefinedIndicatorsMethods file. (The alternative would be a nested myCustomClass inside myIndicatorClass.)

    Public myCustomClass within myUserDefinedIndicatorsMethods
    Code:
    namespace NinjaTrader.Indicator
    {
        partial class Indicator
        {
            public class myCustomClass : IComparable< MyObject>, IEquatable< MyObject>
            {
                
                int CurrentBar2 = CurrentBar;
            }
        }
    }
    Nested Custom Class:
    Code:
    namespace NinjaTrader.Indicator
    {
        public class myIndicatorClass : Indicator
        {
            public class myCustomClass : IComparable< MyObject>, IEquatable< MyObject>
            {
                
                int CurrentBar2 = CurrentBar;
            }
        }
    }
    Best Regards
    poseidon_sthlm

    #2
    poseidon_sthlm, you would need to use one of the approaches as discussed here for Print - http://www.ninjatrader.com/support/f...ead.php?t=2271

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    134 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    75 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    119 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    114 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    92 views
    0 likes
    Last Post CarlTrading  
    Working...
    X