Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving on chart with Home and End keys don't fire a plot event?

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

    Moving on chart with Home and End keys don't fire a plot event?

    I just wrote a Plot() method for my indicator and to keep the CPU workload down, I am only displaying my diamonds on bars that are displayed on the chart. It's quite simple, just using DrawDiamond() and checking if the bar is between First and Last painted.

    However I just realised that when I'm not connected to the data provider with incoming ticks, my Plot() isn't invoked after I hit either the Home or the End keys to move to the left or the right hand end of the data.

    I have to click the chart to trigger the repaint.

    Is this normal? Can I put an event in my code to catch these keys and trigger the repaint myself - presumably via ChartControl.Invalidate(), or is there some other stuff going on that I need to be aware of?

    Thanks.

    #2
    If there are no incoming ticks, the plot method would not be called until you interact with the chart. I'm not quite sure how you were calling Plot prior to hitting home and end, but what you describe is expected behavior if you're not connected.

    If you need to force the Plot method to be called, you can use ChartControl.Invalidate()
    MatthewNinjaTrader Product Management

    Comment


      #3
      I override the Plot() method with my simple routine so that I can use a menu button to fire off an event which tells the indicator to stop plotting, without disturbing the process and without requiring another OnBarUpdate to come along.

      But that is not really relevant, as you say you wouldn't expect ninja to call Plot after hitting Home or End anyway.

      So how can I tie in an event to pick up the Home or End key press so I can call ChartControl.Invalidate(), because that's the only way then that I'll be able to force it.

      I guess I can google it but since I've got your attention, are there any examples in the forum indicator share folder?

      Comment


        #4
        To clarify, hitting Home/End should force the plot to update during that time, but you'd need to somehow interact the chart (by clicking on it, etc) to get the plot to fire again.

        The only example I can think of us perhaps using the methods in the BarTimer indicator to create a custom timer which calls ChartControl.Invalidate() at a certain interval.

        If you find yourself only in this situation after hitting home/end, you can perhaps create a bool on KeyPressEvent which then would turn on your custom trigger event:

        MatthewNinjaTrader Product Management

        Comment


          #5
          I coded up the following which I thought must be relatively simple, but I'm just not catching the event:

          Code:
              protected override void OnStartUp()
              {
                  if (ChartControl != null && ChartControl.ChartPanel != null)
                      ChartControl.ChartPanel.KeyPress += new KeyPressEventHandler(keyPressEventHandler);
              }
              private void keyPressEventHandler(object sender, KeyPressEventArgs ex)
              {
                  Print("Key pressed: " + ex.KeyChar);
                  switch(ex.KeyChar)
                  {
                      case (char) Keys.Home:
                          ChartControl.Invalidate();
                          break;
                      case (char) Keys.End:
                          ChartControl.Invalidate();
                          break;
                      default:
                          break;
                  }
                  //ex.Handled = true;
               }
          What is going wrong? I've also tried attaching the event direct to ChartControl.KeyPress

          Comment


            #6
            Adamus,

            This is because the form itself is eating up the KeyEvent.

            I have attached a sample that should get you working, however, the home key will call the KeyEvent but the chart will still use the home function for the chart.

            Additionally, try using ChartControl.Refresh();
            Attached Files
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              That does it nicely. Seems like I was on the wrong path with KeyPressEvent and KeyPress as well - KeyEvent and KeyDown is the way to go. Thanks.

              Comment


                #8
                Just for the record

                Actually even more key here (sorry for the pun) is ChartControl.Refresh() rather than ChartControl.Invalidate() which doesn't necessarily always work - as you suggested.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by bmartz, 03-12-2024, 06:12 AM
                4 responses
                32 views
                0 likes
                Last Post bmartz
                by bmartz
                 
                Started by Aviram Y, Today, 05:29 AM
                4 responses
                12 views
                0 likes
                Last Post Aviram Y  
                Started by algospoke, 04-17-2024, 06:40 PM
                3 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by gentlebenthebear, Today, 01:30 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by cls71, Today, 04:45 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X