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 mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Started by gwenael, Today, 09:29 AM
        0 responses
        1 view
        0 likes
        Last Post gwenael
        by gwenael
         
        Started by Karado58, 11-26-2012, 02:57 PM
        8 responses
        14,829 views
        0 likes
        Last Post Option Whisperer  
        Started by Option Whisperer, Today, 09:05 AM
        0 responses
        1 view
        0 likes
        Last Post Option Whisperer  
        Started by cre8able, Yesterday, 01:16 PM
        3 responses
        11 views
        0 likes
        Last Post cre8able  
        Working...
        X