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 maybeimnotrader, Today, 05:46 PM
    0 responses
    6 views
    0 likes
    Last Post maybeimnotrader  
    Started by quantismo, Today, 05:13 PM
    0 responses
    6 views
    0 likes
    Last Post quantismo  
    Started by AttiM, 02-14-2024, 05:20 PM
    8 responses
    166 views
    0 likes
    Last Post jeronymite  
    Started by cre8able, Today, 04:22 PM
    0 responses
    8 views
    0 likes
    Last Post cre8able  
    Started by RichStudent, Today, 04:21 PM
    0 responses
    5 views
    0 likes
    Last Post RichStudent  
    Working...
    X