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

How to use swing indicator like filter?

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

    How to use swing indicator like filter?

    Hello everybody.

    I am developing a strategy where, among other conditions, I will only enter a LONG position if the Swing indicator informs me of the existence of a Lower Low and, for a SHORT entry, a Higher High signal.

    I've been studying the indicator references and posts about Swing on the forum, but I still don't understand how to develop this logic to use it as a filter.

    What has been developed so far with the help of the forum is this part of the strategy:

    if (mySwing.SwingHigh[0] > 0)
    {
    for (int i = 1; i < 2; i++)
    {
    if (mySwing.SwingHighBar(0,i,18) > -1)
    {
    mySwingHighBarsAgo = mySwing.SwingHighBar(0, i, 18);
    Print(Time[0]+" Instance # "+i+" bars ago: "+mySwingHighBarsAgo+ " High was: "+High[mySwingHighBarsAgo]);
    }
    }
    }​

    I'm new to C# so I'm at a loss for it. I would greatly appreciate it if such fantastic support could help me.

    Attached is a piece of my strategy.

    Thanks.​
    Attached Files

    #2
    Hello EvergreenGain,

    I see that you are looping through instances of swings, what questions did you have surrounding this logic? Is there an instance of the swing that you wanted to use later in your code or could you explain how you wanted to use this loop in your code?
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,

      I wanted to extract from this loop the information on the existence or not of a Lower Low for a long entry and a Higher High for a Short entry.

      In my thoughts, we could use the Swing indicator results (1 and -1) for example for the respective inputs.

      At the end of the day, what I need is a function that checks for the existence of L/L and H/H to filter the entries.

      In any case, thank you very much for your prompt response.

      This support is amazing!!!

      Carlos Guimarăes​

      Comment


        #4
        Hello EvergreenGain,

        If you wanted to store a value from the loop you would need to make a variable that is outside of the loop and then set that variable while looping.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse,

          I developed the following code to check the existence of a previous Higher/High or a Lower/Low, and based on this information (I used a Boolean variable) I enter Long or Short.

          Excerpt from the logic described above"

          region Swing Filter Logic

          for (int i = 1; i <= 2; i++)
          {

          if (mySwing.SwingLowBar(Strength, i, BarsAgo) > -1)
          {
          countSwingLows++; // Increments the counter if a bearish reversal point is found.
          }
          }

          if (countSwingLows == 2)
          {
          twoSwingsLows = true; // Sets to true if there are two bearish reversal points.
          }
          else
          {
          twoSwingsLows = false; // Set to false otherwise.
          }


          for (int i = 1; i <= 2; i++)
          {

          if (mySwing.SwingHighBar(Strength, i, BarsAgo) > -1)
          {
          countSwingHighs++; // Increments the counter if a bullish reversal point is found.
          }
          }
          if (countSwingHighs == 2)
          {
          twoSwingsHighs = true; // Sets to true if there are two bullish reversal points.
          }
          else
          {
          twoSwingsHighs = false; // Set to false otherwise.
          }
          {

          Print(Time[0]+" Instance # "+i+" HigherHigh?: "+twoSwingsHighs+ " LowerLow?: "+twoSwingsLows);

          // // Prints the high price of the most recent swing high
          // Print("The high of the swing bar is " + High[Math.Max(0, Swing(Strength).SwingHighBar(0, i, 50))]);
          }

          #endregion

          I took the printout and it's not working. Could you please help me where I'm going wrong, as I'm still starting my lines of code in C#?

          Thanks​
          Attached Files

          Comment


            #6
            Hello EvergreenGain,

            From the output all I can tell is that the bools are false. To find out why you would have to add additional prints in your loops and make sure your conditions are becoming true. You would have to print the values you are getting from the swing to make sure you are getting a bars ago and not -1.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by EvergreenGain View Post
              Jesse,

              I wanted to extract from this loop the information on the existence or not of a Lower Low for a long entry and a Higher High for a Short entry.

              In my thoughts, we could use the Swing indicator results (1 and -1) for example for the respective inputs.

              At the end of the day, what I need is a function that checks for the existence of L/L and H/H to filter the entries.

              In any case, thank you very much for your prompt response.

              This support is amazing!!!

              Carlos Guimarăes​
              Hi Carlos,

              A swing is basically a ZIgZag, it all depends on the "Strength" how fast the HH and LL are identified. For example, with a Strength = 5 the HH and LL are not etsblished until at least 5 bars after the the H or L occured.

              So, your strategy will give you a Buy or Sell signal at least 5 bars later after most of the action has already taken place and the trade is over. It is more like catching a train that aleady left the station 5 minutes ago and no change to hop on for a ride.

              If that was a working proposition everyone would be a winner by simply trading the Swing Indicator's Highs and Lows, but sadly with the Swing indicator one would always be late for the party.

              That said, however, it is quite possible to trade swing highs and lows in combination and confirmation from price patterns and actions that are not easy to program in a consistently profitable stratetegy. Best is to trade swings highs and lows by eyes when more than two ducks fall into a row, and those are not necessarily the same ducks everytime.

              Cheers!
              Last edited by aligator; 09-15-2023, 06:47 PM.

              Comment


                #8
                On the one hand you are covered in reason Alligator. Thank you for your comment. But on the other hand, if we can count the previous candles, we could have the exact moment when the indicator starts to repeat and, from referring to previous candles, perhaps
                Previous swings, using this indicator not to give us tops and bottoms, but to filter a more robust entry strategy.

                I'll copy a link from Pablo below so you understand what I mean:

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello EvergreenGain,

                  From the output all I can tell is that the bools are false. To find out why you would have to add additional prints in your loops and make sure your conditions are becoming true. You would have to print the values you are getting from the swing to make sure you are getting a bars ago and not -1.
                  Jesse,

                  I reformulated my strategy according to some interesting videos on YouTube and I would like you to take a look and tell me why I can't access the current and previous swing high using the code snippet below:

                  //LONG ENTRY

                  if ((Swing1.SwingLow[Strength] > Swing1.SwingLow[Strength + 1])
                  && (Close[2]< Open[2])
                  && (Close[3]< Open[3])
                  && (Close[4]< Open[4]))
                  {
                  conditionsToEnterLong = true;
                  }

                  else

                  {
                  conditionsToEnterLong = false;
                  }

                  // SHORT ENTRY

                  if ((Swing1.SwingHigh[Strength] < Swing1.SwingHigh[Strength + 1])
                  && (Close[2]> Open[2])
                  && (Close[3]> Open[3])
                  && (Close[4]> Open[4]))
                  {
                  conditionsToEnterShort = true;
                  }

                  else

                  {
                  conditionsToEnterShort = false;
                  }

                  #endregion

                  Your help would be greatly appreciated, Jesse, or another colleague who can contribute to my question.

                  My thanks in advance.

                  EvergreenGains​

                  Comment


                    #10
                    Hello EvergreenGain,

                    The SwingLow and SwingHigh plots are not used for accessing specific swing values. You would use the custom methods the swing has if you wanted to get a specific instance which returns a BarrsAgo that can be used to get a fixed price in time.

                    SwingHighBar
                    SwingLowBar
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fx.practic, 10-15-2013, 12:53 AM
                    5 responses
                    5,404 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by Shai Samuel, 07-02-2022, 02:46 PM
                    4 responses
                    95 views
                    0 likes
                    Last Post Bidder
                    by Bidder
                     
                    Started by DJ888, Yesterday, 10:57 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by MacDad, 02-25-2024, 11:48 PM
                    7 responses
                    159 views
                    0 likes
                    Last Post loganjarosz123  
                    Started by Belfortbucks, Yesterday, 09:29 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post Belfortbucks  
                    Working...
                    X