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

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:	133
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
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Click image for larger version

Name:	chart.png
Views:	86
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
        Chris L.NinjaTrader Customer Service

        Comment


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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by FrancisMorro, Today, 03:24 AM
          0 responses
          1 view
          0 likes
          Last Post FrancisMorro  
          Started by Segwin, 05-07-2018, 02:15 PM
          10 responses
          1,769 views
          0 likes
          Last Post Leafcutter  
          Started by Rapine Heihei, 04-23-2024, 07:51 PM
          2 responses
          30 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by Shansen, 08-30-2019, 10:18 PM
          24 responses
          943 views
          0 likes
          Last Post spwizard  
          Started by Max238, Today, 01:28 AM
          0 responses
          10 views
          0 likes
          Last Post Max238
          by Max238
           
          Working...
          X