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

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 andrewtrades, Today, 04:57 PM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      5 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      7 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X