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

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 TraderJA, Today, 12:06 AM
        0 responses
        4 views
        0 likes
        Last Post TraderJA  
        Started by SnailHorn, Yesterday, 10:49 PM
        0 responses
        7 views
        0 likes
        Last Post SnailHorn  
        Started by naanku, Yesterday, 07:25 PM
        0 responses
        8 views
        0 likes
        Last Post naanku
        by naanku
         
        Started by milfocs, Yesterday, 07:23 PM
        0 responses
        6 views
        0 likes
        Last Post milfocs
        by milfocs
         
        Started by PaulMohn, Yesterday, 06:59 PM
        0 responses
        8 views
        0 likes
        Last Post PaulMohn  
        Working...
        X