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

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?
                Josh G.NinjaTrader 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
                    Josh G.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    5 responses
                    67 views
                    0 likes
                    Last Post tsantospinto  
                    Started by cre8able, Today, 03:20 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post cre8able  
                    Started by Fran888, 02-16-2024, 10:48 AM
                    3 responses
                    48 views
                    0 likes
                    Last Post Sam2515
                    by Sam2515
                     
                    Started by martin70, 03-24-2023, 04:58 AM
                    15 responses
                    115 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by The_Sec, Today, 02:29 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X