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 Haiasi, 04-25-2024, 06:53 PM
    2 responses
    16 views
    0 likes
    Last Post Massinisa  
    Started by Creamers, Today, 05:32 AM
    0 responses
    4 views
    0 likes
    Last Post Creamers  
    Started by Segwin, 05-07-2018, 02:15 PM
    12 responses
    1,785 views
    0 likes
    Last Post Leafcutter  
    Started by poplagelu, Today, 05:00 AM
    0 responses
    3 views
    0 likes
    Last Post poplagelu  
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,407 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Working...
    X