Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to get Bar.GetBar() to work in the class object

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

    how to get Bar.GetBar() to work in the class object

    Hi,

    writing my first class in NT and i stuck;

    I cannot figure out how to Bars.GetBar working in the class object i defined.

    tTe method works perfectly fine in "protected override void OnBarUpdate()"
    but if I want to use it in my own class, it would give me an compile error
    "an object reference is required for non-static field, method.."
    what do i need to do? tks!

    public class TrendLine{


    private string trendLineType;
    private DateTime x1;
    private DateTime x2;
    private double y1;
    private double y2;
    private int penetrationCount;


    public DateTime X1
    {
    get
    {
    return x1;
    }
    set
    {
    x1 = value;
    }
    }

    public DateTime X2
    {
    get
    {
    return x2;
    }
    set
    {
    x2 = value;
    }
    }

    public double Y2
    {
    get
    {
    return y2;
    }
    set
    {
    y2 = value;
    }
    }

    public double Y1
    {
    get
    {
    return y1;
    }
    set
    {
    y1 = value;
    }
    }

    public int GetBarAgoX1()
    {
    DateTime timeOfInterest;
    int barsAgo;
    timeOfInterest = new DateTime(2014, 2, 20, 9, 30, 0);
    barsAgo= Bars.GetBar(timeOfInterest);
    Return barsAgo;
    }
    }

    #2
    Originally posted by lang0477 View Post
    Hi,

    writing my first class in NT and i stuck;

    I cannot figure out how to Bars.GetBar working in the class object i defined.

    tTe method works perfectly fine in "protected override void OnBarUpdate()"
    but if I want to use it in my own class, it would give me an compile error
    "an object reference is required for non-static field, method.."
    what do i need to do? tks!

    public class TrendLine{


    private string trendLineType;
    private DateTime x1;
    private DateTime x2;
    private double y1;
    private double y2;
    private int penetrationCount;


    public DateTime X1
    {
    get
    {
    return x1;
    }
    set
    {
    x1 = value;
    }
    }

    public DateTime X2
    {
    get
    {
    return x2;
    }
    set
    {
    x2 = value;
    }
    }

    public double Y2
    {
    get
    {
    return y2;
    }
    set
    {
    y2 = value;
    }
    }

    public double Y1
    {
    get
    {
    return y1;
    }
    set
    {
    y1 = value;
    }
    }

    public int GetBarAgoX1()
    {
    DateTime timeOfInterest;
    int barsAgo;
    timeOfInterest = new DateTime(2014, 2, 20, 9, 30, 0);
    barsAgo= Bars.GetBar(timeOfInterest);
    Return barsAgo;
    }
    }
    Are you using a namespace that contains Bar objects?

    Comment


      #3
      Thank you for reply.

      Yes, this class is within the default namespace of NinjaTrade.Indicator.
      I couldnt find any example of using Bars.GetBar() in the user defined classes. not sure what i am missing.

      namespace NinjaTrader.Indicator
      {
      .........
      public class TrendLine{

      ....
      }

      }

      Comment


        #4
        It would expect this unfortunately for the custom class, but would you get the same outcome if you put your GetBarAgoX1 in the indicator UserDefined methods which is a partial indicator class?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sjsj2732, 03-23-2026, 04:31 AM
        0 responses
        74 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        313 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        311 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        148 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        111 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X