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

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.
    Emily C.NinjaTrader Customer Service

    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.
          Emily C.NinjaTrader Customer Service

          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!
                  Emily C.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Chippy, 04-29-2022, 11:47 AM
                  2 responses
                  150 views
                  0 likes
                  Last Post mauroqenk  
                  Started by sukhob, Today, 01:10 PM
                  1 response
                  13 views
                  0 likes
                  Last Post bltdavid  
                  Started by llanqui, 11-29-2023, 07:15 AM
                  3 responses
                  99 views
                  0 likes
                  Last Post lunardiplomacy  
                  Started by ZenCortexNow, Today, 01:28 PM
                  0 responses
                  15 views
                  0 likes
                  Last Post ZenCortexNow  
                  Started by MatthewLesko, 12-10-2021, 10:24 AM
                  51 responses
                  6,192 views
                  0 likes
                  Last Post brenthilburn  
                  Working...
                  X