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

Swing vs Low[Math.Min] not as expected

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

    Swing vs Low[Math.Min] not as expected

    Hi, am trying to get the values for the last 3 x swing highs and swing lows using the swing indicator, and the output for the swing low give the same value for 1,2 and 3 ? is the code below valid ? many thanks for looking

    Code:
                    Print("0 1 The high of the swing bar "+Swing(5).SwingHighBar(0, 1, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 128))] );
                    Print("0 2 The high of the swing bar "+Swing(5).SwingHighBar(0, 2, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 2, 128))] );
                    Print("0 3 The high of the swing bar "+Swing(5).SwingHighBar(0, 3, 128)+" is " +High[Math.Max(0, Swing(5).SwingHighBar(0, 3, 128))] );
    
                    Print("0 1 The low of the swing bar "+Swing(5).SwingLowBar(0, 1, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 1, 128))] );
                    Print("0 2 The low of the swing bar "+Swing(5).SwingLowBar(0, 2, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 2, 128))] );
                    Print("0 3 The low of the swing bar "+Swing(5).SwingLowBar(0, 3, 128)+" is " +Low[Math.Min(0, Swing(5).SwingLowBar(0, 3, 128))] );

    #2
    Ah, should be Math.Max for a Low also .. ok, my bad .. ?!!!!

    Comment


      #3
      Hello 12tkram, thanks for your post.

      The code you posted works fine for me. I made a test that draws a dot 3 swing highs. Please see attached. To add it to your system, place the file within Documents\NinjaTrader 8\bin\Custom\Indicators.

      Let me know if it is not working after reviewing this, kind regards.
      Attached Files
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        that code works ? for me all the values for the swing lows were exactly the same, i switched it over to Math.Max and it seemed to work ok .. I will check out your code and mine is still a bit weird to be honest .. thanks for your feedback ..

        Comment


          #5
          oh, ok, yeh, yours is for the swing highs, mine works fine for the swing highs, it was the swing lows that were the issue.

          Comment


            #6
            Hi,

            I revised my OnBarUpdate method and this is working for me:

            protected override void OnBarUpdate()
            {
            //Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)
            if(CurrentBar < 128)
            return;

            Draw.Dot(this, "swing1", false, Swing(5).SwingHighBar(0, 1, 128), High[Swing(5).SwingHighBar(0, 1, 128)], Brushes.Red);
            Draw.Dot(this, "swing2", false, Swing(5).SwingHighBar(0, 2, 128), High[Swing(5).SwingHighBar(0, 2, 128)], Brushes.Red);
            Draw.Dot(this, "swing3", false, Swing(5).SwingHighBar(0, 3, 128), High[Swing(5).SwingHighBar(0, 3, 128)], Brushes.Red);

            Draw.Dot(this, "swingLow1", false, Swing(5).SwingLowBar(0, 1, 128), Low[Swing(5).SwingLowBar(0, 1, 128)], Brushes.Green);
            Draw.Dot(this, "swingLow2", false, Swing(5).SwingLowBar(0, 2, 128), Low[Swing(5).SwingLowBar(0, 2, 128)], Brushes.Green);
            Draw.Dot(this, "swingLow3", false, Swing(5).SwingLowBar(0, 3, 128), Low[Swing(5).SwingLowBar(0, 3, 128)], Brushes.Green);
            }

            If you don't get the same thing on your side please let me know.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              12tkram,

              I wanted to add that your swing indicator should be set up at the class level to save resources.

              e.g.

              Code:
              public class TestSwing : Indicator
                  {
              
                      Swing MySwing;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"Enter the description for your new custom Indicator here.";
                              Name                                        = "TestSwing";
                              Calculate                                    = Calculate.OnBarClose;
                              IsOverlay                                    = true;
                              DisplayInDataBox                            = true;
                              DrawOnPricePanel                            = true;
                              DrawHorizontalGridLines                        = true;
                              DrawVerticalGridLines                        = true;
                              PaintPriceMarkers                            = true;
                              ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                              //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                              //See Help Guide for additional information.
                              IsSuspendedWhileInactive                    = true;
                          }
                          else if (State == State.Configure)
                          {
                          }
                          else if (State == State.DataLoaded)
                          {
                              MySwing = Swing(5);
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          //Swing(int strength).SwingHighBar(int barsAgo, int instance, int lookBackPeriod)
                          if(CurrentBar < 128)
                              return;
              
                          Draw.Dot(this, "swing1", false, MySwing.SwingHighBar(0, 1, 128), High[MySwing.SwingHighBar(0, 1, 128)], Brushes.Red);
                          Draw.Dot(this, "swing2", false, MySwing.SwingHighBar(0, 2, 128), High[MySwing.SwingHighBar(0, 2, 128)], Brushes.Red);
                          Draw.Dot(this, "swing3", false, MySwing.SwingHighBar(0, 3, 128), High[MySwing.SwingHighBar(0, 3, 128)], Brushes.Red);
              
                          Draw.Dot(this, "swingLow1", false, MySwing.SwingLowBar(0, 1, 128), Low[MySwing.SwingLowBar(0, 1, 128)], Brushes.Green);
                          Draw.Dot(this, "swingLow2", false, MySwing.SwingLowBar(0, 2, 128), Low[MySwing.SwingLowBar(0, 2, 128)], Brushes.Green);
                          Draw.Dot(this, "swingLow3", false, MySwing.SwingLowBar(0, 3, 128), Low[MySwing.SwingLowBar(0, 3, 128)], Brushes.Green);
                      }
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                thanks, that looks a lot neater than mine .. I will update my code .. many thanks again for the hints/tips

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                59 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Today, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Started by olisav57, Today, 07:39 PM
                0 responses
                7 views
                0 likes
                Last Post olisav57  
                Started by trilliantrader, Today, 03:01 PM
                2 responses
                21 views
                0 likes
                Last Post helpwanted  
                Started by cre8able, Today, 07:24 PM
                0 responses
                10 views
                0 likes
                Last Post cre8able  
                Working...
                X