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

Opening Bell indicator NT8 - IsFirstBarOfSession not working?

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

    Opening Bell indicator NT8 - IsFirstBarOfSession not working?

    Hello,

    This is my first attempt to write a simple NT8 indicator. The purpose is to play a sound file at market open. In the OnBarUpdate() method I have an if stmt:

    if (bOpeningBellAlert && Bars.IsFirstBarOfSession && IsFirstTickOfBar && !String.IsNullOrEmpty(sSoundFile))
    {
    PlaySound(@"" + sSoundFile);
    }
    The sound file would not play at the first tick of a daily chart. When I changed the if stmt as such:
    if (bOpeningBellAlert && !String.IsNullOrEmpty(sSoundFile))
    {
    PlaySound(@"" + sSoundFile);
    }
    Then, the sound file would play on every tick. I'm running NT8 version 8.0.14.2 64-bit. I have attached the indicator in hope that someone can take a look and see what I did wrong.

    Also, I'm interested to know since playing a sound file at market open is a single event, would an indicator be over killed because it's continuously being check on every tick update?

    Thanks in advance for your help
    Attached Files

    #2
    Hello hcgaloi,

    Thank you for your note.

    What time series are you applying the indicator to? For example, a daily chart.
    The warning at the following link of the helpguide states IsFirstBarOfSession is always false on Non-Intraday bar periods.



    Rather than playing a sound, if you call an alert which also plays a sound, and set the rearm period to a value which would prevent it becoming rearmed until the next day, does this resolve the issue?

    For example,

    Code:
    if(Bars.IsFirstBarOfSession)
    Alert("myAlert", Priority.High, "OpenAlert", NinjaTrader.Core.Globals.InstallDir+@"\sounds\Alert1.wav", 6000, Brushes.Black, Brushes.Yellow);
    See Alert section of our helpguide,


    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for helping.

      You were right! I applied the indicator to a Daily chart, thus, Bars.IsFirstBarOfSession returned false.
      I have also tried to replaced PlaySound with Alert() and rearmed after 8 hours. Here is the new code:

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;


      //
      //Bars.IsFirstBarOfSession is for intraday charts. It will will
      //always return false on non-intraday bar periods (e.g., Day, Month, etc)
      //
      if (bOpeningBellAlert && IsFirstTickOfBar && !String.IsNullOrEmpty(sSoundFile))
      {

      Print("KCDB IsFirstTickOfBar = " +IsFirstTickOfBar);

      //
      //instead of PlaySound, use alert to plays a sound, and set the rearm period to a
      //value which would prevent it becoming rearmed until the next day (rearm after 8 hours (288000 secs)
      //
      //Alert("KevinOpeningSoundAlert", Priority.High, "OpeningAlert", sSoundFile, 288000, Brushes.Black, Brushes.Yellow);
      PlaySound(@"" + sSoundFile);
      }

      }//protected override void OnBarUpdate()

      Because Alert() can only be called when State is in State.Realtime, I'm unable to test with playback, so I use PlaySound() for testing purpose. However, PlaySound() doesn't get executed even though the if condition is true as verified by Print() stmt.

      Thanks again for your help.

      I have added the indicator in the attachment if you would kindly check my codes.
      Attached Files
      Last edited by hcgaloi; 06-23-2018, 05:58 PM. Reason: add attachment

      Comment


        #4
        Will you be sharing this 'indicator' of an opening bell?

        Comment


          #5
          Sure. I'll share once I test it fully ... 8-)

          Comment


            #6
            look very forward to it!!

            Comment


              #7
              Hello Kevin,

              Working with you via email but for those interested in the thread, I have put together an indicator which will have an alarm go off when the time is equal to the user inputted time.

              Please let us know if you need further assistance.
              Attached Files
              Alan P.NinjaTrader Customer Service

              Comment


                #8
                Hello SBMT17,

                With the help of NinjaTrader_AlanP, I got the OpeningBellAlert indicator working. I have attached the file here. You need to import the indicator to NT8 by Tools->Import->Ninja Script Add-On then choose the .zip file. The indicator sound is default to NT Alert1. If you prefer exchange opening bell sound, I have attached the OpeningBell.wav. You can copy the sound file to NT8 sound folder at Program Files (x86)\NinjaTrader 8\sounds.

                To use the indicator, add it to Daily chart or any intraday chart. There are three user input fields if you want to change them:

                1. Sound file is default to Alert1. You can click on it and pick any .wav file you want (OpeningBell.wav)
                2. Rearm alert is default to 32400 seconds (9 hours), change it to any value that you want
                4. Enable Alert is checked. Uncheck if you don't want an alert.

                Cheers

                NT8OpeningBellAlertIndicator.zip
                Attached Files
                Last edited by hcgaloi; 06-25-2018, 10:42 PM. Reason: add attachment

                Comment


                  #9
                  Originally posted by hcgaloi View Post
                  2. Rearm alert is default to 32400 seconds (9 hours), change it to any value that you want

                  [ATTACH]49384[/ATTACH]
                  I'm confused how to set it up to trigger the bell on 06:30 PST.

                  Comment


                    #10
                    Hello Johndc,

                    Thanks for your post and welcome to the NinjaTrader forums!

                    Hopefully, member hcgaloi will be able to respond to this 2018 forum thread.

                    In looking at the code of the indicator, it appears to be dependant upon the first bar of the session.

                    If you are using a trading hours template that is RTH based (Regular trading hours), then (assuming 6:30 PST equates to the opening time of the session), it should sound the alert and send an alert message to the New>alerts log window.

                    There are no abilities in the indicator to adjust the time.



                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for the reply NinjaTrader_PaulH. Sorry to bump this thread..

                      After installing the opening bell indicator, it just triggered the alert on some random time.

                      Comment


                        #12
                        Hello Johndc,

                        Thanks for your reply.

                        Have you tried the indicator in Post #7, by my collegue AlanP, where you can specify the time?

                        That might be more suited to your needs.

                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          It does work, but there is no option to change the sound and just plays some default. I'll try to find someone who can able to add that option. Thanks

                          Comment


                            #14
                            Originally posted by NinjaTrader_PaulH View Post
                            Hello Johndc,

                            Thanks for your reply.

                            Have you tried the indicator in Post #7, by my collegue AlanP, where you can specify the time?

                            That might be more suited to your needs.
                            Okay I got it to work. I had to manually add the openingbell wav files in the Sound folder and changed the file name in the Script editor. Thanks

                            Hopefully someone can just add the option.
                            Last edited by Johndc; 01-07-2021, 05:35 PM.

                            Comment


                              #15
                              Originally posted by Johndc View Post
                              Hopefully someone can just add the option.
                              Did a small update on that code (untested)...
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by ZenCortexCLICK, Today, 04:58 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post ZenCortexCLICK  
                              Started by sidlercom80, 10-28-2023, 08:49 AM
                              172 responses
                              2,280 views
                              0 likes
                              Last Post sidlercom80  
                              Started by Irukandji, Yesterday, 02:53 AM
                              2 responses
                              17 views
                              0 likes
                              Last Post Irukandji  
                              Started by adeelshahzad, Today, 03:54 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post adeelshahzad  
                              Started by Barry Milan, Yesterday, 10:35 PM
                              3 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X