• 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

Looking for a time alert indicator

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

    #16
    Hello Slide588,

    Thanks for your reply.

    An extra check for this specific case can be addressed in the following way:

    //declare this variable outside of Initialize() and OnBarUpdate()
    private int x;

    //assign the value in Initialize()
    protected override void Initialize()
    {
    x = Time[0].Minute;
    }

    protected override void OnBarUpdate()
    {
    if(x == 0)
    x = 60;
    else
    x = Time[0].Minute;

    if(DateTime.Now.Minute == (x - 1) && (60 - DateTime.Now.Second) <= 15)
    //trigger alert
    }

    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment


      #17
      Hi Alan

      So I've coded this and the alerts aren't playing. They do play if I take the time check out. I'm testing the code in replay mode; will it make a difference? Can I send the code through for checking? Also is there a way to see values to debug the code in NT7, set break points etc?

      Thanks

      Comment


        #18
        Hello Slide588,

        Thanks for your reply.

        DateTime.Now will pull your PC clock's time rather than the time of the bar when running in replay mode, so you would have to rewrite this script in order for it to behave as expected while connected to Market Replay. You would need to use the Time[] to retrieve the time stamp of the bar.

        Additionally, you will need to ensure that your strategy is calculating on each tick, or that your CalculateOnBarClose property is set to false.

        You can debug your scripts in this manner with Visual Studio. For more information on how to do this with Visual Studio, please follow the link below:
        https://ninjatrader.com/support/help..._debugging.htm

        Please let me know if I may be of any further assistance.
        Alan S.NinjaTrader Customer Service

        Comment


          #19
          Thanks for all your help Alan.

          Just to confirm, with CalculateOnBarClose = false then Time[0] will give the instant bar time stamp, ie second by second or even milliseconds and with CalculateOnBarClose = true then Time[0] will give the time when the bar will close.

          So I could use Time[0] for both real time and replay mode. If the above is correct then what would be the code please for sounding the alert 15 seconds before the close of the bar using Time[0]? Because I don't know when the bar will close with CalculateOnBarClose = false, or do I? Have I missed something?

          Comment


            #20
            Hello Slide588,

            Thanks for you reply.

            I think that the best solution here would be to borrow some code from the BarTimer() indicator to implement in your script.

            If you go to Tools --> Edit NinjaScript --> Indicator --> double click on the BarTimer indicator to open it, you will see that this indicator declares a DateTime variable in the following manner:

            Code:
            		
            private DateTime Now
            		{
            			get 
            			{ 
            				DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); 
            
            				if (now.Millisecond > 0)
            					now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
            
            				return now;
            The key here is that the variable is assigned the Bars.MarketData.Connection.Now value when connected to Market Replay, which will print the time of the bar while in replay. You can add this property to your script to reliably check against the time remaining on the bar while connected to Market Replay and your real-time data feed.

            You are correct in that regardless of the CalculateOnBarClose setting, retrieving the Time[] value will return the closing time of the bar rather than the intra-bar value.

            Please let me know if I may be of any further assistance.
            Alan S.NinjaTrader Customer Service

            Comment


              #21
              Hi Alan

              If I can get some extra help with this please. So I've added the suggested code as:

              #region Miscellaneous

              private DateTime Now
              {
              get
              {
              DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now);

              if (now.Millisecond > 0)
              now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate ).TotalSeconds));

              return now;
              }
              }

              #endregion

              And in OnBarUpdate() have the condition:

              if ((Now.Minute==0) && (Now.Second<=30))
              {}

              i.e. I want to do something if there's 30 seconds or less until the bar closes. It doesn't seem to be working in replay mode, haven't tried live. Is there something obvious that I'm doing wrong?

              Thanks.

              Comment


                #22
                Is CalculateOnBarClose set to false?

                What period type are you using?
                JoshNinjaTrader Customer Service

                Comment


                  #23
                  CalculateOnBarClose = false and I'm using 3 min charts.


                  Is there a way to do a simple Print statement to check if a condition is triggered to debug my code? Where would I see the output?



                  Thanks

                  Comment


                    #24
                    I think you are on the right track regarding debugging with Prints. Prints would go to your NinjaScript Output Window. You will find a button for it at the top of the NS editor.

                    The following help guide document talks about this topic: Help Guide- Debugging Your NinjaScript
                    JoshNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kangethe, Today, 08:04 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post kangethe  
                    Started by akuntysh, Yesterday, 09:21 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post akuntysh  
                    Started by i2w8am9ii2, Today, 06:57 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post i2w8am9ii2  
                    Started by buzzripper, Today, 06:14 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Ray  
                    Started by sidviciousX, Today, 06:47 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_RyanS  
                    Working...
                    X