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

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
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,404 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    95 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    159 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    8 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X