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

Using Price above Last Swing High/Low

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

    Using Price above Last Swing High/Low

    Could anyone help me out with a simple line of code to determine whether the the current price is above the last swing high (as in the Ninja indicator Swing with default 5 setting)? Thank you

    ACtually let me clarify:

    Basically I"m looking to do something if I know that within the last 10 bars, price has crossed up over the most recent swing high. I'm also looking to do something else if I know that within the last 10 bars, price has crossed below the last swing low. I'm looking to do a third thing when over the last 10 bars, price has not moved past the last swing high, or the last swing low.

    For example, price crosses the last swing high and Ninja will execute X - I want x to remain in effect until another Swing high starts printing (which requires a retracement). If during this retracement, price continues to retrace and not cross this swing high for 10 bars, I want Ninja to do something else Y and no longer do X. If during the course of that retracement, it happens to create a Swing Low, and then it happens to cross that Swing low, I want Ninja to do Z and to no longer do Y.

    Is this possible? Should I be using a for loop, or will if statements work?
    Last edited by jmflukeiii; 04-06-2012, 03:59 PM.

    #2
    Basically - How do I say "if Price hasn't crossed either a swing high or a swing low for 10 bars, do Y"

    Comment


      #3
      Originally posted by jmflukeiii View Post
      Basically - How do I say "if Price hasn't crossed either a swing high or a swing low for 10 bars, do Y"
      Requirement is not very clear. You mean that you want to isolate a situation where in the last 10 bars, price has not broken out of the last swing low or swing high, no matter how long ago those swings occurred? Or do you mean something else?

      Comment


        #4
        Thank you for the reply, here is the sample script as is:

        The problem here is that the outline turns blue only when the price is above the last swing high. However, by passing the swing high, the trend is deemed to be "up" and thus I want blue candles (colored for down, empty for up) until that "trend" is no longer moving strongly.... bear with me....
        price crosses the swing, candles turn blue.
        Price goes up for however long, and then a new swing high value forms during a retracement.
        IF this retracement lasts 10 bars or more (meaning it does NOT cross the new swing high value), I want the candles to no longer be blue but turn yellow instead.

        I've tried cross above also because the other issue with the way its written below is that if price crosses the swing high, but then pulls back below that swing high, it changes back colors. But the problem with cross above is it just looks back a certain number of bars and once that fixed period is over, it stops doing the condition - i.e. so price could cross the swing high and go straight up for 40 bars, but because the lookback on the cross above is only 10, it stops printing blue after 10 bars. Let me know if this question is still unclear

        if (Close[0]<Swing(5).SwingLow[0])
        {

        if (Close[0]<Open[0])
        {
        CandleOutlineColor = candleOutlineDown;
        BarColor = Color.Red;

        }
        else if (Close[0]>Open[0])
        {
        CandleOutlineColor = candleOutlineDown;
        BarColor = Color.Transparent;
        }

        }
        else if (Close[0]>Swing(5).SwingHigh[0])

        {

        if (Close[0]<Open[0])
        {
        CandleOutlineColor = candleOutlineUp;
        BarColor = Color.DodgerBlue;

        }
        else if (Close[0]>Open[0])
        {
        CandleOutlineColor = candleOutlineUp;
        BarColor = Color.Transparent;
        }
        }
        else
        {
        if (Close[0]<Open[0])
        {
        CandleOutlineColor = candleOutlineDoji;
        BarColor = Color.Yellow;

        }
        else if (Close[0]>Open[0])
        {
        CandleOutlineColor = candleOutlineDoji;
        BarColor = Color.Transparent;
        }
        }
        }

        Comment


          #5
          This is getting closer, but still not quite right.... This code snippet stops printing blue bars 5 bars after the second swing high value is created.... is the only way I can do that is if I have the strength be 10??

          {
          if (CrossAbove(EMA(1),Swing(5).SwingHigh[0],Swing(5).SwingHighBar(0,1,10)))
          {
          if (Close[0]<Open[0])
          {
          CandleOutlineColor = candleOutlineUp;
          BarColor = Color.DodgerBlue;

          }
          else if (Close[0]>Open[0])
          {
          CandleOutlineColor = candleOutlineUp;
          BarColor = Color.Transparent;
          }
          }
          else if (CrossBelow(EMA(1),Swing(5).SwingLow[0],Swing(5).SwingLowBar(0,1,10)))
          {
          if (Close[0]<Open[0])
          {
          CandleOutlineColor = candleOutlineDown;
          BarColor = Color.Red;

          }
          else if (Close[0]>Open[0])
          {
          CandleOutlineColor = candleOutlineDown;
          BarColor = Color.Transparent;
          }
          }
          }
          Last edited by jmflukeiii; 04-07-2012, 09:07 AM.

          Comment


            #6
            There is still quite a bit that you have not accounted for, which means that it is still not quite clear.

            Taking the long side only as an example, here is what might happen. How is your coloring scheme done for each situation?

            Close is above last swing high (how many bars ago qualify it as a market?)

            Then:
            • Price consolidates at the high, closing above and below it, but not creating a Swing point.
            • Price immediately retreats and keeps closing below the Swing high, but does not go below the Swing low, or form another Swing Low.
            • Price runs away in a breakout (this is the easy, obvious one).

            Comment


              #7
              Here is an indicator that has been written to be used with Strategy Wizard - Ultimate Swing High Low - NinjaTrader Indicator

              Comment


                #8
                Originally posted by koganam View Post
                There is still quite a bit that you have not accounted for, which means that it is still not quite clear.

                Taking the long side only as an example, here is what might happen. How is your coloring scheme done for each situation?

                Close is above last swing high (how many bars ago qualify it as a market?)

                Then:
                • Price consolidates at the high, closing above and below it, but not creating a Swing point.
                • Price immediately retreats and keeps closing below the Swing high, but does not go below the Swing low, or form another Swing Low.
                • Price runs away in a breakout (this is the easy, obvious one).
                The answer is the same, as soon as the price closes above the swing high, it would turn "blue". If it dances around for 10 bars and doesn't do anything after that "it turns yellow". But it remains blue until 10 bars of non progression have occurred.

                Comment


                  #9
                  Next question

                  I solved my issue for the most part and the indicator works.

                  However, I want to change the outline color of the current bar in progress only while not affecting all bars that have happened. What is the most efficient way of doing that?

                  Comment


                    #10
                    Originally posted by jmflukeiii View Post
                    I solved my issue for the most part and the indicator works.

                    However, I want to change the outline color of the current bar in progress only while not affecting all bars that have happened. What is the most efficient way of doing that?
                    Change the BarColor.

                    ref: http://www.ninjatrader.com/support/h...l?barcolor.htm

                    Comment


                      #11
                      Thanks Kogonam, I'm going to change CandleOutlineColor.

                      My question was more referring to how do I affect only the current bar's (the bar that is forming) outline while allowing the rest of the bars to be printed with colors I have already put together through the indicator?

                      Comment


                        #12
                        Originally posted by jmflukeiii View Post
                        Thanks Kogonam, I'm going to change CandleOutlineColor.

                        My question was more referring to how do I affect only the current bar's (the bar that is forming) outline while allowing the rest of the bars to be printed with colors I have already put together through the indicator?
                        No difference. Both BarColor and CandleOutlineColor refer to the specific bar on which they are invoked. That is how we can duplicate the custom bar coloring of TradeStation or Telechart.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Barry Milan, Today, 10:35 PM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Manfred  
                        Started by WeyldFalcon, 12-10-2020, 06:48 PM
                        14 responses
                        1,427 views
                        0 likes
                        Last Post Handclap0241  
                        Started by DJ888, Yesterday, 06:09 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        40 views
                        0 likes
                        Last Post jeronymite  
                        Started by bill2023, Today, 08:51 AM
                        2 responses
                        16 views
                        0 likes
                        Last Post bill2023  
                        Working...
                        X