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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    566 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X