Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Region: Mistake or just redundant?

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

    Draw.Region: Mistake or just redundant?

    I was having some issues with Draw.Region, so decided to write a new class based off of copying its code.

    I notice this section in the code, that leaves me a bit confused.
    Code:
    				// cap it end->start
    				points[pointIdx].X = chartControl.GetXByBarIndex(chartBars, endIdx + Displacement);
    				points[[COLOR="red"]pointIdx++[/COLOR]].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));
    
    				points[[COLOR="red"]pointIdx[/COLOR]].X = chartControl.GetXByBarIndex(chartBars, startIdx + Displacement);
    				points[pointIdx++].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));
    (emphasis mine)

    Notice that the third line of code merely replaces the self-same points[pointIdx] calculated off of endIdx, with one calculated off of startIdx; and the fourth line of code is an exact duplicate of the second line of code. It seems strange to be immediately replacing code that has not been used, then writing the exact same code for another quantity that has not been used either.

    Did you intend to write,
    Code:
    				// cap it end->start
    				points[pointIdx].X = chartControl.GetXByBarIndex(chartBars, endIdx + Displacement);
    				points[[COLOR="Red"]pointIdx[/COLOR]].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));
    
    				points[[COLOR="red"]pointIdx++[/COLOR]].X = chartControl.GetXByBarIndex(chartBars, startIdx + Displacement);
    				points[pointIdx++].Y = chartScale.GetYByValue(Math.Max(chartScale.MinValue, Math.Min(chartScale.MaxValue, Price)));
    or am I off my rocker?

    #2
    I believe the key may be with the timing of the increments to pointIdx. Here is the progression that I see in the existing code. We'll assume that pointIdx begins with a value of 1:

    1) Change X on index 1
    2) Change Y on index 1, then increment pointIdx to 2
    3) Change X on index 2
    4) Change Y on index 2, then increment pointIdx to 3
    5) Rinse/Repeat

    In your suggestion, I believe the flow would work as follows:

    1) Change X on index 1
    2) Change Y on index 1
    3) Change X again on index 1, then increment pointIdx to 2
    4) Change Y on index 2, then increment pointIdx to 3

    Does that provide a bit more clarity, or point you in the right direction?
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Dave View Post
      I believe the key may be with the timing of the increments to pointIdx. Here is the progression that I see in the existing code. We'll assume that pointIdx begins with a value of 1:

      1) Change X on index 1
      2) Change Y on index 1, then increment pointIdx to 2
      3) Change X on index 2
      4) Change Y on index 2, then increment pointIdx to 3
      5) Rinse/Repeat

      In your suggestion, I believe the flow would work as follows:

      1) Change X on index 1
      2) Change Y on index 1
      3) Change X again on index 1, then increment pointIdx to 2
      4) Change Y on index 2, then increment pointIdx to 3

      Does that provide a bit more clarity, or point you in the right direction?
      Thanks. I was off my rocker. I have been looking at code too long!

      I looked at that incrementer multiple times, and still did not make the connection that it was assigning, then incrementing: a construct that I have myself used multiple times. I shall turn off the code window for a few days, until I start seeing clearly again.

      Thanks for your time.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,281 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      19 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by Tim-c, Today, 02:10 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Taddypole, Today, 02:47 PM
      0 responses
      5 views
      0 likes
      Last Post Taddypole  
      Started by chbruno, 04-24-2024, 04:10 PM
      4 responses
      53 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Working...
      X