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

LineAlert coding problems

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

    LineAlert coding problems

    Hi everyone

    LineAlert is a superb indicator (strictly 'method'). Pure price action - everyone should use it!

    I'm trying to adjust this to accommodate some of the sound files I've recorded and to have different alerts for buys and sells. However, my new indicator doesn't work and I must have made a mistake in the coding somewhere.

    Firstly, to say that:

    Dow_BUY_LineAlert.wav

    Dow_SELL_LineAlert.wav

    are the files I've recorded. They work and I've placed them in the folder 'C:\Program Files\NinjaTrader 7\sounds'.

    This is what I've adjusted:

    In Variables, I've put:

    Code:
            private string     soundFileUP            = "Dow_BUY_LineAlert.wav";
            private string     soundFileDOWN        = "Dow_SELL_LineAlert.wav";
    In Properties:

    Code:
        [Description("The name of the sound file. NT will look for this file in \\Program Files\\NinjaTrader\\sounds")]
            [GridCategory("Parameters")]
            public string SoundFileUP
            {
                get { return soundFileUP; }
                set { soundFileUP = value; }
            }
    
            [Description("The name of the sound file. NT will look for this file in \\Program Files\\NinjaTrader\\sounds")]
            [GridCategory("Parameters")]
            public string SoundFileDOWN
            {
                get { return soundFileDOWN; }
                set { soundFileDOWN = value; }
            }
    In 'OnBarUpdate', where the original reads:

    Code:
    else
                        {            
                            //Alert Checking is done here. Can add your own actions to the block if desired. 
                            if(CrossBelow(Close, lineValueAtLastBar, 1) || CrossAbove(Close, lineValueAtLastBar, 1))
                            {
                                Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFile, 0, Color.White, Color.Black);  
                            }
                        }
    I've altered this to:

    Code:
    else if( CrossAbove(Close, lineValueAtLastBar, 1))
                            { Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFileUP, 0, Color.White, Color.Black); }
    
                        else   if( CrossBelow(Close, lineValueAtLastBar, 1) )
                            { Alert("AlertLineCrossing", Cbi.Priority.High, alertMessage, soundFileDOWN, 0, Color.White, Color.Black); }
    I think there must be a mistake in these 'else if' statements.

    Any advice will be much appreciated.
    Last edited by arbuthnot; 03-24-2014, 03:23 PM. Reason: Edited wrong post

    #2
    Hi arbuthnot,

    At a glance everything looks good.

    Would you be willing to supply a slimmed down version of your indicator that demonstrates this?

    Also, may I have the sound files as well so that I may test these?

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea

      Thanks very much for your reply.

      I'm attaching the exported indicator file. (As almost all the coding is the original LineAlert, I don't think I can slim it down, though I've marked out the areas of code in question).

      What is strange is that I can't upload the sound files, which are definitely '.wav'. These are the error messages I got:

      Dow_BUY_LineAlert.WAV:
      Invalid File
      Dow_SELL_LineAlert.WAV:
      Invalid File

      By the way, the indicator still doesn't work even if I substitute the original sound alert.

      I'm a bit perplexed as to what is happening and I'd greatly appreciate your advice and suggestions, Chelsea. Thanks.
      Attached Files

      Comment


        #4
        Hi arbuthnot,

        I imported your script, and then copied the Alert1.wav sound file twice and renamed these Dow_SELL_LineAlert.wav and Dow_Buy_LineAlert.wav.

        Then I played your script, added a horizontal line and received the sounds after a cross and did not receive errors.

        Are you getting errors in the Log tab of the Control Center?

        Is your machine running 64-bit windows or 32-bit?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea

          Thanks so much for testing my script and it's interesting to know that it ran perfectly well.

          There are lots of errors in the log file and this is an example which probably gets to the heart of the matter:

          Unable to play sound file C:....Dow_BUY_LineAlert.wav' Sound API only supports playing PCM wave files.
          I recorded these on a USB Voice Recorder, which produces high quality recordings in what I thought was in the conventional .wav format. It is interesting and probably relevant that I couldn't upload these.

          However, I had said my indicator didn't work with one of the NT 'native' alerts. What I had done is change the sound file name in the Indicator box.

          However, what I've done now is change the sound file name in the Variables section of the code itself and it does now work!!!

          So the culprit is the sound file I made! I think I should be able to convert my files to PCM (whatever that is!) and the problem should then be resolved.

          By the way, I have a 32-bit machine under (soon to be abandoned by Microsoft) XP.

          Many thanks for your assistance, Chelsea, and I now know I just have to make the correct sound files.

          Much obliged.

          P.S. Added on edit: for anyone having a similar problem, I've found a site where you can convert sound files to the correct format online. Go here:



          Using this, my indicator now works perfectly.
          Last edited by arbuthnot; 03-24-2014, 03:24 PM. Reason: Adding link for converting files online

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          66 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          13 views
          0 likes
          Last Post benmarkal  
          Started by f.saeidi, Today, 01:38 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X