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 FrazMann, Today, 11:21 AM
        0 responses
        1 view
        0 likes
        Last Post FrazMann  
        Started by geddyisodin, Yesterday, 05:20 AM
        8 responses
        51 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        10 responses
        36 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by DayTradingDEMON, Today, 09:28 AM
        4 responses
        24 views
        0 likes
        Last Post DayTradingDEMON  
        Started by George21, Today, 10:07 AM
        1 response
        19 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X