Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem inputting a string

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

    Problem inputting a string

    Hi,

    This is hopefully a very basic one. I rate my programming skills as a C-. :-)

    Anyways, i just modified an indicator to use PlaySound to alert me when such-and-such happens. Works awesome if i do: PlaySound(@"C:\Sounds\long.wav") - however i'd like to make an input in the indicator so that i can change the file name and path for the sound (rather than have it hardcoded).

    I seem to be having problems with this. Here's what i tried...

    Instead of using PlaySound(@"c:\sounds\long.wav");
    I used PlaySound(@longWavFile);

    In #region Properties section i put:

    [Description("Long Sound input file")]
    [Category("Parameters")]
    public string longWavFile

    {
    get { return longWavFile; }
    set { longWavFile = value; }
    }

    When i compile this it gives me a warning that i've done something so tragically wrong, that it will crash ninja! Ha! Yeah, right!

    Oh wait, when i put the compiled indicator onto a chart, it actually does crash ninja!

    Is it a simple solution?

    Thanks!
    Orange.

    #2
    Originally posted by MrOrange View Post
    Hi,

    This is hopefully a very basic one. I rate my programming skills as a C-. :-)

    Anyways, i just modified an indicator to use PlaySound to alert me when such-and-such happens. Works awesome if i do: PlaySound(@"C:\Sounds\long.wav") - however i'd like to make an input in the indicator so that i can change the file name and path for the sound (rather than have it hardcoded).

    I seem to be having problems with this. Here's what i tried...

    Instead of using PlaySound(@"c:\sounds\long.wav");
    I used PlaySound(@longWavFile);

    In #region Properties section i put:

    [Description("Long Sound input file")]
    [Category("Parameters")]
    public string longWavFile

    {
    get { return longWavFile; }
    set { longWavFile = value; }
    }

    When i compile this it gives me a warning that i've done something so tragically wrong, that it will crash ninja! Ha! Yeah, right!

    Oh wait, when i put the compiled indicator onto a chart, it actually does crash ninja!

    Is it a simple solution?

    Thanks!
    Orange.
    Yes. That WILL crash NinjaTrader, as I found out when I made the same mistake and wasted NinjaTrader Development's time before I noticed the error myself. You have a circular reference, so you WILL run out of heap space if you try to run that indicator, even though it might compile.

    Correct is:

    Code:
    [Description("Long Sound input file")]
    [Category("Parameters")] 
    public string [COLOR="Red"][B]L[/B][/COLOR]ongWavFile
    
    {
    get { return longWavFile; }
    set { longWavFile = value; } 
    }
    In other words, the get property string MUST be different from the public identifier. I use a different scheme, but the easiest way is to just capitalize the first letter of the public identifier if the variable starts with a small letter, and vice-versa. Hence what I have shown above.

    Comment


      #3
      Thanks koganam, it worked!!!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      331 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      549 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      549 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X