Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change variable values by pressing certain keys on keyboard.

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

    Change variable values by pressing certain keys on keyboard.

    Hi,

    I am trying to modify some values by pressing certain keys on the keyboard and tried this:


    static double line_value;

    public void OnKeyDown(object sender, KeyEventArgs e)
    {
    if (e.Key == Key.LeftShift)
    line_value = 5000;
    if (e.Key == Key.RightShift)
    line_value = 5010;

    }



    protected override void OnBarUpdate()
    {
    if (State == State.Historical)
    line_value = Close[0];
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 20, Bold = false };
    Draw.Text(this, "myTag", false, line_value.ToString("0.0"), -270, line_value, 2, Brushes.Black, myFont, TextAlignment.Center, null, null, 1);
    Draw.Line(this, "myTag" + 1, false, CurrentBar, line_value, -210, line_value, Brushes.Black, DashStyleHelper.Solid, 1, true);


    }​


    The initial values were correct, and the text and the line were drawn correctly, but when I pressed left or right Shift keys, nothing had changed,
    wonder what I did wrong.

    I tried using letters, but every time I pressed a letter key, a small window pop up, asked to enter a Stock symbol.

    Also, I am wondering if NinjaTrader could recommend any resources and sample codes related to interactions between keyboard hits or mouse clicks
    and variable values in my script? I have watched quite a few videos and bought a e-book about NinjaScript, all of them are about strategy coding, not
    really I was looking for.

    Thanks so much!!
    Last edited by warpinator; 04-02-2024, 03:48 PM.

    #2
    Hello warpinator,

    Thank you for your post.

    Creating custom keyboard shortcuts starts to go outside of the scope of support that the NinjaScript team can offer; it relies heavily on general C# concepts and goes outside of the supported HotKey functions that are already built into the platform. With that said, I suggest checking out the examples mentioned in the following post; you can use a text box to prevent the instrument selector from popping up when you type a letter:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Hi Emily,

      Thanks so much for your reply.

      So I replaced OnKeyDown() with:

      public override void OnMouseDown(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor dataPoint)
      {
      if (chartScale.GetValueByY() > Close[0])
      line_value = 5000;
      if (chartScale.GetValueByY() < Close[0])
      line_value = 5010;


      }​

      And I got error messages:
      no suitable method found to override
      There is no argument given that corresponds to the required parameter "Y" of ChartScale.GetValueByY()

      Not sure what I did wrong.

      Thanks so much!!

      Comment


        #4
        I found an old post regarding this matter:
        I created a fresh indicator, and I am trying to add the overloaded OnMouseDown() method. My objective is to capture the event when the mouse button is pressed. I am using the below link from the NinjaTrader Language Reference. https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?onmousedown.htm When


        I really hope that there's a way for me to interact with my indicators, so the values of some variables can be changed quickly.

        It seems that is not doable with mouse clicks or keyboard hits, is it possible I could have some buttons I can click and change the values of some variables in the indicator?

        Thanks so much

        Comment


          #5
          Originally posted by warpinator View Post
          I found an old post regarding this matter:
          I created a fresh indicator, and I am trying to add the overloaded OnMouseDown() method. My objective is to capture the event when the mouse button is pressed. I am using the below link from the NinjaTrader Language Reference. https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?onmousedown.htm When


          I really hope that there's a way for me to interact with my indicators, so the values of some variables can be changed quickly.

          It seems that is not doable with mouse clicks or keyboard hits, is it possible I could have some buttons I can click and change the values of some variables in the indicator?

          Thanks so much
          It is certainly possible that buttons could better suit your needs to get your desired behavior. We have a reference sample that demonstrates adding different buttons in the chart toolbar and in the Chart Trader. You could take these ideas to add buttons that toggle/change the values of different parameters:


          Thank you for using NinjaTrader.

          Comment


            #6
            Thanks Emily,

            Unfortunately I am not a professional programmer, this is beyond my ability, I am wondering if Ninja Trader could recommend any programmers that charge a fee to build custom indicators?

            Thanks so much!!
            Last edited by warpinator; 04-03-2024, 08:28 PM.

            Comment


              #7
              Originally posted by warpinator View Post
              Thanks Emily,

              Unfortunately I am not a professional programmer, this is beyond my ability, I am wondering if Ninja Trader could recommend any programmers that charge a fee to build custom indicators?

              Thanks so much!!
              Hello warpinator,

              Thank you for your post.

              You can search our list of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

              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 companies and services 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.

              Let me know if I may be of further assistance.

              Comment


                #8
                Hi Patrick,

                Thanks for your reply, great resources !!

                Just a quick question about forum etiquette, I have some questions regarding a few of old posts (2017 - 2020), should I start a new topic, or it is OK to reply to those old posts.

                Thanks so much

                Comment


                  #9
                  Originally posted by warpinator View Post
                  Hi Patrick,

                  Thanks for your reply, great resources !!

                  Just a quick question about forum etiquette, I have some questions regarding a few of old posts (2017 - 2020), should I start a new topic, or it is OK to reply to those old posts.

                  Thanks so much
                  Hello warpinator,

                  Thank you for your reply.

                  That is a great question! If you reply to an older thread our team will see it, however it is typically better to start a new topic and include a link to the other threads you are asking about in your post. That way we can get the context you are referring to, but then the new thread is addressed in the most accurate and timely manner without getting too many wires crossed from the older thread.

                  I hope this helps to address your question. Please feel free to reach out with any additional NinjaTrader items we may assist you with!

                  Comment

                  Latest Posts

                  Collapse

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