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

NinjaScript Error in New Indicator

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

    NinjaScript Error in New Indicator

    Hello,

    I'm attempting to develop a simple indicator, but I'm new to NinjaScript and to C# and have an error that has me stuck and that I need help with.

    The purpose of the indicator is to draw simple horizontal lines with specific colors, styles and widths when a button on the chart is pressed.

    I draw these buttons by hand each day when I arrive at a chart to mark off certain support and resistance levels and other such things on the different time-frames that I trade and drawing them by hand for each market that I trade takes too long.

    I want to be able to have the indicator instantly draw all the horizontal lines that I need formatted in the way where I can quickly recognize what each one is for, so that all I have to do is re-position them on my charts.

    Screenshots attached. The orange boxes show code that I added. The red box shows code that I added which is giving me the error message.

    The .cs file for this indicator is also attached.

    Please assist and advise.

    Thanks,

    i2w8am9ii2
    Attached Files

    #2
    Hello i2w8am9ii2,

    Thanks for your post.

    You will want to create a class level bool variable that you set to true when the button is clicked. Example: private bool buttonIsClicked = false;

    You already have a private method for detecting when the button is clicked so this (below) is where you would set the bool to be true.

    private void MyDrawButtons1_Click(object sender, RoutedEventArgs rea)
    {
    System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
    if (button != null)
    Print(button.Name + " Clicked");
    buttonIsClicked = true;
    }


    In the OnBarUpdate() you would replace if ((myDrawButtons1.Click += true)) with an if statement that checks if the bool you created is now true: if (buttonIsClicked)
    At the end of the Draw statements, I would suggest setting the bool to be false.

    If you would like another example of working with buttons or plan to add more buttons, I would suggest downloading this from NT user apps: https://ninjatraderecosystem.com/use...bar-buttons-2/ Please note: The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thanks so much for taking your time to look through my code and to provide me with info and code.

      I added the code and am now down to just one last NinjaScript error, which is Code: CSO103 "The name 'buttonIsClicked' does not exist in the current content". This is on line 135.

      Attached are two screenshots and an updated version of my indicator .cs file.

      Please let me know how to resolve this error.

      Thanks again,

      i2w8am9ii2
      Attached Files

      Comment


        #4
        Hello i2w8am9ii2,

        Thanks for your reply.

        The error message is advising that in the OnBarUpdate() it does not know what buttonIsClicked is. You must declare all variables before you use them. In my previous reply I advised:
        "You will want to create a class level bool variable that you set to true when the button is clicked. Example: private bool buttonIsClicked = false;"

        In your code where you have private RSI RSI1; which is at the (Public) class level which means you can use RSI1 in any method in the class DrawHorizontalLines2. Likewise you would declare private bool buttonIsClicked = false; in the same area. By declaring at the class level you can use the bool in the method private void MyDrawButtons1_Clic as well as the method OnBarUpdate().

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          I just discovered my mistake when I looked through the file you said I could download from NT user apps for another example of adding buttons.

          I now no longer have any NinjaScript error messages.

          Thanks so much for your help. It is very much appreciated.

          i2w8am9ii2

          Comment


            #6
            Paul,

            I no longer have any NinjaScript error messages, but the indicator is not drawing any horizontal lines when I click the button in Replay mode.

            Attached is a screenshot highlighting the changes I made in the code.

            Attached also is the .cs file of the latest version of my indicator.

            Any help would be greatly appreciated.

            i2w8am9ii2
            Attached Files

            Comment


              #7
              Hello i2w8am9ii2,

              Thanks for your reply.

              I would suggest looking at what price level you are drawing the line at, looks like zero to me.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hi Paul,

                Thanks for your feedback.

                I first tried changing it to 100, but still no lines were drawn (I also checked the Drawing Objects window), then I tried changing it to 3180 (for the E-mini S&P) but still no lines were drawn (again I checked the Drawing Objects window afterwards, but it was empty).

                Screenshots attached.

                Thanks for your time,

                i2w8am9ii2
                Attached Files

                Comment


                  #9
                  Hello i2w8am9ii2,

                  Thanks for your reply.

                  You may have to wait a few moments for the lines to draw.

                  If you do not see them, please check the "log" tab of the control center for any error messages related to the indicator.

                  If no error messages then i would suggest debugging your code with print statements, i would place one inside where you have the draw statements just so you can see that the bool has become true (as evidenced by the print statement printing something in the output window). This would help you to see if the bool statement ever becomes true after you have clicked the button. Here is a link to the debugging tips of the help guide: https://ninjatrader.com/support/help...script_cod.htm
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Paul,

                    Thanks for the info.

                    I will try it out.

                    i2w8am9ii2

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jackiegils, Yesterday, 11:05 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post jackiegils  
                    Started by cre8able, 05-09-2024, 09:15 PM
                    2 responses
                    17 views
                    0 likes
                    Last Post cre8able  
                    Started by Trader146, Yesterday, 09:17 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post Trader146  
                    Started by ttrader23, 05-08-2024, 09:04 AM
                    9 responses
                    43 views
                    0 likes
                    Last Post ttrader23  
                    Started by ZeroKuhl, 05-09-2024, 04:31 PM
                    8 responses
                    46 views
                    0 likes
                    Last Post ZeroKuhl  
                    Working...
                    X