Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator to draw lines relative to mouse selection of two bar points

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

    Indicator to draw lines relative to mouse selection of two bar points

    Hi
    I would like to make an indicator where one can select two bars on a chart. Then draw a line whose length and position are based on the time and price of the two bar points.

    e.g. on chart select bar A low and bar B high - we have available time (or bar number) and Price for Bar A and Bar B. Then draw a line which is mid point between Bar A and Bar B in Time and Price to Bar B time and price.

    How to access the mouse click data for price and time for the selected points and how to reference the bar time and open or close price to be able to calculate line start and end points and then plot the line?

    thanks
    Suraj

    #2
    Hi Suraj,

    Here is a snippet I use in my indicators to draw extended lines on preselected bars. It uses a mouse down event to get the data for 2 picks of the mouse. Then a button click event to do the drawing of the extended lines. You can get OHLC values from the bar1 and bar2 or any manipulation such as midpoint using math . Hope this helps. The rest you should be able to figure out.

    Code:
    private void AIMouseDownEvent(object sender, MouseButtonEventArgs e)
    {
    TriggerCustomEvent(o =>
    {
    if (ChartControl != null)
    {
    if (e.ChangedButton.ToString().ToLower().Contains("left"))
    {
    if (mouse1picked == false)
    {
    mousepoint1 = ChartControl.MouseDownPoint.X.ConvertToHorizontalP ixels(ChartControl.PresentationSource);
    int barnum1 = ChartBars.GetBarIdxByX(ChartControl, mousepoint1);
    DateTime hightime = ChartBars.GetTimeByBarIdx(ChartControl, barnum1);
    datepickedhigh = RoundUpToNearest(hightime, TimeSpan.FromMinutes(1));
    mouse1picked = true;
    pickedhighprice = BarsArray[0].GetHigh(barnum1);
    
    }
    else
    {
    mousepoint2 = ChartControl.MouseDownPoint.X.ConvertToHorizontalP ixels(ChartControl.PresentationSource);
    int barnum2 = ChartBars.GetBarIdxByX(ChartControl, mousepoint2);
    DateTime lowtime = ChartBars.GetTimeByBarIdx(ChartControl, barnum2);
    datepickedlow = RoundUpToNearest(lowtime, TimeSpan.FromMinutes(1));
    mouse1picked = false;
    pickedlowprice = BarsArray[0].GetLow(barnum2);
    }
    }
    }
    }, null);
    }
    Tom
    Intelligent Trader Inc.
    NinjaTrader Ecosystem Vendor - Artificial Intelligence Based Indicators

    Comment


      #3
      Hi Tom,

      thanks for the info - I will work through this, it will give me a good start in understanding how to make the indicator.
      Do you have a web link to your AI indicator site?

      Thanks,
      Suraj

      Comment


        #4
        Hi Suraj,

        You are welcome. I am not sure of the rules of posting external links. But if you click on my vendor signature it will take you to our site.

        Tom
        Intelligent Trader Inc.
        NinjaTrader Ecosystem Vendor - Artificial Intelligence Based Indicators

        Comment


          #5
          Thanks Tom, got it.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          110 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          59 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          37 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          41 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          78 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X