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 rbeckmann05, Yesterday, 06:48 PM
      1 response
      12 views
      0 likes
      Last Post bltdavid  
      Started by llanqui, Today, 03:53 AM
      0 responses
      6 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by burtoninlondon, Today, 12:38 AM
      0 responses
      10 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      15 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Working...
      X