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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        9 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        14 views
        0 likes
        Last Post AaronKoRn  
        Started by carnitron, Yesterday, 08:42 PM
        0 responses
        11 views
        0 likes
        Last Post carnitron  
        Started by strategist007, Yesterday, 07:51 PM
        0 responses
        13 views
        0 likes
        Last Post strategist007  
        Started by StockTrader88, 03-06-2021, 08:58 AM
        44 responses
        3,983 views
        3 likes
        Last Post jhudas88  
        Working...
        X