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

Sound Files Dropdown Picker

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

    Sound Files Dropdown Picker

    Hello,

    I'm trying to create a dropdown sounds picker to go with NinjaTrader_Alan's Inside Bar indicator. I need it to avoid having to hardcode it on multiple versions of the same indicator for each chart.
    So far I've researched those sources to find how to do it https://ninjatrader.com/support/foru...225#post775225 https://ninjatrader.com/support/foru...976#post671976 https://ninjatrader.com/support/foru...409#post805409

    I updated NinjaTrader_Alan Inside bar indicator based on his recommendation from the 3rd link above. Script in attachment.

    I added those:
    Code:
     #region Properties
    // Create our user definable color input
    [XmlIgnore()]
    [Display(Name = "BorderBrush", GroupName = "NinjaScriptParameters", Order = 0)]
    public Brush BorderBrush
    { get; set; }
    
    // Serialize our Color object
    [Browsable(false)]
    public string BorderBrushSerialize
    {
    get { return Serialize.BrushToString(BorderBrush); }
    set { BorderBrush = Serialize.StringToBrush(value); }
    }
    
    //dropdown sounds picker
    [NinjaScriptProperty]
    [TypeConverter(typeof(NinjaTrader.NinjaScript.Indic ators.AlanIndicators.SoundConverter))]
    public string SoundFiles
    {get;set;}
    #endregion
    Code:
     public class SoundConverter : TypeConverter
    {
    
    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
    {
    if (context == null)
    {
    return null;
    }
    //List <string> list;
    List <string> list = new List <string> ();
    
    
    DirectoryInfo dir = new DirectoryInfo(NinjaTrader.Core.Globals.InstallDir+ "sounds");
    
    FileInfo[] files= dir.GetFiles("*.wav");
    
    foreach (FileInfo file in files)
    {
    list.Add(file.Name);
    }
    
    
    return new TypeConverter.StandardValuesCollection(list);
    }
    
    
    
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
    {
    return true;
    }
    }

    I get those errors:
    InsideBarPaintedUserSpecifiedColor.cs The type or namespace name 'DirectoryInfo' could not be found (are you missing a using directive or an assembly reference?) CS0246 118 4
    InsideBarPaintedUserSpecifiedColor.cs The type or namespace name 'DirectoryInfo' could not be found (are you missing a using directive or an assembly reference?) CS0246 118 28
    InsideBarPaintedUserSpecifiedColor.cs The type or namespace name 'FileInfo' could not be found (are you missing a using directive or an assembly reference?) CS0246 120 4
    InsideBarPaintedUserSpecifiedColor.cs The type or namespace name 'FileInfo' could not be found (are you missing a using directive or an assembly reference?) CS0246 122 13
    Attached Files

    #2
    Try adding,

    Code:
    using System.IO;
    More info here.

    Comment


      #3
      Hello bltdavid, the output looks like a charm thanks. With screenshot. I'll test later the sound signals.

      Many thanks.
      Attached Files

      Comment


        #4
        I've tested and it doesn't play the sound. I've got the wav file in there C:\Program Files (x86)\NinjaTrader 8\sounds
        Attached Files

        Comment


          #5
          Hello PaulMohn,

          Thank you for the post.

          In the file you attached I don't see you have used the sound at all, you would still need to use the sound file in some way for example with Alert or PlaySound. It looks like you have the Path part handled so you would pass that path to Alert or PlaySound

          https://ninjatrader.com/support/help...lightsub=alert
          https://ninjatrader.com/support/help...tsub=PlaySound

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Hello Jesse and many thanks for your point. Would it work that way, by just adding a PlaySound action in OnBarUpdate, but without specifying the wav file?

            Code:
             protected override void OnBarUpdate()
            {
            if(CurrentBar<2) return;
            
            if(High[0]<High[1] && Low[0]>Low[1])
            {
            BarBrush = BorderBrush;
            Draw.Line(this, "tag1"+CurrentBar, false, 0, High[1], 1, High[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
            Draw.Line(this, "tag2"+CurrentBar, false, 0, Low[1], 1, Low[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
            PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds");
            
            }
            }
            So not to hardcode it and allow for the dropdown selection?

            Comment


              #7
              Hello PaulMohn,

              No you would need to specify the file you wanted to play with PlaySound. That could be a string variable which is a path to a file or also hard coded:

              Code:
              PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\MySound.wav");
              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                But then can I still switch and drop-down select any wav file? The purpose is to load the same script on multiple charts/instruments and just switch the sound via dropdown (the idea is to have a sound firing the instrument name and then the signal like GC Inside Bar on the GC Chart, ES inside bar on the ES chart and so on), so I don't have to create multiple versions of the same script for each Chart/instrument.

                Comment


                  #9
                  Hello PaulMohn,

                  I would suggest to review the sample where you found that sound picker to see how the string is being used, you could likely supply the SoundFiles string to the PlaySound or Alert assuming that the SoundFiles is a sound file path. You can use a Print to see what the value of SoundFiles is when the script is running:

                  Code:
                  Print(SoundFiles);
                  If that is a path to a wave file when you printed it then you can use it with the methods:
                  Code:
                  PlaySound(SoundFiles);
                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Ok, many thanks for the suggestion. here's what I've done:

                    Code:
                     protected override void OnBarUpdate()
                    {
                    if(CurrentBar<2) return;
                    
                    if(High[0]<High[1] && Low[0]>Low[1])
                    {
                    BarBrush = BorderBrush;
                    Draw.Line(this, "tag1"+CurrentBar, false, 0, High[1], 1, High[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                    Draw.Line(this, "tag2"+CurrentBar, false, 0, Low[1], 1, Low[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                    //PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds");
                    PlaySound(SoundFiles);
                    
                    }
                    Print(SoundFiles);
                    }
                    But nothing shows in the Output Window. Do i need to wait for an Inside Bar? or is there another way?

                    Comment


                      #11
                      I lowered the time frame and now I get the prints. I'll wait to see if sound triggers on the next Inside Bar.

                      Comment


                        #12
                        Hello PaulMohn,

                        I don't specifically see anything wrong with that, did you manually select a sound file before clicking OK on the indicator dialog? It would be blank if you hadn't selected a file to start with.

                        That otherwise seems to print the alert name so you would likely need to still build the path:

                        Code:
                        PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\" + SoundFiles);

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          I waited for an Inside Bar but the sound did not trigger. I got this error in the log:
                          04/10/2021 18:18:00 Default Failed to play sound file 'GoldIB.wav': Please be sure a sound file exists at the specified location.

                          The sound file is there C:\Program Files (x86)\NinjaTrader 8\sounds

                          Also in attachment.

                          Here's my OnbarUpdate
                          Code:
                           protected override void OnBarUpdate()
                          {
                          if(CurrentBar<2) return;
                          
                          if(High[0]<High[1] && Low[0]>Low[1])
                          {
                          BarBrush = BorderBrush;
                          Draw.Line(this, "tag1"+CurrentBar, false, 0, High[1], 1, High[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                          Draw.Line(this, "tag2"+CurrentBar, false, 0, Low[1], 1, Low[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                          //PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds");
                          PlaySound(SoundFiles);
                          
                          }
                          Print(SoundFiles +" " + Time[0]);
                          }
                          Attached Files

                          Comment


                            #14
                            Originally posted by NinjaTrader_Jesse View Post
                            Hello PaulMohn,

                            I don't specifically see anything wrong with that, did you manually select a sound file before clicking OK on the indicator dialog? It would be blank if you hadn't selected a file to start with.

                            That otherwise seems to print the alert name so you would likely need to still build the path:

                            Code:
                            PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\" + SoundFiles);

                            I look forward to being of further assistance.
                            Yes I had it on the specific wav file in the Indicator property window. Here's the prints:

                            GoldIB.wav 04/10/2021 18:43:00
                            GoldIB.wav 04/10/2021 18:44:00
                            GoldIB.wav 04/10/2021 18:45:00
                            GoldIB.wav 04/10/2021 18:46:00
                            GoldIB.wav 04/10/2021 18:47:00
                            GoldIB.wav 04/10/2021 18:48:00
                            GoldIB.wav 04/10/2021 18:49:00
                            GoldIB.wav 04/10/2021 18:50:00
                            GoldIB.wav 04/10/2021 18:51:00
                            GoldIB.wav 04/10/2021 18:52:00
                            GoldIB.wav 04/10/2021 18:53:00
                            GoldIB.wav 04/10/2021 18:54:00
                            GoldIB.wav 04/10/2021 18:55:00
                            GoldIB.wav 04/10/2021 18:56:00

                            May thanks for the PlaysSound update, I'll test it.

                            Comment


                              #15
                              Yep, now it's working.

                              Working OnbarUpdate
                              Code:
                               protected override void OnBarUpdate()
                              {
                              if(CurrentBar<2) return;
                              
                              if(High[0]<High[1] && Low[0]>Low[1])
                              {
                              BarBrush = BorderBrush;
                              Draw.Line(this, "tag1"+CurrentBar, false, 0, High[1], 1, High[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                              Draw.Line(this, "tag2"+CurrentBar, false, 0, Low[1], 1, Low[1], Brushes.LimeGreen, DashStyleHelper.Dot, 2);
                              //PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds");
                              //PlaySound(SoundFiles);
                              PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\" + SoundFiles);
                              
                              }
                              Print(SoundFiles +" " + Time[0]);
                              }
                              Many thanks again. Have a great day!
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sjeffblack, Today, 01:22 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Started by Kicks.Spin, Today, 01:24 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by JLSwin, Today, 01:07 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Started by dgee949, Today, 12:11 PM
                              4 responses
                              19 views
                              0 likes
                              Last Post dgee949
                              by dgee949
                               
                              Started by jalro, Today, 10:25 AM
                              1 response
                              18 views
                              0 likes
                              Last Post NinjaTrader_Kate  
                              Working...
                              X