Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ChartScale Not returning correct Y Value Price

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

    ChartScale Not returning correct Y Value Price

    Hello!

    Alright so I have a couple of questions, here is a quick summary of the strategy (I am using a strategy because I want to place buttons in the chart trader, will attach example below):

    The object is to be able to input a price and execute logic based on that price. I do not want it to just be an input in the strategy as I would like it to be easy to use.

    I have two ways I tried and two dead ends,

    First one:
    - Placed a text box in the chart trader ("TextboxExample" below)
    - But whenever I go to type this thing shows up ("ThisThingExample" If I can disable this I am golden and fix is done)

    Second one:
    - I put a button where the text box was
    - When clicked into "Edit" mode then it collects the point where I click the screen next
    - Then converts it to a value using the chartscale Function .GetValueByY()
    - It then draws a line at that point and executes logic in the strategy based off of it

    For whatever reason whenever I click (especially near the bottom of the screen) it places the line that I tell it to draw too far up on the chart.
    I printed the values it was converting to and they dont match exactly where my cursor is (close but not quite).
    For what it is worth as well the closer I get to the bottom the more it resists converting close to my point.

    Not sure what it could be let me know if you can help, I have attached pics below and I am pasting how I have coded the conversion as well below.
    Let me know if I need to make a mock to test, Thanks!

    Here is code:

    This is how I save the chartscale (couldn't access in my data collection spot) -
    """
    private NinjaTrader.Gui.Chart.ChartScale charts;
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    charts = chartScale;​
    """
    (Not full code just important bit)

    Here is my function for Mouse Click (I subscribe ChartControl.MouseLeftButtonUp += OnMouseClick) -
    """
    private void OnMouseClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
    Point cursorPoint = ChartControl.MouseDownPoint;
    if(charts != null){
    lvlPrice = charts.GetValueByYWpf((float) cursorPoint.Y);
    Print(charts.GetValueByY((float) cursorPoint.Y));
    }
    }​
    """

    And then I have it draw at lvlPrice
    Attached Files

    #2
    Hello Vikuno1,

    I would suggest taking a look at the script in the following post and how that accesses the mouse location. That uses the mouse moved event but you could also use the click event for the same purpose. That has the correct syntax to convert the WPF mousepoint into valid x/y for NinjaScript.



    Comment


      #3
      I switched to the WPF Version of the method and it fixed. I think is had to do with the ChartScale moving while clicking during playback. Thanks! Will let you know if I run into any other problems

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X