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

Left Right option

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

    Left Right option

    I have an indicator in which I included the option to optionally turn on/off a sound file. To do that I used
    private bool sound_On = true; // in the Variables Section of the code,

    followed by

    if (sound_On) Alert(uniqueID, NinjaTrader.Cbi.Priority.High, "MyCross", soundFilelong, str, Color.Black, Color.Yellow);

    in the protected override void OnBarUpdate() Section, and in the Properties section I have

    [GridCategory("Parameters")]
    public bool Sound_On
    {
    get { return sound_On; }
    set { sound_On = value; }
    }

    So far so good. Now I have another indicator which places a colored stripe in a chart. This one seems a bit more complex as it uses some kind of dockstyle and toolstripforms.

    It reads
    Dock = Dockstyle.Right.

    I can manually replace "Right" with "Left", and it then places the stripe to the left of the chart.

    Question. With what do I have to replace "Right", and what do I have to add into the code similarly to the Sound thing I explained, so that I can have it as an option in the indicator menu to place it left or right, if that is even possible.

    sandman

    #2
    Hello sandman,

    Thank you for your post.

    Set up another bool and use it to set the value, for example:
    Code:
    if(myBool)
    Dock = Dockstyle.Right;
    else if(!myBool)
    Dock = Dockstyle.Left;

    Comment


      #3
      Thanks Patrick,

      I tried different variations to include your suggested piece of code but I guess I am doing something wrong. I include an image. To the left is the indicator as it is right now and it works, including my amendment that the sound on or off and even the width of the stripe can be defined through the indicator menu.

      But with this left or right I am doing something wrong. On the right side of the image is my attempt to include the code but it gives error messages. I already tried changing the commas to semicolons but that gives similar error messages.

      Could you look it over and advise as to where or how I am off.

      sandman
      Attached Files

      Comment


        #4
        Hello sandman,

        Thank you for your response.

        I will look into this matter further and follow up with you when I have additional details.

        Comment


          #5
          Originally posted by sandman View Post
          Thanks Patrick,

          I tried different variations to include your suggested piece of code but I guess I am doing something wrong. I include an image. To the left is the indicator as it is right now and it works, including my amendment that the sound on or off and even the width of the stripe can be defined through the indicator menu.

          But with this left or right I am doing something wrong. On the right side of the image is my attempt to include the code but it gives error messages. I already tried changing the commas to semicolons but that gives similar error messages.

          Could you look it over and advise as to where or how I am off.

          sandman
          I didn't try to compile this, but this should work:

          Code:
          if (toolStripForm==null)
          {
             if (margin_On)
                toolStripForm= new ToolStrip() ( Dock=DockStyle.Right, Name='ToolStripFormeSenderReceiever', Visible=true); 
              else if (!margin_On)
                toolStripForm= new ToolStrip() ( Dock=DockStyle.Left, Name='ToolStripFormeSenderReceiever', Visible=true); 
          
          ....
          
          }

          Comment


            #6
            Hello sandman,

            Thank you for your patience.

            It looks like sledge is correct here. You would need to remove the semi-colon ';' at the end of the section with the check for margin_On. You would likely also want the if(margin_On) before the open bracket.

            Comment


              #7
              Thank you Sledge and Patrick,
              I have tried this for the last two hours but simply cannot get it to compile. I keep getting error messages. One of these I resolved as it requires double quote marks. But that did not resolve it fully. See attached image.

              I attach the indicator in the version that works, and have included in it the code from Sledge in green; line 66.

              Is it possible for either of you to review this once more. I am not an expert at this but I feel Sledge's code is correct - the only thing wrong is where the brackets are put.

              sandman
              Attached Files

              Comment


                #8
                Hello sandman,

                Thank you for your patience.

                I have not had a chance to fully test this on my end. I will return on Sunday and test this further.

                Comment


                  #9
                  Hello sandman,

                  Thank you for your patience.

                  You will find the corrected code below:
                  Code:
                  				if (toolStripForm==null)
                  				{
                     			if (margin_On)
                        		toolStripForm= new ToolStrip() {Dock=DockStyle.Right, Name="ToolStripFormeSenderReceiever", Visible=true}; 
                      			else if (!margin_On)
                        		toolStripForm= new ToolStrip() {Dock=DockStyle.Left, Name="ToolStripFormeSenderReceiever", Visible=true}; 
                  
                  
                  				}

                  Comment


                    #10
                    Thanks a LOT Patrick. Works like a charm.

                    Out of interest:
                    How did you figure out to use this type of bracket "{ }" instead of the "()" regular ones?

                    sandman

                    Comment


                      #11
                      Hello sandman,

                      Thank you for your response.

                      This was actually the format being used in your strategy code that was compiling above the commented section:
                      Code:
                      		protected override void OnStartUp()
                      		{			
                      
                      			if(toolStripForm == null)
                      				{	
                      					toolStripForm = new ToolStrip()
                      						{	
                      						Dock = DockStyle.Right,
                      						Name = "ToolStripFormeSenderReceiver", 
                      						Visible		= true 	
                      						};
                      In most cases, you can look to other uses of class you are trying to use (such as ToolStrip) in your indicator or others for the correct syntax to use.

                      Comment


                        #12
                        Originally posted by sandman View Post
                        Thanks a LOT Patrick. Works like a charm.

                        Out of interest:
                        How did you figure out to use this type of bracket "{ }" instead of the "()" regular ones?

                        sandman
                        That is the standard C# syntax to initialize a new object with specific parameters.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by techgetgame, Today, 11:42 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post techgetgame  
                        Started by sephichapdson, Today, 11:36 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post sephichapdson  
                        Started by bortz, 11-06-2023, 08:04 AM
                        47 responses
                        1,612 views
                        0 likes
                        Last Post aligator  
                        Started by jaybedreamin, Today, 05:56 PM
                        0 responses
                        9 views
                        0 likes
                        Last Post jaybedreamin  
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        19 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Working...
                        X