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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X