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

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.
      Represents an instant in time, typically expressed as a date and time of day.

      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.


          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.

                  You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by
                  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).



                          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 adeelshahzad, Today, 03:54 AM
                          0 responses
                          0 views
                          0 likes
                          Last Post adeelshahzad  
                          Started by CortexZenUSA, Today, 12:53 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post CortexZenUSA  
                          Started by CortexZenUSA, Today, 12:46 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post CortexZenUSA  
                          Started by usazencortex, Today, 12:43 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post usazencortex  
                          Started by sidlercom80, 10-28-2023, 08:49 AM
                          168 responses
                          2,266 views
                          0 likes
                          Last Post sidlercom80  
                          Working...
                          X