Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Swing Indicator into Strategy

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

    Swing Indicator into Strategy

    Hi,

    I'm new to Ninjatrader, can someone please help me or point me in the right direction? I'm looking to turn the default Swing Indicator into a strategy. I would like for it to go long (limit order) when price crosses the previous swing high, and short (limit order) when price crosses the previous swing high.

    Thank you in advance!

    #2
    Hello Dakid4getz,

    Thank you for your note.

    I recommend that you start with the Automated Strategy Development YouTube video.
    This is a great starting ground for understanding how to use the basic interface and how NinjaScript Strategies work.

    * https://www.youtube.com/watch?v=Maaq...56536A44DD7105

    We have a comprehensive help guide that goes through the available NinjaScripts items and even some basic tutorials on creating your own script.

    * http://www.ninjatrader.com/support/h...nt7/index.html

    Our support forum is a wealth of knowledge from our user base and even includes some reference items on how to code particular items.

    * http://www.ninjatrader.com/support/forum/

    Lastly, you are always welcome to send in a support request on any items that you may need assistance with.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Cal,

      I was able to create the strategy; however, I still need help with limit orders and the way the strategy analyzer shows the trades. I'm using the CrossAbove() function like this:

      For longs
      if (CrossAbove(Close, Swing(swingstrength).SwingHigh, 1))
      EnterLongLimit(quantity, Swing(swingstrength).SwingHigh, "LE")

      I keep getting errors when trying to compile. Do you know what it could be? Should I use something else other than CrossAbove()?

      Comment


        #4
        Here's what my trade function looks like:
        private void doTrade()
        {
        double swing_high = 0.0, swing_low = 0.0;

        swing_high = Swing(swingStrength).SwingHigh[1];
        swing_low = Swing(swingStrength).SwingLow[1];

        if( Position.MarketPosition == MarketPosition.Flat )
        {
        if(Close[1] <= swing_high && Close[0] > swing_high)
        EnterLongStop(swing_high + TickSize, "LE");
        if(Close[1] >= swing_low && Close[0] < swing_low)
        EnterShortStop(swing_low - TickSize, "SE");
        }
        if ( Position.MarketPosition == MarketPosition.Short)
        {
        if(Close[1] <= swing_high && Close[0] > swing_high)
        EnterLongStop(swing_high + TickSize, "LE");
        }
        if ( Position.MarketPosition == MarketPosition.Long)
        {
        if(Close[1] >= swing_low && Close[0] < swing_low)
        EnterShortStop(swing_low - TickSize, "SE");
        }
        }

        I'm open to suggestions. The code as it stands does not go into any trades...

        Thank you in advance!

        Comment


          #5
          Hello dakid4getz,

          Thank you for your response.

          You would need to call the SwingHighBar as the BarsAgo for the Swing().SwingHigh to pull the previous swing high as Swing().SwingHigh[1] is only the value of the swing high on the previous bar, not hte previous swing high.

          Please visit the following link for information on Swing and SwingHighBar: http://www.ninjatrader.com/support/h.../nt7/swing.htm

          Comment


            #6
            PatrickH,

            Thank you for the reply; this is the update (just to show entries when flat):

            int sHighBar = 0, sLowBar =0;
            double swing_high = 0, swing_low = 0;

            sHighBar = Swing(swingStrength).SwingHighBar(0, 1, 10);
            sLowBar = Swing(swingStrength).SwingLowBar(0, 1, 10);

            swing_high = Swing(swingStrength).SwingHigh[sHighBar];
            swing_low = Swing(swingStrength).SwingLow[sLowBar];

            if( Position.MarketPosition == MarketPosition.Flat )
            {
            if(Close[0] > swing_high)
            EnterLongStop(swing_high + TickSize, "LE");
            if(Close[0] < swing_low)
            EnterShortStop(swing_low - TickSize, "SE");
            }

            It compiles but it does not go into any trades. What am I doing wrong? I'm still trying to learn...

            Thank you for your help and patience.

            Comment


              #7
              Dakid4getz,

              I would suggest printing out the values that you are testing against and see if these are the values that you are looking for. Using Ptint() will print out what you pass through to the Output window via Tools from the Control Center

              http://www.ninjatrader.com/support/h...html?print.htm
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Hi Dakid4getz,​

                Can you help me with same strategy I m also looking for same trading setup

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                580 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                336 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                102 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X