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

Problem with 'Swing' indicator in strategy

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

    Problem with 'Swing' indicator in strategy

    Hello,

    In my strategy, when the swing low is crossed below, the strategy to enters a short position as shown circled in red like it's supposed to, but the strategy will also enter a short position a few bars later circled in yellow, despite the fact the the swing low has already been crossed below (and is no longer visible) and the data box not showing a swing low value for the bar circled in yellow. This occurs repeatedly. How do I prevent this from occurring? Is this a glitch in the swing indicator?

    #2
    Hello burmaz,

    Print the time of the bar and all values used in the condition that submits the order. Include labels for each value and each comparison operator (*important). Enable TraceOrders and also print the order object from OnOrderUpdate().

    This will tell you why the condition evaluated as true or false for any bar and will show what happened with the order.

    Below is a link to a forum post that demonstrates using print and TraceOrders to understand behavior.


    Save the output from the output window to a text file and attach this with your next post.
    I am happy to assist with analyzing the output. Let me know at what date and time the action occurs.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello,

      I attached the relevant output. The Swing indicator print output is not reporting the same values as the databox or the chart. The swing was broken at 9:33am, circled in red, and the incorrect trade was entered at 9:51am. The chart and databox show no swing low values past 9:33am as expected. HOWEVER, the print output is still reporting a swing low value at 9:40am and 9:51am as if the swing had never been broken. Is this a glitch in the swing indicator?
      Attached Files

      Comment


        #4
        Hello burmaz,

        I'm not certain what is being compared here...

        09:40:52.4040000 | SwingLow| Swing(Close, Convert.ToInt32(SwingIndicator)).SwingLow[0] 3892.5

        Is this good or bad?

        Are these values used in a condition?

        What is the condition statement? I will assist with directing how to add comparison operator labels and all of the values from the condition.

        Did you enable TraceOrders?

        You are saying the SwingLow[0] is producing a value, but there is no plot on the chart for that bar, is this correct?
        Does IsValidDataPoint() return true to show a value was set on this bar? (or are we looking at the Close price when no plot value is set?)
        https://ninjatrader.com/support/help...ddatapoint.htm

        Below is a link to sample code of detecting previous swings.
        https://ninjatrader.com/support/foru...12#post1085012
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5

          Hello,

          Thank you for your fast reply.


          09:40:52.4040000 | SwingLow| Swing(Close, Convert.ToInt32(SwingIndicator)).SwingLow[0] 3892.5

          09:51:54.1600000 | SwingLow| Swing(Close, Convert.ToInt32(SwingIndicator)).SwingLow[0] 3892.5

          This value is bad because the value appears after the swing was broken at 9:33am. There is no swing low value plotted on the chart or in the databox at 9:40am or 9:51am yet it is displayed via 'print'. My strategy is supposed to enter a short position when the bar closes below the swing low. The swing was broken by a 'low' circled in red in the picture attached above at 9:33am. Therefore my strategy should not see a swing low value at 9:40am or 9:51am, and my strategy should not enter a trade. However, my strategy sees an incorrect swing low value at 9:40am and when the price closes below this incorrect swing low value, it enters a short position that it should not be entering.

          The discrepancy between what is shown on the chart and in the databox and values that are generated using 'print' is the issue. I want my strategy to react exactly how swing is displayed on the chart and the data box.

          I am using the strategy builder. How do I use 'Does IsValidDataPoint()' that you mentioned?




          Relevant output from trace orders:


          5/19/2022 9:40:52 AM Strategy 'VVWAPAuto11PnLSwingRCrossForcastEODEmailATRNoCros sATRStoplossCLOSEUnlocked/-1': Entered internal SubmitOrderManaged() method at 5/19/2022 9:40:52 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='shortbottom' FromEntrySignal=''
          enter short 31.25 > -10000

          Comment


            #6
            Hello burmaz,

            The strategy will need to be unlocked to add a check that the plot has a value set with IsValidDataPoint(). Unlike other indicators, the swing indicator does not set plot values on all bars, only when a swing is occurring. When no plot value is set, the Close price is returned instead. This means you may be looking at the Close price because no plot value is being set on that bar.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello,

              Thank you for your response.

              The values being returned are the same values of the broken swing line. The close value for 09:40:52.4040000 is 3887.50, not the 3892.5 'print' returns as shown above. The close value for 09:51:54.1600000 is 3881.25, also not the 3892.5 that 'print' returns above. The swing indicator is giving the swing values despite the swing line having been broken, not the close values. The swing indicator functions properly on the chart and databox but ignores that the swing line has been broken for the 'print' returns.
              Last edited by burmaz; 05-19-2022, 08:34 PM.

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello burmaz,

                The strategy will need to be unlocked to add a check that the plot has a value set with IsValidDataPoint(). Unlike other indicators, the swing indicator does not set plot values on all bars, only when a swing is occurring. When no plot value is set, the Close price is returned instead. This means you may be looking at the Close price because no plot value is being set on that bar.
                Hello,

                Thank you for your response.

                The values being returned are the same values of the broken swing line. The close value for 09:40:52.4040000 is 3887.50, not the 3892.5 'print' returns as shown above. The close value for 09:51:54.1600000 is 3881.25, also not the 3892.5 that 'print' returns above. The swing indicator is giving the swing values despite the swing line having been broken, not the close values. The swing indicator functions properly on the chart and databox but ignores that the swing line has been broken for the 'print' returns.

                Comment


                  #9
                  Hello burmaz,

                  It is noted in the help guide that the swing is a visual tool and not intended for signals, the plot data gets re written as it goes so that would not be suitable for conditions to use those plots in an accurate way. You can unlock the code if you wanted to use the swings more advanced methods to retrieve values. The swing has two methods called SwingLowBar and SwingHighBar which would be the accurate way to look for swing data, that uses logic to find the data.



                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by junkone, Today, 11:37 AM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by frankthearm, Yesterday, 09:08 AM
                  11 responses
                  43 views
                  0 likes
                  Last Post frankthearm  
                  Started by quantismo, 04-17-2024, 05:13 PM
                  5 responses
                  35 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by proptrade13, Today, 11:06 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by love2code2trade, 04-17-2024, 01:45 PM
                  4 responses
                  35 views
                  0 likes
                  Last Post love2code2trade  
                  Working...
                  X