Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I can't get the correct swing highs past a certain point

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

    I can't get the correct swing highs past a certain point

    I have a method that uses the swing indicator to get the values of previous swing highs. It's working fine for the first few instances, then begins to output incorrect values the further back that I look. The strength of the swing indicator is set to 10 and I'm trying to get 15 instances.

    This is my code:

    private void GetSwings() {
    if(mySwing.SwingHigh[0] > 0) // check for valid swing high
    {
    for(int i = 1; i <= 15; i++)
    {
    if(mySwing.SwingHighBar(0, i, CurrentBar) > -1) // check for valid swing high bar
    {
    myswingHighBarsAgo = mySwing.SwingHighBar(0, i, CurrentBar);
    Print(Time[myswingHighBarsAgo]+" Instance # "+i+" bars ago: "+myswingHighBarsAgo+" High was: "+High[myswingHighBarsAgo]);
    Dot highDot = Draw.Dot(this, "dotHigh"+i, true, Time[myswingHighBarsAgo], High[myswingHighBarsAgo] + 6 * TickSize, Brushes.DodgerBlue);
    highDot.OutlineBrush = Brushes.DodgerBlue;
    }
    }
    }
    }

    The attached photo shows the blue dots become misaligned on the older instances.

    Click image for larger version

Name:	swings.png
Views:	155
Size:	67.3 KB
ID:	1177247

    #2
    Hi jableshank, thanks for posting.

    Did you use Prints in your script to confirm the data is being offset in some way? It will be important to use the Print method to debug and print data coming from the script to explain the output.



    The Swing indicator can re-draw its high and low values as the data is processed, so what is likely happening is the swing value is the same as the dot but as more data is processed the prior swing is changed and your dot is not changed. Try debugging by printing each value of swing high and low of each bar as notice if the values are changing. Another way to test is to use the Playback connection and see what happens on real time data vs the historical data.



    Best regards,
    -ChrisL

    Comment


      #3
      Click image for larger version

Name:	chart.png
Views:	111
Size:	72.3 KB
ID:	1177295Hey Chris, thanks for the reply. This is what I get in the output window. All of the times and price levels match the dots but only match with a portion of the swings on the chart. How would I go about confirming the data is being offset in some way?

      Click image for larger version  Name:	output.png Views:	0 Size:	45.3 KB ID:	1177294

      Comment


        #4
        Hello jableshank , thanks for your reply.

        Note these swing values and bar timestamps and play this same data back on the playback connection. Do you see the swing highs and low lines changing as new data is added? The swing indicator source code is also available to study through the NinjaScript editor and you can see how it looks back on bars to calculate the swing high and low and how this can change as new data is added.

        Best regards,
        -ChrisL

        Comment


          #5
          Thanks Chris, I'll check out the source code for sure.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X