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

Offset Percent isn't working in Strategy Builder

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

    Offset Percent isn't working in Strategy Builder

    Hi,
    I'm a new user and am confused why these simple conditions don't work in Strategy Builder. I just want to see occurrences where if the MACD Diff increases (Long) or decreases (Exit) by 20%. Here are the conditions in 2 different Sets:

    Long:
    (MACD(12,26,9).Diff[0] ) >==MACD(12,26,9).Diff[1] * 0.2)

    Exit:
    (MACD(12,26,9).Diff[0] * 0.2) <==MACD(12,26,9).Diff[1]

    I've attached a screenshot of a backtest and it shows entrances and exits that aren't following set conditions. Am I missing something? It just trades all over the place. Please help me to find a way to properly set this up. Thanks!

    Screenshot.pdf

    #2
    Hello Lance El Camino,

    Thanks for your post and welcome to the NinjaTrader forum.

    For your long condition, It looks like you are comparing the current bar value to only 20% of the previous bar value. I suspect you really want this to be 120%

    For your short condition, it looks like you are comparing only 20% of the current bar value to the previous bar value. I suspect you really want this to be 80%

    Try changing the 0.2 to 1.2 for the long and change the 0.2 to 0.8 for the short.

    Also, I would suggest using draw objects on the chart to show when your conditions are true as this will better help you understand why your strategy performs as it does. I have attached a video that shows the process of adding markers to show the conditions as we as how to offset them for better observation. https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA

    Also, to further debug within the strategy, you can create print statements to output the value of anything you are trying to compare, here is a short video on how to use print statements in the strategy builder to find the bar by bar values: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw I would suggest you use this approach if you are not getting the expected results.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul. According to the Help guide it appears the Offset percentage adds to that value. In the example about checking for Volume Expansion it says "Current value of Volume is greater than or equal to the value of Volume of 1 bar ago + 300%" This implies that it adds that percent to the value of 1 bar ago.

      I actually tried using 1.2 on Long and still not getting accurate results. Same as using .8 on the Exit, nope.

      Long:

      (MACD(12,26,9).Diff[0] ) >==MACD(12,26,9).Diff[1] * 1.2)

      Exit:

      (MACD(12,26,9).Diff[0]) <==MACD(12,26,9).Diff[1] * 0.8)

      I've attached some results. It's not calculating properly. I've gone through and analyzed a lot of these and can't find a solid reason why it enters and exits so placing markers won't help. It's only 2 conditions. Seems like it's just not calculating properly?

      Screenshot2.pdf

      Comment


        #4
        Hello Lance El Camino,

        Thanks for your reply.

        Regarding Offset in the strategy builder, here is the link: https://ninjatrader.com/support/help...setAnItemValue

        Note that it shows: Offsets a percentage value of the item's value. A value of 1 is equal to 100% where a value of 0.1 is equal to 10%.

        Also, when you look at the completed condition in the strategy builder it shows that it is multiplying the value by the percent value entered, therefore if you want to see if a value is 20% greater you would use 1.2.

        Please use the print statement and print out the actual values you are trying to compare and walk through them.

        Using markers will help you further debug by visually showing you on the chart on which bar the conditions are true and then you can compare the actual values being determined.

        Note if you are using Calculate.OnBarClose or are looking at historical data, that your orders are being placed on the bar after the conditions are true and this is why just looking at orders can be misleading. The best way to debug is print and markers.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          Thanks for showing how to print output. I can see how it can be helpful BUT it appears the percent offset isn't calculating. I set it to 1.5 and 0.5 to reduce executions but it didn't.

          (MACD(12,26,9).Diff[0] ) >==MACD(12,26,9).Diff[1] * 1.5) is the Long Signal condition.

          (MACD(12,26,9).Diff[0]) <==MACD(12,26,9).Diff[1] * 0.5) is the Exit Long condition.

          Sample of print output:

          12/9/2020 3:50:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 3:50:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''

          12/9/2020 3:50:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 3:50:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit' FromEntrySignal='Long'

          12/9/2020 3:50:00 AM Strategy 'PreviousBarClose/219686901': Ignored SubmitOrderManaged() method at 12/9/2020 3:50:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit' FromEntrySignal='Long' Reason='This was an exit order but no position exists to exit'

          Time/Date 12/9/2020 3:50:00 AM Bool OkToTrade= True MACD(12, 26, 9).Diff[0] = -0.23051189862537 MACD(12, 26, 9).Diff[1] = -0.209072692846026109.5% change,NOT >== 150% OFFSET.

          12/9/2020 4:00:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 4:00:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''

          12/9/2020 4:00:00 AM Strategy 'PreviousBarClose/219686901': Ignored SubmitOrderManaged() method at 12/9/2020 4:00:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

          12/9/2020 4:00:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 4:00:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit' FromEntrySignal='Long'

          Time/Date 12/9/2020 4:00:00 AM Bool OkToTrade= True MACD(12, 26, 9).Diff[0] = -0.186046027071146 MACD(12, 26, 9).Diff[1] = -0.23051189862537 80.5% change, NOT <== 50% OFFSET.

          12/9/2020 4:00:00 AM Strategy 'PreviousBarClose/219686901: Cancelled pending exit order, since associated position is closed, orderId='NT-00040-8108' account='Sim101' name='Stop loss' orderState=Working instrument='ES 03-21' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=3691.75 quantity=1 tif=Gtc oco='NT-00026-8108' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-12-09 03:50:00' gtd='2099-12-01' statementDate='2021-01-08'

          12/9/2020 4:10:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 4:10:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''

          12/9/2020 4:10:00 AM Strategy 'PreviousBarClose/219686901': Entered internal SubmitOrderManaged() method at 12/9/2020 4:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit' FromEntrySignal='Long'

          12/9/2020 4:10:00 AM Strategy 'PreviousBarClose/219686901': Ignored SubmitOrderManaged() method at 12/9/2020 4:10:00 AM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Exit' FromEntrySignal='Long' Reason='This was an exit order but no position exists to exit'

          Time/Date 12/9/2020 4:10:00 AM Bool OkToTrade= True MACD(12, 26, 9).Diff[0] = -0.229814395407268 MACD(12, 26, 9).Diff[1] = -0.186046027071146 This wasn't even less than previous bar so why enter Long?? Does it only calculate Absolute Value with no recognition of negative integers?

          Here's a visual of the chart:

          Screenshot3.pdf

          What am I missing here? When Bool OkToTrade = True that means the bar that just closed met the condition? Thanks!

          Comment


            #6
            Hello Lance El Camino,

            Thanks for your reply.

            The strategy code will multiple the percent value times the actual value of the selected bar MACD diff value.

            I will sugest again that you want to start at looking at the values on a bar by bar basis and you want to use markers on the chart to indicate where the conditions are true. I would remove placing orders for now as they are a distratction until you get the logic working correctly.

            I am near the end of my day here so I won't be able to get to this until some later on Monday.

            Please attach your strategy (that you used to generate the data in post #5).

            Your strategy can be found under documents>NinjaTrader8>bin>custom>Strategies> it will be a .cs type.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello Lance El Camino,

              I've attached a couple of screenshots, one that shows the chart where blue does indicate that MACD diff[0] > = Diff[1] * 1.2 and magenta dots show where MACD diff [0] * 0.8 <= MACD Diff1.

              You can also see the print out on a bar by bar basis that shows the values the contribute to the determination of when to show the dots.

              The other screenshot also shows how the print statement is constructed, to help clarify the data in the output window,

              The values appear to be correctly calculated.

              Click image for larger version

Name:	LanceEl-1.PNG
Views:	382
Size:	165.4 KB
ID:	1136189

              Click image for larger version

Name:	lanceEl-2.PNG
Views:	372
Size:	152.0 KB
ID:	1136190

              Please note that with an oscillating signal, such as the Diff plot, you will get negative values.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Thanks Paul! This is really nice and I realize that the calculation was mixing negative with positive values at times producing True conditions where I mistakenly thought it shouldn't.

                On an unrelated note, I have access to the Order Flow Cum Delta indicator but notice it can't be used in Strategy Builder. How can I include this into a strategy?

                Thank you!

                Comment


                  #9
                  Hello Lance El Camino,

                  Thanks for your reply.

                  Correct, the Order Flow Cumulative Delta (and all of the other Order flow indicators) are not available in the Strategy Builder. In general, they require additional data synchronization that is not in the Strategy Builder.

                  You would need to work with the Ninjascript editor to work with a script that uses the Order Flow Cumulative Delta indicator. Here is a link to the Ninjascoipt section, and an example: https://ninjatrader.com/support/help...ive_delta2.htm
                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sidlercom80, 10-28-2023, 08:49 AM
                  172 responses
                  2,278 views
                  0 likes
                  Last Post sidlercom80  
                  Started by Irukandji, Yesterday, 02:53 AM
                  2 responses
                  17 views
                  0 likes
                  Last Post Irukandji  
                  Started by adeelshahzad, Today, 03:54 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by CortexZenUSA, Today, 12:53 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post CortexZenUSA  
                  Started by CortexZenUSA, Today, 12:46 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post CortexZenUSA  
                  Working...
                  X