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

Simple swing break strategy - OnEachTick

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

    Simple swing break strategy - OnEachTick

    Hello,
    I have simple strategy which uses @Swing.cs indicator. I need to enter the trade when price crosses last valid swingLow - for short and swingHigh - for long trades.

    I need to operate on Calculate.OnEachTick so that it enters inside candle:

    Problem 1: how do I get values swing high and low (according to indicator dots?

    To get swing High and Low i Use:

    // How do I get last valid swing High?
    double swingHigh = Swing1.SwingHigh[0];

    // How do I get last valid swing Low?
    double swingLow = Swing1.SwingLow[0];

    But I get nonsense values :-/ What am I doing wrong?

    Problem 2: I have check TickReplay in Data series settings so that I get accurate filling but when I add strategy to chart (Tick Replay checked, Timeframe 15) I see entries on bad levels see attachments.

    Could you please help me in these two things. How properly refer to SwingHigh and SwingLow values on candle "actual - one" (preactual)
    How to set data to see entries "on swing values" not on close of candles.

    Thanks a lot Paul
    Attached Files

    #2
    Hello kujista,

    Thanks for your post.

    Ninjascripts, in general, when applied to a data series, will process starting on the first bar of the data series, and process according to the logic in your script. The script will continue processing the bars in their order moving to ultimately the right edge of the chart.

    The Swing indicator does not "confirm" a swing until the "strength" number of bars have passed since the last High or Low was detected. The "strength" bars after a potential high all have to be less then the High to confirm the swing high (and the same for Low except they would be greater than the potential low). Once the swing is confirmed, then the indicator will draw dots back to the swing high and at that point the new swing high or low value would be available.

    From the help guide, here is the swing indicator description: The Swing indicator will plot lines that represent the swing points based on the strength (number of bars to the left and right of the swing point) parameter provided, it's mostly a visual tool and not meant to be predictive in nature. Only after the strength number of bars has passed since the extreme point, the swing return value could be definitely set, thus the indicator updates it's calculations as new incoming data warrants so. https://ninjatrader.com/support/help...nt8/?swing.htm

    The above information is to help you understand that the swing signal then is delayed by whatever the strength bar setting you are using. In your code you are using 1, so the High would at best be known 2 bars later (the high bar, the 1 strength bar).

    I would suggest using a larger swing strength setting and then printing the values of swing high and low in order to help you understand how it is working. Once you have a better understanding then you can adjust to your preferred setting. By printing the values (with swing at a higher strength setting) it will be easier for you to see when the swing high/low is confirmed.

    Tick replay does not change how orders fill.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      I have to admit I cannot figure out how the Swing exactly works :-/ Could you please at least tell me,
      If it is possible to get values (I show them in DataBox) on next candle opening from Swing with strength 1?

      Paul
      Attached Files

      Comment


        #4
        I thought all i have to do is Swing1.SwingLow[0] and High :-/ but it is obviously more complicated

        Comment


          #5
          Hello kujista,

          Thanks for your reply.

          I've created a test strategy that you can replicate. To help visualize I have it draw an arrow on the bar where the change in swing is known (as discussed 2 bars later)

          Click image for larger version

Name:	kujista-1.PNG
Views:	503
Size:	100.2 KB
ID:	1080806

          Note that we are checking the current swing high value to the one 2 bars ago as this would be the swing high point + 1 strength bar, so we look for a price change to detect a new swing high
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi,

            well If I have swing strength 3, I will test against 1 + 3 bars for swingLow/High change, is that so? I guess it works me now fine for strength 1.

            Thanks for answer and cofirmation.

            Comment


              #7
              Hello kujista,

              Thanks for your reply.

              "well If I have swing strength 3, I will test against 1 + 3 bars for swingLow/High change, is that so? ", Correct!
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello kujista,

                Thanks for your reply.

                I've created a test strategy that you can replicate. To help visualize I have it draw an arrow on the bar where the change in swing is known (as discussed 2 bars later)

                Click image for larger version

Name:	kujista-1.PNG
Views:	503
Size:	100.2 KB
ID:	1080806

                Note that we are checking the current swing high value to the one 2 bars ago as this would be the swing high point + 1 strength bar, so we look for a price change to detect a new swing high
                I would appreciate if it is possible to produce this strategy as a zip file to download. I too am having difficulty finding the right values for swing high/lows ( or rather the point at which it changes)

                Comment


                  #9
                  Hello Mindset,

                  Thanks for your post.

                  The complete code is displayed in the screenshot, you should be able to recreate this easily enough.
                  Please note that the example was done with a swing strength of 1.

                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ghoul, Today, 06:02 PM
                  3 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  44 views
                  0 likes
                  Last Post jeronymite  
                  Started by Barry Milan, Yesterday, 10:35 PM
                  7 responses
                  20 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by AttiM, 02-14-2024, 05:20 PM
                  10 responses
                  180 views
                  0 likes
                  Last Post jeronymite  
                  Started by DanielSanMartin, Yesterday, 02:37 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post DanielSanMartin  
                  Working...
                  X