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

Help with Basic Swing Strategy

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

    Help with Basic Swing Strategy

    Hello,

    I've been using NT7 for a few years and I've developed a basic strategy that I've been back testing manually. I want to automate the back testing using the Strategy Analyzer and need help setting it up properly. Any guidance on how to set this up would really be appreciated.

    Here are the rules:

    This is basically a modified AB=CD pattern.
    Any Forex 60 minute chart (this example is in a downtrend though same goes for uptrend)

    1. Identify most recent swing low
    2. Identify next swing high (Point A)
    3. Confirm price has broken below the close of the swing low.
    4. Identify next swing low (Point B)
    5. Confirm price retraces to .618 fib retracement of recent swing high to second swing low (Point C)
    6. Enter Sell Limit order at .618 fib retracement
    7. Stop Loss order at 1 ATR above swing high (Point A)
    8. Profit Target at 1:1

    It's pretty simple but in backtesting manually it works. Any suggestions on how to set this up properly would be hugely helpful.

    Thank you,
    Jeremy

    #2
    Hello jeremy152,

    Welcome to the forums!

    The NinjaScript strategy will have to be applied to a data series in the Strategy Analyzer. This can be one instrument, or you can use an instrument list. Once the parameters are configured, the backtest can be started.

    Backtesting and using the Strategy Analyzer can be further referenced in our publicly available help guide. There are interactive videos in the help guide that can provide further direction as well. You may need to view the page with a different browser if the interactive videos are unable to load. I'll provide a link below.

    Backtesting - https://ninjatrader.com/support/help...a_strategy.htm

    Please let me know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim,

      Thank you for the fast response. I'm able to set up the data series and I've gone through the tutorials - Most are around MA Cross which I don't need for this strategy. My question pertains more to what conditions I need to consider using in the wizard and how to set them up. I know this is pretty rudimentary but I'm just starting out.

      Jeremy

      Comment


        #4
        Hello Jeremy,

        Thanks for the additional detail.

        If you haven't already, I would highly recommend to view the Strategy Wizard 301 recorded webinar as it is a great resource for learning to use the Strategy Wizard and understanding what can be done with it. It is designed for creating simple strategies. Some aspects of your strategy will have to be unlocked and written by hand.

        Items 1-4 can be accomplished using the Swing indicator to determine your swings. Once one swing has been detected, you can set a variable and use that variable in another condition that finds the "next" Swing value.

        I would advise to start writing this logic in separate strategies and only focusing on 1 condition set at a time. This way you can better verify the conditions you have written before combining them all into the main strategy.

        Items 5 and 6 would need to be able to reference an indicator that does the Fibonacci Retracements since it is not possible to reference the lines created by the drawing tool in the Strategy Wizard. You could reference this by writing your own code, however.

        Item 7 would require unlocking the code and setting the Stop Loss dynamically.

        Item 8, I'm not sure how the Profit Target would be set "1:1." You can set it to be a certain number of ticks away from the entry, an exact price value, or for an amount of PnL. I would suggest to run through the Strategy Wizard webinar to get more acquainted with how Targets and Stops can be set in the Wizard.

        Strategy Wizard 301 - https://www.youtube.com/watch?v=FmBiNYsf1e8

        Strategy Wizard (doc) - https://ninjatrader.com/support/help...egy_wizard.htm

        SetStopLoss() (move to OnBarUpdate() for a dynamically calculated stop loss) - https://ninjatrader.com/support/help...etstoploss.htm

        We also have an EcoSystem of NinjaScript Consultants that would be happy to write this strategy or any others at your request. If you are looking for such services, I can have a member of our Business Development team reach out with more information.

        Please let me know if I can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          I'm having some difficulty setting up the swing indicator in the condition window it doesn't seem to be cooperating with me. I want to use the swing indicator combined with the Fisher transform, to create signals of when the fisher transform has reached an apex or valley and begin returning to the mean do I nest the fisher transform in the swing indicator as the data series in Swing? or is it the other way around? and what happens in the left middle and right sides of the screen in the builder.
          is it Price/ close in the left window , equals in the center, and then swing lower plot, with the Fisher transform as the data series? on the right side of the screen? or is it done some other way? I seem to recall a video someone did, but can't find it tonight.

          Originally posted by NinjaTrader_Jim View Post
          Hello Jeremy,

          Thanks for the additional detail.

          If you haven't already, I would highly recommend to view the Strategy Wizard 301 recorded webinar as it is a great resource for learning to use the Strategy Wizard and understanding what can be done with it. It is designed for creating simple strategies. Some aspects of your strategy will have to be unlocked and written by hand.

          Items 1-4 can be accomplished using the Swing indicator to determine your swings. Once one swing has been detected, you can set a variable and use that variable in another condition that finds the "next" Swing value.

          I would advise to start writing this logic in separate strategies and only focusing on 1 condition set at a time. This way you can better verify the conditions you have written before combining them all into the main strategy.

          Items 5 and 6 would need to be able to reference an indicator that does the Fibonacci Retracements since it is not possible to reference the lines created by the drawing tool in the Strategy Wizard. You could reference this by writing your own code, however.

          Item 7 would require unlocking the code and setting the Stop Loss dynamically.

          Item 8, I'm not sure how the Profit Target would be set "1:1." You can set it to be a certain number of ticks away from the entry, an exact price value, or for an amount of PnL. I would suggest to run through the Strategy Wizard webinar to get more acquainted with how Targets and Stops can be set in the Wizard.

          Strategy Wizard 301 - https://www.youtube.com/watch?v=FmBiNYsf1e8

          Strategy Wizard (doc) - https://ninjatrader.com/support/help...egy_wizard.htm

          SetStopLoss() (move to OnBarUpdate() for a dynamically calculated stop loss) - https://ninjatrader.com/support/help...etstoploss.htm

          We also have an EcoSystem of NinjaScript Consultants that would be happy to write this strategy or any others at your request. If you are looking for such services, I can have a member of our Business Development team reach out with more information.

          Please let me know if I can be of further assistance.

          Comment


            #6
            Hello Daryl,

            I've made a quick video setting up a print for the Swing indicator with the Fisher Transform indicator as input. (Detecting swings off of the Fisher Transform plot value.) The output tells us how many bars are to the left and right of the swing point. You would want to model your logic around how the swing indicator outputs data to create a strategy that can trigger off of it.

            Demo - https://www.screencast.com/t/zVg5OqDEJ

            Additional reading on the Swing Indicator can be found in our publicly available reference here - https://ninjatrader.com/support/help...n-us/swing.htm

            Please let me know if I can be of further help.
            JimNinjaTrader Customer Service

            Comment


              #7
              Very cool and thank you for the video which showed me a very different thing than I thought I was looking for. I had already created pretty much you had done in it but on the conditions side of the builder and not nested inside the print actions. THAT IS COOL!!!! I'd never thought of how that is done nor of it's utility before your video. I'm totally going to begin digging into print actions and how those are used now.

              The question I was meaning to ask, and probably wasn't clear, how to you tell that print indicator that you want it to perform an action after it has begun drawing swing dots on a given side. IE we have just begun a swing LONG after creating a short term pivot LOW. Maybe, if other conditions are also met, it could be a good time to enter a long trade position. I even added a color changing 1 period SMA to the fisher transform to be able to see a separate and distinct plot drawn in the falling or climbing state. is that possibly the easier way to detect the indicator trend direction? is added a similar slope change single period MA to a momentum of the MACD of a supersmoother, which is an average of that same MACD settings. Presented in a histogram so I can see a slightly different difference histogram than the one more normally associated with the MACD indicator. It's the being able to tag those transition points from falling to rising, where red turns to green on the line, That I want to potentially perform an action if other conditions are also met simultaneously....

              Also and this might be a topic for a different thread in the case of multiple indicators which might need to be nested inside specific output boxes and separate windows etc. how do you tell the various indicators in a strategy where you want them displayed on the chart other than the default output window? is that done in the editor, or can it be done in the builder?

              Originally posted by NinjaTrader_Jim View Post
              Hello Daryl,

              I've made a quick video setting up a print for the Swing indicator with the Fisher Transform indicator as input. (Detecting swings off of the Fisher Transform plot value.) The output tells us how many bars are to the left and right of the swing point. You would want to model your logic around how the swing indicator outputs data to create a strategy that can trigger off of it.

              Demo - https://www.screencast.com/t/zVg5OqDEJ

              Additional reading on the Swing Indicator can be found in our publicly available reference here - https://ninjatrader.com/support/help...n-us/swing.htm

              Please let me know if I can be of further help.
              Attached Files

              Comment


                #8
                Hello Daryl,

                Thanks for your reply.

                The Swing indicator will plot dots between upper and lower swings at the same time. The indicator provides a good visual for how long a swing lasts, but the dots only tell you that the market direction has not dropped below the point in which the swing started.

                The Strategy Builder is limited in mathematical operations, and I am not sure of a way to count how many times the SwingHigh or SwingLow is the same to count how many dots it has plotted. This would involve unlocking the code and writing additional logic to count each time the plot value is the same, and then set the counter back to 0 once changed.

                Some programming concepts can be referenced in the NinjaTrader 7 help guide here: https://ninjatrader.com/support/help...g_concepts.htm

                Have you looked at using IsRising() and IsFalling() in your strategy? These can be found under Misc > Rising and Misc > Falling in the Strategy Builder.

                how do you tell the various indicators in a strategy where you want them displayed on the chart other than the default output window? is that done in the editor, or can it be done in the builder?
                When you select "Plot On Chart" AddChartIndicator() is used to add the indicator to the chart. The indicator is then added to a new indicator panel owned by that indicator or the main price panel. This is determined by the IsOverlay property of the Indicator. We do not offer a supported way to specify which panel an indicator should plot to through NinjaScript. Other users may be able to share their experience with unsupported code, however.

                Please let me know if I can be of additional help.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Yeah:
                  It's about what I've tried and found works pretty well in most cases so far. I've used is rising as well as is greater than or less than X bars ago too. Both work fine and seem to be the logic used underneath the color change plots used on some of the already existing moving average indicators. Fascinating stuff once digging into it really.
                  So swing is more useful as a visual cue than as an algorithm programming indicator at least for this purpose currently. Seeing as how there are more streamlined ways to call for an action already in the strategy builder. Thank you very very much, you guys as always are a tremendous help. I really appreciate the thing on how to use the print action too. I'd seen other threads ask for that, but it hadn't really clicked on how to go about using it.

                  Originally posted by NinjaTrader_Jim View Post
                  Hello Daryl,

                  Thanks for your reply.

                  The Swing indicator will plot dots between upper and lower swings at the same time. The indicator provides a good visual for how long a swing lasts, but the dots only tell you that the market direction has not dropped below the point in which the swing started.

                  The Strategy Builder is limited in mathematical operations, and I am not sure of a way to count how many times the SwingHigh or SwingLow is the same to count how many dots it has plotted. This would involve unlocking the code and writing additional logic to count each time the plot value is the same, and then set the counter back to 0 once changed.

                  Some programming concepts can be referenced in the NinjaTrader 7 help guide here: https://ninjatrader.com/support/help...g_concepts.htm

                  Have you looked at using IsRising() and IsFalling() in your strategy? These can be found under Misc > Rising and Misc > Falling in the Strategy Builder.


                  When you select "Plot On Chart" AddChartIndicator() is used to add the indicator to the chart. The indicator is then added to a new indicator panel owned by that indicator or the main price panel. This is determined by the IsOverlay property of the Indicator. We do not offer a supported way to specify which panel an indicator should plot to through NinjaScript. Other users may be able to share their experience with unsupported code, however.

                  Please let me know if I can be of additional help.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  168 responses
                  2,262 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  3 responses
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by WeyldFalcon, 12-10-2020, 06:48 PM
                  14 responses
                  1,429 views
                  0 likes
                  Last Post Handclap0241  
                  Started by DJ888, 04-16-2024, 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
                  41 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X