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

Profit (and Loss) Targets question

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

    #31
    I will continue to document what I see now with the addition of Print statement data, but what I have observed from the beginning is that the Bool is properly being set to False yet the strategy continues to enter new trades while the bool is false. I'm concerned it is because at the close of the Bar which causes the bool=False it also simultaneously enters a new trade and does not seem to have time to 'realize' that the bool=false.

    The strategy is set to go long when 'green is below red' and go short when 'green is above red'

    I'll keep testing with live data but also may try to test via simulated feed data as well.

    Comment


      #32
      Paul, I think we have some data to work with and I'd appreciate your help interpreting it.

      Below is a section of the Output data (which has added notes from me 'RB') that I believe shows the issue, I have attached the rest of the data file as a text file here 20191115-Output-of-EMA-RB41-Output-test-with-error.txt .

      Where there are vertical spaces between the lines is where I have made edits and removed other data from other tests, I have also kept the raw data file as well if you want it (also attached) 20191115-RAW-Output-of-EMA-RB41-Output-test-with-error.txt .

      Just as a reminder of what we are looking for or trying to fix.
      I have a pertrade profit target and a pertrade stoploss target for the strategy as well as a persession profit target and per session stoploss target for the strategy.

      Once the persession target (either profit or stoploss) is reached then the trading is supposed to halt.
      This is not happening very well, it eventually does but not very close to the targets and the ones I'm most concerned about are the persession stoploss targets. It is OK if I end up with more money than expected for the persession profit targets. ;-)

      targets are set as follows:
      pertrade profit = +$300
      pertrade stoploss = -$300
      persession profit = +$500
      persession stoploss = -$500

      #####

      ((RB NOTE I can think of 4 ways that "PerSession UNRealizedPNL" = 0
      1, Trade is entered but has not moved and is at break even
      2, PerTrade Profit target of +$300 has been reached and trade is exited - not noted for some reason
      3, PerTrade Stoploss target of -$500 is reached and trade is exited
      4, PerSession Stoploss target of -$500 is reached and trade is exited

      there may be other reasons but that explains most of them I think

      search for the word "Suspect" and you will go right to the area I think shows the issue I am experiencing))

      ###

      11/15/2019 7:57:07 AM Strategy 'RB41-Output-test/183068400': Entered internal SubmitOrderManaged() method at 11/15/2019 7:57:07 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='XoverShort' FromEntrySignal=''
      | EMA41 Time/date = 11/15/2019 7:57:07 AM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -479.99999999999 | EMA41 PerTrade UNRealizedPNL = -260.000000000005


      ((RB NOTE this is a suspect area as the trading via strategy should have stopped once PerSession RealizedPNL exceeded -$500 per the PerSession StopLossTarget of -$500 - NOTE that bool is now FALSE yet trading continues))

      11/15/2019 7:57:07 AM Strategy '183068400/RB41-Output-test: Cancelled pending exit order, since associated position is closed, orderId='9c589cb2cc63445e992806c3b24fe658' account='Sim101' name='Profit target' orderState=Working instrument='CL 12-19' orderAction=Sell orderType='Limit' limitPrice=57.11 stopPrice=0 quantity=2 tif=Gtc oco='2c53199e23874b06a90970c64590b503' filled=0 averageFillPrice=0 onBehalfOf='' id=106950 time='2019-11-15 07:40:55' gtd='2099-12-01' statementDate='2019-11-15'



      | EMA41 Time/date = 11/15/2019 7:58:57 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -739.999999999995 | EMA41 PerTrade UNRealizedPNL = -40.0000000000063
      | EMA41 Time/date = 11/15/2019 8:00:41 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -739.999999999995 | EMA41 PerTrade UNRealizedPNL = -120.000000000005
      | EMA41 Time/date = 11/15/2019 8:02:06 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -739.999999999995 | EMA41 PerTrade UNRealizedPNL = -159.999999999997



      | EMA41 Time/date = 11/15/2019 8:02:54 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -739.999999999995 | EMA41 PerTrade UNRealizedPNL = -219.999999999999


      | EMA41 Time/date = 11/15/2019 8:03:29 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -1039.99999999999 | EMA41 PerTrade UNRealizedPNL = 0
      11/15/2019 8:03:35 AM Strategy 'RB4EMA-Test8-233tick/183068256': Entered internal SubmitOrderManaged() method at 11/15/2019 8:03:35 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='XoverLong' FromEntrySignal=''

      ((RB NOTE for some reason it now is respecting the halt of strategy trades it appears))

      | EMA41 Time/date = 11/15/2019 8:04:20 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -1039.99999999999 | EMA41 PerTrade UNRealizedPNL = 0
      | EMA41 Time/date = 11/15/2019 8:05:11 AM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -1039.99999999999 | EMA41 PerTrade UNRealizedPNL = 0

      Comment


        #33
        Hello RonnieB,

        Thanks for your post.

        What I see is that the bool OktoTrade is false which would be expected based on your PNL values and limits

        This then suggests that your entry conditions are not correctly set to test for Oktotrade to be true.

        In your sets that place entry orders, I would add a print statement that again includes the time, the set number for reference and the state of the bool.

        Alternatively, you may want to create a single entry strategy as simple as can be and test your pnl logic there first.
        Paul H.NinjaTrader Customer Service

        Comment


          #34
          Thanks Paul,
          I really do appreciate your advice.
          Can you tell me what this means?...

          11/15/2019 7:57:07 AM Strategy '183068400/RB41-Output-test: Cancelled pending exit order, since associated position is closed, orderId='9c589cb2cc63445e992806c3b24fe658' account='Sim101' name='Profit target' orderState=Working instrument='CL 12-19' orderAction=Sell orderType='Limit' limitPrice=57.11 stopPrice=0 quantity=2 tif=Gtc oco='2c53199e23874b06a90970c64590b503' filled=0 averageFillPrice=0 onBehalfOf='' id=106950 time='2019-11-15 07:40:55' gtd='2099-12-01' statementDate='2019-11-15'
          I will work on adding some type of Print statement in the Entry Order Sets (and may make a very simple strategy test with as simple as can be parameters), but it would be helpful to know what the above statement means since it happened at the time that the bool was changed from true to false. Plus if you have looked at the data, you can see that more than one trade was placed AFTER the bool was set to be false, i.e. the trade at 8:03:35 AM should not have happened.

          Comment


            #35
            Hello RonnieB,

            Thanks for your reply.

            The order entry/exit messages are not needed for your debugging of the bool state.

            The message is advising that the Profit order was cancelled because the position that it was associated with has been closed. The Stop loss and Profit target are O-CO tied, meaning when one is filled the other is automatically canceled.
            Paul H.NinjaTrader Customer Service

            Comment


              #36
              Perhaps I misunderstood...
              In your sets that place entry orders, I would add a print statement that again includes the time, the set number for reference and the state of the bool.
              This is what I am doing... adding the Print data in the sets that 1) place the entry orders and 2) verify the bool status (in theory before they place the orders)

              Isn't that what you are suggesting I do as quoted here?
              Attached Files

              Comment


                #37
                Hello RonnieB,

                Thanks for your reply.

                From a debugging perspective, what you want to do it to have an empty set (the last set) with no conditions and print out the time and all of the variables of interest so that you can see bar by bar what is happening. From that information, you would then review down into where the bool is not showing correctly and add further print statements in the sets which is why i recommend adding the set number to distinguish where the print statement comes from and gives you a sequence (IE was true in Set1 then false in set 4, etc.).

                Again you may want to create a very simple strategy with just a single order entry and the PNL criteria to minimize the distractions. Once you have that working correctly that may help you with what you ultimately want.
                Paul H.NinjaTrader Customer Service

                Comment


                  #38
                  Hi Paul,
                  I have attached an output 'printout' which shows the 'suspect area' where the Session Stop of -500 was breached but the strategy took a new trade (BuyToCover) at approx 11/20/2019 10:03:22 AM while the PerSession RealizedPNL = -540.

                  Look for Notes '((RB NOTE ' in the attached file

                  In this case, the trade taken by the strategy when the bool=False ended up as a positive trade making the PerSession RealizedPNL = -240 and then it appears to have stopped taking trades as the bool remained False even though the new PerSession RealizedPNL = -540 was 'more than' the trigger amount of -500.

                  See uploaded screenshot for more details

                  Does this help us figure out what is going on?
                  If this is not sufficient to figure out what the problem is, please advise as to what other items to include in the print statement to better understand what is going on.
                  Thanks in advance,
                  Ronnie
                  Attached Files

                  Comment


                    #39
                    Hello RonnieB,

                    Thanks for your reply.

                    Nice work with the print statements.

                    In this line: | EMA41 Time/date = 11/20/2019 10:03:22 AM | EMA41 Bool OKtoTrade = True | we see that EMA41 PerSession RealizedPNL = -380.000000000038
                    On this line: EMA41 Time/date = 11/20/2019 10:04:47 AM | EMA41 Bool OKtoTrade = False we see that EMA41 PerSession RealizedPNL = -540.000000000035

                    So this confirms that the bool is being set to false correctly based on your condition of PerSession StopLossTarget = -500 The bool remains false for the rest of the lines you printed, so the bool is not being unintentional reset to true.

                    Do you have OktoTrade = true as an entry condition in every set where you place entry orders?



                    Paul H.NinjaTrader Customer Service

                    Comment


                      #40
                      Thanks Paul,
                      YES all the places that place orders include verification that the bool 'OKtoTrade' = True in order to place an order.
                      To verify I checked all the pertinent screens in the strategy builder and attached screenshots for you to see in case I'm missing something.

                      I assume in set 1 and set 2 (the ones that matter most re. placing orders IMO) that the conditions listed to ALL be satisfied do not matter the order in which they occur (i.e. moving the bool check above the CrossAbove statement) does not matter, correct?

                      Attached Files

                      Comment


                        #41
                        adding 1 more screenshot since I was limited to 5 uploads per post...
                        Attached Files

                        Comment


                          #42
                          Hello RonnieB,

                          Thanks for your replies and screenshot.

                          Please move Set 3 to be the first set. (Left click on the set tab and hold, drag to the left and let go to move the set).

                          This will update the bool when the PNL is above or below before getting to the entry sets. As is it would set the bool after a trade has already been made.



                          Paul H.NinjaTrader Customer Service

                          Comment


                            #43
                            AWESOME!
                            I've moved set3 to be set1, redid the print statements to ref. RB43 (instead of RB42) and will test the new setup.
                            Thanks so much for your help here, hopefully this does the trick for now and I can move to the next adjustment(s).
                            I'll let you know
                            Ronnie

                            Comment


                              #44
                              Here is the latest, is there any way to keep the losses closer to the target whilst still doing the calc on bar close?
                              i.e. 'watch' the price and when it goes below the session loss target exit all trades for the strategy?

                              | EMA41 Time/date = 11/20/2019 2:56:01 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -200.000000000003 | EMA41 PerTrade UNRealizedPNL = -19.999999999996
                              | EMA41 Time/date = 11/20/2019 2:57:37 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -200.000000000003 | EMA41 PerTrade UNRealizedPNL = -79.9999999999983
                              | EMA41 Time/date = 11/20/2019 2:59:06 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -200.000000000003 | EMA41 PerTrade UNRealizedPNL = -120.000000000005
                              11/20/2019 2:59:22 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Entered internal SubmitOrderManaged() method at 11/20/2019 2:59:22 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='XoverShort' FromEntrySignal=''
                              |$| EMA43 Time/date= 11/20/2019 2:59:16 PM Set#2(short) OKtoTrade bool= True
                              | EMA41 Time/date = 11/20/2019 2:59:16 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -200.000000000003 | EMA41 PerTrade UNRealizedPNL = -99.9999999999943
                              11/20/2019 2:59:22 PM Strategy '183068452/RB43EMAxoverOUTPUT: Cancelled pending exit order, since associated position is closed, orderId='452093e1bf4644a8b0fbba783c11f1ee' account='Sim101' name='Profit target' orderState=Working instrument='CL 01-20' orderAction=Sell orderType='Limit' limitPrice=57.29 stopPrice=0 quantity=2 tif=Gtc oco='09d6317b12f741f4be90307f1893bb39' filled=0 averageFillPrice=0 onBehalfOf='' id=107649 time='2019-11-20 14:22:14' gtd='2099-12-01' statementDate='2019-11-20'
                              11/20/2019 2:59:22 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Amended stop order orderId='fe1b3e4923a04c41a9effb18dd9d806f' account='Sim101' name='Stop loss' orderState=Submitted instrument='CL 01-20' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=57.24 quantity=1 tif=Gtc oco='2a55e2a41bb041f3897b63c34adb9185' filled=0 averageFillPrice=0 onBehalfOf='' id=107652 time='2019-11-20 14:59:22' gtd='2099-12-01' statementDate='2019-11-20'
                              11/20/2019 2:59:22 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Amended target order orderId='b7c74404fc8e48a59f06f486a09aa742' account='Sim101' name='Profit target' orderState=Submitted instrument='CL 01-20' orderAction=BuyToCover orderType='Limit' limitPrice=56.94 stopPrice=0 quantity=1 tif=Gtc oco='2a55e2a41bb041f3897b63c34adb9185' filled=0 averageFillPrice=0 onBehalfOf='' id=107653 time='2019-11-20 14:59:22' gtd='2099-12-01' statementDate='2019-11-20'
                              11/20/2019 2:59:30 PM CancelAllOrders: BarsInProgress=0
                              11/20/2019 2:59:30 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Entered internal SubmitOrderManaged() method at 11/20/2019 2:59:30 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='Exit on session close' FromEntrySignal=''
                              | EMA41 Time/date = 11/20/2019 2:59:59 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 4:00:00 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 4:00:02 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 4:00:05 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 4:00:23 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0


                              ((RB NOTE truncated to limit characters here in this post....))

                              | EMA41 Time/date = 11/20/2019 4:35:38 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 4:39:25 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              11/20/2019 4:42:31 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Entered internal SubmitOrderManaged() method at 11/20/2019 4:42:31 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='XoverLong' FromEntrySignal=''
                              |$| EMA43 Time/date= 11/20/2019 4:42:29 PM Set#3(long) OKtoTrade bool= True
                              | EMA41 Time/date = 11/20/2019 4:42:29 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = 0
                              11/20/2019 4:42:31 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Amended stop order orderId='5a7304107e404711b91f2ee747c07b9f' account='Sim101' name='Stop loss' orderState=Submitted instrument='CL 01-20' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=56.9 quantity=1 tif=Gtc oco='044770cc6a7c4c219db1bf7a3f388e44' filled=0 averageFillPrice=0 onBehalfOf='' id=107656 time='2019-11-20 16:42:31' gtd='2099-12-01' statementDate='2019-11-20'
                              11/20/2019 4:42:31 PM Strategy 'RB43EMAxoverOUTPUT/183068452': Amended target order orderId='0623356b123544b9ac5d8549f0105168' account='Sim101' name='Profit target' orderState=Submitted instrument='CL 01-20' orderAction=Sell orderType='Limit' limitPrice=57.2 stopPrice=0 quantity=1 tif=Gtc oco='044770cc6a7c4c219db1bf7a3f388e44' filled=0 averageFillPrice=0 onBehalfOf='' id=107657 time='2019-11-20 16:42:31' gtd='2099-12-01' statementDate='2019-11-20'
                              | EMA41 Time/date = 11/20/2019 4:47:08 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -59.9999999999881
                              | EMA41 Time/date = 11/20/2019 4:48:22 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -140.000000000001
                              | EMA41 Time/date = 11/20/2019 4:55:45 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -159.999999999997
                              | EMA41 Time/date = 11/20/2019 5:01:40 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -140.000000000001
                              | EMA41 Time/date = 11/20/2019 5:02:58 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -179.999999999993
                              | EMA41 Time/date = 11/20/2019 5:04:16 PM | EMA41 Bool OKtoTrade = True | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -319.999999999993 | EMA41 PerTrade UNRealizedPNL = -239.999999999995
                              | EMA41 Time/date = 11/20/2019 5:06:24 PM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -619.99999999999 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 5:08:43 PM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -619.99999999999 | EMA41 PerTrade UNRealizedPNL = 0
                              | EMA41 Time/date = 11/20/2019 5:10:26 PM | EMA41 Bool OKtoTrade = False | EMA41 PerSession StopLossTarget = -500 | EMA41 PerSession RealizedPNL = -619.99999999999 | EMA41 PerTrade UNRealizedPNL = 0

                              Comment


                                #45
                                See screenshot and attached Print log...
                                Why is this still in a short trade when the Bool=False and the bar has closed multiple times in that state?
                                Shouldn't the trade exit after just 1 bar close when the bool=false?
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by arvidvanstaey, Today, 02:19 PM
                                4 responses
                                10 views
                                0 likes
                                Last Post arvidvanstaey  
                                Started by samish18, 04-17-2024, 08:57 AM
                                16 responses
                                56 views
                                0 likes
                                Last Post samish18  
                                Started by jordanq2, Today, 03:10 PM
                                2 responses
                                8 views
                                0 likes
                                Last Post jordanq2  
                                Started by traderqz, Today, 12:06 AM
                                10 responses
                                18 views
                                0 likes
                                Last Post traderqz  
                                Started by algospoke, 04-17-2024, 06:40 PM
                                5 responses
                                47 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Working...
                                X