Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnRender/Update Y Scaling during mouse dragging

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

    OnRender/Update Y Scaling during mouse dragging

    This relates to an older post by someone else



    but is it possible to have NT8 refresh/OnRender while the user clicks + drags instead of after the user unclicks?

    I am trying to implement vertical scroll without having to use the CTRL button like I am able in NT7. MessageBox's do appear before I unclick so the code does keep running on the MouseMove event but the chart is stagnant. I have even tried ForceRefresh but to no avail.

    Thank you.

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    chartControl.MouseMove += new System.Windows.Input.MouseEventHandler((sender,e) => mouse_drag(sender,e,chartScale));
    }

    void mouse_drag(object sender, System.Windows.Input.MouseEventArgs e,ChartScale chartScale)
    {

    if (e.LeftButton == MouseButtonState.Pressed)
    {

    chartScale.Properties.FixedScaleMax = chartScale.Properties.FixedScaleMax + .005;
    OnRender(ChartControl, chartScale);

    }

    }

    #2
    Hello gummysergeant101,

    Thank you for writing in. I am currently running this by our product management team and I will update this post as soon as I have more information. Please note, our normal operating hours are between 8:30AM EST and 6:00PM EST Monday through Friday.

    Thank you for your continued patience in the meantime.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      thank you for the reply!

      Thank you Michael! Hope to hear from you and your team soon.

      Comment


        #4
        Hello gummysergeant101,

        I believe I was able to get this working with the following code:
        Code:
        public class MouseMoveTriggerRenderExample : Indicator
            {
                private bool mouseClicked = false;
                private Point? currentMouse;
                private double amountToChange = 0.0;
                protected override void OnStateChange()
                {
                    if (State == State.SetDefaults)
                    {
                        Description                         = @"";
                        Name                                = "MouseMoveTriggerRenderExample";
                        Calculate                           = Calculate.OnBarClose;
                        IsOverlay                           = true;
                        DisplayInDataBox                    = true;
                        DrawOnPricePanel                    = true;
                        DrawHorizontalGridLines             = true;
                        DrawVerticalGridLines               = true;
                        PaintPriceMarkers                   = true;
                        ScaleJustification                  = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                        IsSuspendedWhileInactive            = true;            
                    }
                    else if (State == State.Historical)
                    {
                        ChartControl.PreviewMouseDown += mouse_down;
                        ChartControl.PreviewMouseMove += mouse_move;
                    }
                }
                protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                {
                    if(currentMouse.HasValue){
                        amountToChange = (ChartControl.MouseDownPoint.Y - currentMouse.Value.Y) * .005;
                        chartScale.Properties.FixedScaleMax = chartScale.Properties.FixedScaleMax + amountToChange;
                    }
                }
                public void mouse_down(object sender, System.Windows.Input.MouseEventArgs e)
                {
                    mouseClicked = (mouseClicked) ? false : true;
                }
                public void mouse_move(object sender, System.Windows.Input.MouseEventArgs e)
                {
                    if (mouseClicked)
                    {
                        currentMouse = new Point(e.GetPosition(ChartPanel as IInputElement).X, e.GetPosition(ChartPanel as IInputElement).Y);
                        ForceRefresh();
                    }
                    else if(!mouseClicked && currentMouse.HasValue)
                        currentMouse = null;
                }
            }
        Please let me know if I am missing anything or if I may be of further assistance.
        Michael M.NinjaTrader Quality Assurance

        Comment


          #5
          still didn't fire

          I tried your code and still nothing. Added a messagebox and it does fire but ForceRefresh doesn't seem to be running OnRender. I'm thinking it needs chartScale as a parameter? I will investigate more tomorrow morning!

          Thank you again!

          Comment


            #6
            Hello gummysergeant101,

            Please try the following steps:
            1) Open a new chart
            2) You need to set the chart into a fixed scale so click and drag up or down in the y-axis until you see the little "F" icon in the upper right hand corner
            3) Add the indicator you made from the code I sent
            4) Click and drag up and down in the chart
            5) Verify that OnRender is getting called correctly

            Please let me know if you have any questions or if I may be of further assistance.
            Michael M.NinjaTrader Quality Assurance

            Comment


              #7
              That works!

              I can post the refined code for future use by other traders but I can't add System.Drawing or System.Windows.Point in order to retrieve the mouse position within OnRender. So close!

              Comment


                #8
                Hello gummysergeant101,

                I have attached the full code to my response which you can import into NinjaTrader. This code makes the current mouse position available in OnRender.

                If you require further assistance, please email your code to platformsupport[AT]ninjatrader[DOT]com with the subject line: "ATTN: Michael M http://www.ninjatrader.com/support/forum/showthread.php?t=79334".

                Thank you in advance!
                Attached Files
                Michael M.NinjaTrader Quality Assurance

                Comment


                  #9
                  Thank you for all of your help Michael! I took your code and modified it slightly and now it works just like using the CTRL key minus a little smoothness.

                  public class MyCustomIndicator4 : Indicator
                  {
                  private bool mouseClicked = false;
                  private Point? currentMouse;
                  public double current1;
                  public double current2;
                  private double amountToChange = 0.0;
                  //int[] numbers = new int[1,2];
                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"";
                  Name = "MyCustomIndicator4";
                  Calculate = Calculate.OnBarClose;
                  IsOverlay = true;
                  DisplayInDataBox = true;
                  DrawOnPricePanel = true;
                  DrawHorizontalGridLines = true;
                  DrawVerticalGridLines = true;
                  PaintPriceMarkers = true;
                  ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                  IsSuspendedWhileInactive = true;
                  }
                  else if (State == State.Historical)
                  {
                  ChartControl.PreviewMouseDown += mouse_down;
                  ChartControl.PreviewMouseMove += mouse_move;
                  }
                  }
                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {

                  //Point? p = Control.MousePosition;
                  if(currentMouse.HasValue & current1>current2){
                  amountToChange = (chartScale.Properties.FixedScaleMax-chartScale.Properties.FixedScaleMin) * .0055;
                  chartScale.Properties.FixedScaleMax = chartScale.Properties.FixedScaleMax + amountToChange;
                  chartScale.Properties.FixedScaleMin = chartScale.Properties.FixedScaleMin + amountToChange;

                  current2 = current1;
                  }

                  if(currentMouse.HasValue & current1<current2){
                  amountToChange = (chartScale.Properties.FixedScaleMax-chartScale.Properties.FixedScaleMin) * .0055;
                  chartScale.Properties.FixedScaleMax = chartScale.Properties.FixedScaleMax - amountToChange;
                  chartScale.Properties.FixedScaleMin = chartScale.Properties.FixedScaleMin - amountToChange;

                  current2 = current1;
                  }


                  }
                  public void mouse_down(object sender, System.Windows.Input.MouseEventArgs e)
                  {
                  mouseClicked = (mouseClicked) ? false : true;
                  }
                  public void mouse_move(object sender, System.Windows.Input.MouseEventArgs e)
                  {
                  if (mouseClicked)
                  {
                  current1 = e.GetPosition(ChartPanel as IInputElement).Y;
                  currentMouse = new Point(e.GetPosition(ChartPanel as IInputElement).X, e.GetPosition(ChartPanel as IInputElement).Y);
                  ForceRefresh();

                  }
                  else if(!mouseClicked && currentMouse.HasValue)
                  currentMouse = null;
                  }
                  }

                  Comment


                    #10
                    Hello gummysergeant101,

                    Thank you for the update. I am glad to hear you were able to resolve the issue!

                    Please let me know if I may be of further assistance anytime.
                    Michael M.NinjaTrader Quality Assurance

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by funk10101, Today, 09:43 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post funk10101  
                    Started by pkefal, 04-11-2024, 07:39 AM
                    11 responses
                    37 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Yesterday, 08:51 AM
                    8 responses
                    44 views
                    0 likes
                    Last Post bill2023  
                    Started by yertle, Today, 08:38 AM
                    6 responses
                    26 views
                    0 likes
                    Last Post ryjoga
                    by ryjoga
                     
                    Started by algospoke, Yesterday, 06:40 PM
                    2 responses
                    24 views
                    0 likes
                    Last Post algospoke  
                    Working...
                    X