Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Previous swing

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

    #16
    hello Stanfillirenfro,

    Thanks for your reply.

    Correct, the example is using swing in a strategy, sorry I did not clarify this to you.

    If you look at the code, you can duplicate most everything in an indicator except the line AddChartIndicator(mySwing); which only works in a strategy. This function is only add the swing to the chart when the strategy loads, so it is a convienience feature. For your indicator, you would need to add the swing indicator if you wish to see the display.

    Also, to only show the current results add this as the first line in OnBarUpdate():

    if (State != State.Realtime) return;

    That line will skip all of the historical data so the first bar close in real-time will show the swing results of the current swing,

    Comment


      #17
      Hello Paul!

      I have added the swing indicator to the chart.

      I have modified your code as followed, but I do not have any text printed on the output. What could be the problem?


      protected override void OnBarUpdate()
      {


      if (State != State.Realtime)
      return;


      if (CurrentBar <60)
      return;

      if (Swing(5).SwingHigh[0] > 0) // check for valid swing high
      {
      for (int i = 1; i <4; i++)
      {
      if (Swing(5).SwingHighBar(0, i, 30) > -1 ) // check for valid swing high bar
      {
      Print (Time[0]+" Instance # "+i+" bars ago: "+ Swing(5).SwingHighBar(0, i, 30)+ " High was: "+High[Swing(5).SwingHighBar(0, i, 30)]);
      }

      }
      }
      }

      Best regards

      Comment


        #18
        Hello Stanfillirenfro,

        Thanks for your reply.

        You will not see any prints until the first real time bar closes. You may want to test this on a fast chart, just as 10 second bars.

        Comment


          #19
          Hello Paul!
          Many thanks for your reply.
          I have added arrows to see if I could catch the swing properly. With the code, I have arrow on each single bar. Could you please have a look on tne following line and please advice me how to get arrow ONLY on the swing?

          Draw.ArrowDown(this, "tag1"+Swing(5).SwingHighBar, true, 0, High[Swing(5).SwingHighBar] + Brushes.Red);

          Best regards

          Comment


            #20
            Hello Stanfillirenfro,

            Thanks for your reply.

            You would need to create additional logic to only call the draw method when you want to draw the arrow.

            For example, you could use a bool variable that you create and declare and then set true when to draw the arrow:

            if (your condition to draw the arrow && drawNow)
            {
            Draw.ArrowDown(.....
            drawNow = false; // set the bool false to prevent draing further arrows
            }

            Comment


              #21
              Hello Paul!
              Thanks foryour reply!
              I have to think this strategy otherwise. I am not having what I want.
              Many thanks for your help!

              Best regards

              Comment


                #22
                Hello Stanfillirenfro,

                Thanks for your reply.

                I had some time to work on a further sample that may be helpful for you to build from.

                Here is a short video on it: https://Paul-ninjaTrader.tinytake.co...MV8xNjA3MjUwNA

                I have attached the complete code below.

                Please note that we typically do not provide complete examples so this is an exception. You would need to copy/modify to suit your needs.

                SwingLatestTest.zip

                Comment


                  #23
                  Hello Paul!
                  Great!!!
                  Many thanks for the help. It is exactly what I wanted. Many thanks for the exception. Your code is a strong starting point for me. Valuable video and explanation too.
                  Very helpful. I will continue to learn.
                  Many thanks again!

                  Best regards,

                  Comment


                    #24
                    Thanks Paul,

                    This is also exactly what I was looking for.

                    Comment


                      #25
                      What if I need to print an alert showing the prev day swing high and low? But it needs to stay there and doesn't disappear.
                      Is that possible? Maybe something printed on the screen.

                      Comment


                        #26
                        Hello calster,

                        Do you mean you are adding a 1 day series and supplying this as the input series to the swing indicator?

                        Yes, you can call Draw.Text() or Draw.TextFixed to write the text on the chart.

                        Note, if the script is removed, the drawing objects would also be removed.

                        You could also choose to add the information to a TextBlock in a custom addon popup window.
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        576 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        334 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        101 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        553 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        551 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X