Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference of Intraday Time Range

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

    Difference of Intraday Time Range

    Hi,

    I am new to ninjascript, but would like to make a custom indicator that can simply take the difference between the net change in price over the opening hour and the net change in price over the closing hour of a day. I have started a new indicator, but it is the actual argument within the code that I am having trouble with. Can you provide me some help to getting on the right track?

    Thanks,

    Lee

    #2
    Hello Lee,

    Welcome to the NinjaTrader Support Forums!

    Probably the easiest way to get the price values at specific times is going to be to use some time filtering conditions. The following thread has a sample of code on how you may use time filters inside of a NinjaScript Strategy/Indicator.

    http://www.ninjatrader.com/support/f...ead.php?t=3226

    Once, you have your base values, you may then calculate the net change with the current price.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Difference of Desired Time Range

      Hi,

      I have been working on my indicator based on the last post provided. BTW, I could not get the example to work. Regardless, being that I have never used ninjascript or C#, I studied some existing indicators that I thought would help me out. I am trying to program a smart money indicator, and have started by just trying to get the daily value (sum of morning price delta and afternoon price delta), but have run into a road block. My programming skills with this language are very limited, so I am trying to get this daily value before I move on to the final step of taking this same formula over the chart range (or some desired period). I've been working to understand the code and believe I'm on the right track, but am not sure where to go from here.

      I've attached my script, and I am hoping you can review it and let me know where I am going wrong, or what else I can do, or do better. Because I cant seem to get values to print at certain points to test the formulas, its even more difficult for me to trouble shoot.

      Thank you,
      Attached Files

      Comment


        #4
        Hello Lee,

        It looks like you have a semi-colon ";" at the end of two of your conditional statement to check some values before running your indicators which is causing it to not do anything. See Below:

        Code:
        // Check to make sure the end hours of each range is not earlier than the start hour of each range
        			if (openEndHour < openStartHour)[B][U];[/U][/B]
        					return;
        			
        			if (lastEndHour < lastStartHour)[B][I];[/I][/B]
        					return;
        Once, those are removed you should be getting values for your calculations. Then you may use the Print() statements to verify your values that you are expecting.

        Let us know if we can be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Same price values for beginning and ending period

          JC,

          Much thanks to helping find those semicolons. Would not have seen them, and it was making life difficult. So I am now able to get values at the open and close for the time ranges I'm interested, except that the values are identical for the open and close of the morning and afternoon range. I'm not sure if my time is off, but I can get the values and deltas, except they are identical. The open and close values for the opening range appear correct, but I am not sure why they are the same for both. Also, I have found that I will not get any data until I change the data series time range to a minimum of 30 days. Not sure the reason for this.

          I was hoping you could take a look and maybe shed some light on these issues.

          Thanks again,

          Lee
          Attached Files

          Comment


            #6
            Hello Lee,

            Not quite sure what you are expecting. Could you tell me the values you are expecting and the values you are getting?

            You may would want to use Print() statements to verify values are what you expect and to see how your code is executing- Debugging your NinjaScript code.

            You may add the Print() Statements before, after and inside a condition to see the values and also make sure what bar you are referencing for Example:

            Code:
            Print("Time[0]: "+Time[0]);

            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              Hi JC,

              I'm looking for the change in price (positive or negative) for the first half hour of the day, and then the change in price (positive or negative) for the last hour of the day. Then I want to sum these values. When I run the script, I get what looks like the first half hour prices and change (for example, 141.35 opening and 141.85 after half hour for SPY yesterday), but then I get the same values (141.35, and 141.85) for the last hour prices as well. So I am not sure why it seems like I am getting the morning prices, but not the last hour of the day prices. I also am not sure why I need to set the time range to 30 days before I get any results printing on the output window.

              Here is the formula I'm ultimately trying to achieve:
              Today's SMI reading = yesterday's SMI – opening gain or loss for first half hour + change in last hour (gain or loss)

              But right now, I'm just trying to get the daily change:
              price change (gain or loss) over first half hour + price change (gain or loss) over last hour.

              I hope this is a little more clear. Let me know what you think.

              Thanks,

              Lee
              Last edited by lee612801; 12-05-2012, 01:30 PM.

              Comment


                #8
                Originally posted by lee612801 View Post
                Hi JC,

                I'm looking for the change in price (positive or negative) for the first half hour of the day, and then the change in price (positive or negative) for the last hour of the day. Then I want to sum these values. When I run the script, I get what looks like the first half hour prices and change (for example, 141.35 opening and 141.85 after half hour for SPY yesterday), but then I get the same values (141.35, and 141.85) for the last hour prices as well. So I am not sure why it seems like I am getting the morning prices, but not the last hour of the day prices. I also am not sure why I need to set the time range to 30 days before I get any results printing on the output window.

                Here is the formula I'm ultimately trying to achieve:
                Today's SMI reading = yesterday's SMI – opening gain or loss for first half hour + change in last hour (gain or loss)

                But right now, I'm just trying to get the daily change:
                price change (gain or loss) over first half hour + price change (gain or loss) over last hour.

                I hope this is a little more clear. Let me know what you think.

                Thanks,

                Lee
                Would you mind posting the printout of what you are seeing?

                Comment


                  #9
                  Sure, No problem.

                  Here is a text file of the printout from the output window. This is over a 30 day period as I could not get any output from the window with anything less than 30 days.

                  The first 4 values should be the open period price values (start and end price first half hour), and the last period price values (start and end price of last hour) The 5th and 6th values are the delta between the start and end price values for the two periods. At least that is what I intended... As is shown, they are the same for both. Not sure what I'm doing wrong.

                  Thanks for any help you can provide,

                  Lee
                  Attached Files

                  Comment


                    #10
                    Originally posted by lee612801 View Post
                    Sure, No problem.

                    Here is a text file of the printout from the output window. This is over a 30 day period as I could not get any output from the window with anything less than 30 days.

                    The first 4 values should be the open period price values (start and end price first half hour), and the last period price values (start and end price of last hour) The 5th and 6th values are the delta between the start and end price values for the two periods. At least that is what I intended... As is shown, they are the same for both. Not sure what I'm doing wrong.

                    Thanks for any help you can provide,

                    Lee
                    What timeframe are you running it on, and on what instrument?

                    Comment


                      #11
                      My chart is on a daily time frame for SPY.

                      Comment


                        #12
                        Originally posted by lee612801 View Post
                        My chart is on a daily time frame for SPY.
                        So let me get this straight.

                        You are running a single time-frame indicator on a daily chart, and you are trying to determine intraday price levels at specific times?
                        Last edited by koganam; 12-05-2012, 10:43 PM. Reason: Corrected spelling.

                        Comment


                          #13
                          Forgive me for my lack of experience with the program, but should I not be able to use different time frames for price data during the day even though I'm using a daily time frame? If its historical data, why cant I access it regardless of the time frame I have chosen to view my chart. I am only using it to calculate a value (daily change) in my formula, which is then updated daily as the new data is provided. I am very new to this, so I am trying to understand.

                          The values I am getting (text file) for the open session (first half hour) did not appear to me to match the full range of the days trading or the open and close values for the day. So if they are not either one of those (I could be wrong), then what values are they? They appeared to be the first half hours price range, but not the last hour.

                          I am not as concerned with the current day happenings of the market for this indicator, as I am with the historical data of the intraday time ranges. But I want to look at the data over a daily range.

                          Like I said, I am very new to this programming language. I know what I want, its the coding part that is the challenge. If you look at the formula I posted a couple replies back, that is what I am going for:

                          Today's SMI reading = yesterday's SMI – opening gain or loss for first half hour + change in last hour (gain or loss)

                          Can this only be done with an intraday time range? So If I choose 1 minute, 5 minute, or something else, why would daily be excluded? Wouldn't it just update once the data is available and the statement is considered true...



                          Thanks,

                          Lee

                          Comment


                            #14
                            koganam/JC,

                            I went back and looked at the code and can see that it does not seem like I am getting price values at the intraday times specified when I use the GetBar command. Kind of like you said. So the values I am getting must just be the open and close for the day which is why they are the same. Seems to make some sense... I think.

                            Soooooo, I think the question is, what can I do? I am getting the right times for the specified period of each day, but how can I retrieve the price data from each of these times? When I switch to a minute timeframe, nothing shows up on the chart. I would like to view it on a daily chart. I guess that's the trick...

                            As I am a new user, I use the free kinetick (end of day) or Yahoo free feeds. Not sure if this is a problem.

                            Lee

                            Comment


                              #15
                              Originally posted by lee612801 View Post
                              koganam/JC,

                              I went back and looked at the code and can see that it does not seem like I am getting price values at the intraday times specified when I use the GetBar command. Kind of like you said. So the values I am getting must just be the open and close for the day which is why they are the same. Seems to make some sense... I think.

                              Soooooo, I think the question is, what can I do? I am getting the right times for the specified period of each day, but how can I retrieve the price data from each of these times? When I switch to a minute timeframe, nothing shows up on the chart. I would like to view it on a daily chart. I guess that's the trick...

                              As I am a new user, I use the free kinetick (end of day) or Yahoo free feeds. Not sure if this is a problem.

                              Lee
                              Well, it really has nothing to do with the language, which is just a means of translating logic into code, so let us look at the logic, instead of the language.

                              You are using EOD data. What does that mean? It means that at the end of the day, you receive the day's data. The only data that you can possibly receive is the OHLC, because that is the only data that is provided.

                              If that is the only data that you receive, there is no way to extract any other data from within the bar. If you want to use intraday information, then you need intraday data.
                              Last edited by koganam; 12-06-2012, 01:36 PM. Reason: Corrected spelling.

                              Comment

                              Latest Posts

                              Collapse

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