Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw a dot on click

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

    Draw a dot on click

    Hello
    I'm trying to draw a diamond on the clicked candle but I get the following error message: Unhandled exception: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

    My code :
    Code:
    protected void MouseClicked(object sender, MouseButtonEventArgs e)
            {
                clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.GetPosition(ChartControl as IInputElement).X, ChartControl.PresentationSource);
                clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPosition(ChartControl as IInputElement).Y, ChartControl.PresentationSource);
                convertedPrice    = Instrument.MasterInstrument.RoundToTickSize(chartScale.GetValueByY((float)clickPoint.Y));
                convertedTime    = ChartControl.GetTimeBySlotIndex((int)ChartControl.GetSlotIndexByX((int)clickPoint.X));
    
    
                int iTemp = ChartBars.GetBarIdxByTime(ChartControl, convertedTime);
                Print(iTemp+"   "+convertedTime.ToString());
    
                Draw.Diamond(this, "tag1", true, iTemp, Low[iTemp] - TickSize, Brushes.Red);
                ForceRefresh();
            }​
    How to solve my negative index problem when I check visually on the chart and it's correct, it corresponds to the debug display?
    Thanks for your explanations.​

    Edit : I'd like to point out that whatever the index, if it's different from 0 and doesn't come from iTemp but is hard-coded, I get this error.

    #2
    Hello bicou,

    You will need to use TriggerCustomEvent() to synchronize the series to the current index before drawing an object from a non-data-driven thread (or doing anything that relates to a series).
    https://ninjatrader.com/support/help...ustomevent.htm

    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thank you for your reply, I'll go and read it all

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      43 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      25 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      163 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      158 views
      2 likes
      Last Post CaptainJack  
      Working...
      X