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 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
          20 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          29 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          46 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          38 views
          0 likes
          Last Post CarlTrading  
          Working...
          X