Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Started by realblubb, Today, 09:28 AM
      0 responses
      2 views
      0 likes
      Last Post realblubb  
      Started by AaronKoRn, Yesterday, 09:49 PM
      1 response
      18 views
      0 likes
      Last Post Rikazkhan007  
      Started by ageeholdings, Today, 07:43 AM
      0 responses
      12 views
      0 likes
      Last Post ageeholdings  
      Started by pibrew, Today, 06:37 AM
      0 responses
      4 views
      0 likes
      Last Post pibrew
      by pibrew
       
      Working...
      X