• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using "Times"

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

    Using "Times"

    I have a one minute bar chart with a 45 minute underlying bar chart. I wish to call an alert five minutes before the 45 minute bar closes. My logic:


    “When previous 45 min bar closes I can set 45minbarStartTime to Times[1][0]
    Then, when Times[0][0] == 45minbarStart time + 40 minutes
    Alert”


    How to code adding 40 minutes to 45min start time or is this even possible?
    Thanks

    #2
    Originally posted by Pete77 View Post
    I have a one minute bar chart with a 45 minute underlying bar chart. I wish to call an alert five minutes before the 45 minute bar closes. My logic:


    “When previous 45 min bar closes I can set 45minbarStartTime to Times[1][0]
    Then, when Times[0][0] == 45minbarStart time + 40 minutes
    Alert”


    How to code adding 40 minutes to 45min start time or is this even possible?
    Thanks
    "45minbarStart time + 40 minutes" is written as 45minbarStartTime.AddMinutes(40)

    ref: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Comment


      #3
      Hello Pete77,

      koganam is correct. The Time collection holds a DateTime object for each bar. Any DateTime methods can be used.
      https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
      http://ninjatrader.com/support/helpGuides/nt7/time.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you, I could not find an example for that.

        One last problem: I am trying to create a variable by which I can carry the time over to another indicator.
        "startTime = Times[1][0].AddMinutes(40)" Any help with syntax for that?
        I know how to make the variable public in Properties.

        Comment


          #5
          Hello Pete77,

          This depends on what you mean. If you are calling the indicator and getting that property, then just make it an input that is properly serialized.
          http://ninjatrader.com/support/forum...t.php?p=124724

          If you mean how to check an internal value of a running indicator's variable, you would likely need a static class/variable which is not supported for NinjaTrader 7.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the help. I think I am out of my league.
            I have split my project into three small indicators which depend on each other for the purpose of calculating at bar close, one on very tick on another a close of a 45 minute underlying bar and a third at the close of a my basic one minute bar chart. This gets very complicated.
            Is there any way to have parts of one indicator close at different times?
            And if a one minute chart has an underlying 45 minute bar chart with Initialize() set at “CalculateAt at Close = true”, does it close at one minute, or 45 minute” Thanks again

            Comment


              #7
              Hello Pete77,

              Yes, you can Add() to data series to a script and have different intervals (or even different instruments) also trigger OnBarUpdate when that series bar closes.
              Add() - http://ninjatrader.com/support/helpGuides/nt7/add3.htm

              When CalculateOnBarClose is false and the script is processing tick by tick (in real-time data only) it is possible to trigger actions after a close of a bar using a condition that checks for FirstTickOfBar to be true.
              FirstTickOfBar - http://ninjatrader.com/support/helpG...ttickofbar.htm
              CalculateOnBarClose - http://ninjatrader.com/support/helpG...onbarclose.htm

              What you are describing, using 3 separate indicators running separately that need to communicate is not supported for NinjaTrader 7, however, using a static variable it would be possible.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Could you lead me to an example of CalculateOnBarClose at different intervals?
                The example "SampleEnterOnceExitEveryTick_NT7.zip (6.4 KB, 858 views) seems not to help me.

                Comment


                  #9
                  Hello Pete77,

                  The intra-bar granularity reference sample is a good example of adding a secondary series and checking for BarsInProgress.

                  http://ninjatrader.com/support/forum...ead.php?t=6652
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I am back to my original problem using Times.

                    I wish add a condition whereby alert will trigger when current time is 5 minutes from the close a 45 minute bar. (Along with other conditions)

                    "Times[1][0].AddMinutes(40)" prints correctly for this coming time in my 45 minute bar.

                    if(DateTime.Now.Ticks > Times[1][0].AddMinutes(40)) { } is as close as I have been
                    able to get, but it generates the error:

                    "Operator '>' cannot be applied to operands of type 'long' and 'System Date Time'"

                    Can you give me any guidance on this?
                    Last edited by Pete77; 06-07-2017, 12:58 PM.

                    Comment


                      #11
                      Hello Pete77,

                      Is Calculate set to true?

                      Do you have a 5 minute series added to the script?

                      Are you doing the check when BarsInProgress is 1?

                      Are you checking that Times[1][0].AddMinutes(-40) is equal to Times[0][0]?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        This is a 3 min chart with 15 min secondary series.
                        Calculate is set to false.
                        I am checking when BarsInProgress == 1 also when 0..
                        When using: "if(Time[0][0] > Times[1][0].AddMinutes(40))" I get the following error message:

                        "Cannot apply indexing with [] to an expression of type 'System DateTime"

                        Comment


                          #13
                          Hello Pete77,

                          That would be correct.

                          Time does not hold an index for all series.

                          You must use Times (plural).

                          http://ninjatrader.com/support/helpGuides/nt7/times.htm

                          What would be accomplished by checking this in BarsInProgress 0 when the primary series is processing?
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by saeed, Today, 12:32 PM
                          3 responses
                          27 views
                          0 likes
                          Last Post NinjaTrader_PatrickG  
                          Started by motog4, Today, 11:42 AM
                          3 responses
                          14 views
                          0 likes
                          Last Post NinjaTrader_PatrickG  
                          Started by derivtrader, Today, 11:20 AM
                          5 responses
                          27 views
                          0 likes
                          Last Post derivtrader  
                          Started by TAJTrades, Today, 10:34 AM
                          1 response
                          7 views
                          0 likes
                          Last Post NinjaTrader_ChrisL  
                          Started by timcjpfx, Today, 10:20 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Working...
                          X