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 giulyko00, 04-24-2024, 12:03 PM
      5 responses
      27 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by 00nevest, 04-27-2024, 02:27 PM
      3 responses
      27 views
      0 likes
      Last Post 00nevest  
      Started by Newtrader101, Today, 07:36 AM
      0 responses
      2 views
      0 likes
      Last Post Newtrader101  
      Started by 21laienoch, Today, 07:25 AM
      0 responses
      7 views
      0 likes
      Last Post 21laienoch  
      Started by burtoninlondon, 04-28-2024, 12:38 AM
      1 response
      17 views
      0 likes
      Last Post burtoninlondon  
      Working...
      X