Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question regarding previous day High, low and close

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

    Question regarding previous day High, low and close

    Hi everyone,

    I needed a little help on a step for a strategy I'm currently developing.

    The strategy involves hardcoding some price levels into the where i'd like to take profit. The data required for the lines is the high low and close, for the previous day, 2 days before and 3 days before. Also, I don't want it to be a rolling 3 days, which I guess could be done be specifying the number of bars in 24 hours and using the MAX() and MIN() functions. I shall include the code of what I have tried to solve below, however I keep getting 'an object reference is required' error.

    The code I have tried to run so far is:

    public double d1p = (Bars.GetDayBar(1).High + Bars.GetDayBar(1).Low + Bars.GetDayBar(1).Close)/3;
    public double d2p = (Bars.GetDayBar(2).High + Bars.GetDayBar(2).Low + Bars.GetDayBar(2).Close)/3;
    public double d3p = (Bars.GetDayBar(3).High + Bars.GetDayBar(3).Low + Bars.GetDayBar(3).Close)/3

    Any help is much appreciated!

    #2
    Hello Muddy,
    Thanks for posting today.

    If these variables are initialized in the variables region for the indicator they will not be able to reference the Bars object.

    You can initialize this variable to some value and then set in another method.

    For example.
    Code:
    #region variables
    private double d1p = 0;
    
    ...
    
    OnBarUpdate()
    {
    double d1p =(Bars.GetDayBar(1).High + Bars.GetDayBar(1).Low + Bars.GetDayBar(1).Close)/3;
    
    ...}
    Please let us know if we may be of further assistance for anything NinjaTrader.
    Alex G.NinjaTrader Customer Service

    Comment


      #3
      Hi Alex,

      Thanks for the quick response - I'm not actually using an indicator as such - I'm using the equations on which the indicator is based to hard code in limits (which aren't plotted or anything) around which I base my strategy. Basically specific prices I want to see crossed or to take profit at. I tried moving the variables into the onbarupdate() section, however now the inequalities I wish to base my strategy on are getting errors regarding invalid tokens and 'Array size cannot be specified in a variable declaration'. Thanks again for taking the time to help!
      Last edited by Muddy; 07-17-2015, 03:08 PM.

      Comment


        #4
        Hello Muddy,
        Thanks for the reply.

        Can you provide a screenshot of the error that is occurring?

        To send a screenshot with Windows 7 or newer I would recommend using Window's Snipping Tool.

        Click here for instructions

        Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file and send the file as an attachment.

        Click here for detailed instruction

        I look forward to your reply and further assisting.
        Alex G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X