Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy moving profit target

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

    Strategy moving profit target

    Good evening,

    I have been testing my strategy live and have noticed that it is moving my profitTarget orders by itself. Order management is using the managed approach and never is the profit target changed once placed. Here are the logs:

    HTML Code:
    2023-09-25 19:40:22:631|1|32|Order='c9046b6bfebc4113842e60185dd40891/SimLongSim' Name='Supply Entry 1989' New state='Partially filled' Instrument='NQ DEC23' Action='Sell short' Limit price=14861.75 Stop price=0 Quantity=3 Type='Limit' Time in force=GTC Oco='' Filled=1 Fill price=14861.75 Error='No error' Native error=''
    2023-09-25 19:40:22:632|1|8|Execution='8cd1a360c91540b5a32a4d7768f0c8ff' Instrument='NQ DEC23' Account='SimLongSim' Exchange=Default Price=14861.75 Quantity=1 Market position=Short Operation=Operation_Add Order='c9046b6bfebc4113842e60185dd40891' Time='9/25/2023 7:40 PM'
    2023-09-25 19:40:22:632|1|16|NinjaScript strategy 'TestStrategy/307116401' submitting order
    2023-09-25 19:40:22:632|1|32|Order='eddbf2ffb726444d8e2dfb070e5542dc/SimLongSim' Name='Stop loss' New state='Trigger pending' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 19:40:22:632|1|16|NinjaScript strategy 'TestStrategy/307116401' submitting order
    2023-09-25 19:40:22:650|1|32|Order='c978a4731c1e49e58fdc2469b413ea61/SimLongSim' Name='Profit target' New state='Submitted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=1 Type='MIT' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 19:40:22:650|1|64|Instrument='NQ DEC23' Account='SimLongSim' Average price=14861.75 Quantity=1 Market position=Short Operation=Operation_Add
    2023-09-25 19:40:22:756|1|32|Order='c978a4731c1e49e58fdc2469b413ea61/SimLongSim' Name='Profit target' New state='Accepted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=1 Type='MIT' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 19:40:32:244|1|32|Order='c9046b6bfebc4113842e60185dd40891/SimLongSim' Name='Supply Entry 1989' New state='Filled' Instrument='NQ DEC23' Action='Sell short' Limit price=14861.75 Stop price=0 Quantity=3 Type='Limit' Time in force=GTC Oco='' Filled=3 Fill price=14861.75 Error='No error' Native error=''
    2023-09-25 19:40:32:244|1|8|Execution='ae1b3784253b4fa4b61e54b4d82cc6b3' Instrument='NQ DEC23' Account='SimLongSim' Exchange=Default Price=14861.75 Quantity=2 Market position=Short Operation=Operation_Add Order='c9046b6bfebc4113842e60185dd40891' Time='9/25/2023 7:40 PM'
    2023-09-25 19:40:32:244|1|16|NinjaScript strategy 'TestStrategy/307116401' submitting order
    2023-09-25 19:40:32:244|1|32|Order='541971a0f553412ca6852949f1794f90/SimLongSim' Name='Stop loss' New state='Trigger pending' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=2 Type='Stop Market' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 19:40:32:244|1|16|NinjaScript strategy 'TestStrategy/307116401' submitting order
    2023-09-25 19:40:32:257|1|32|Order='b110d771b22a460985752965098c5725/SimLongSim' Name='Profit target' New state='Submitted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=2 Type='MIT' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 19:40:32:257|1|64|Instrument='NQ DEC23' Account='SimLongSim' Average price=14861.75 Quantity=3 Market position=Short Operation=Update
    2023-09-25 19:40:32:370|1|32|Order='b110d771b22a460985752965098c5725/SimLongSim' Name='Profit target' New state='Accepted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=2 Type='MIT' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    // Although the order 'Profit target' was set to 14399.75 in this short, it somehow moved itself and updated to 14860 (Seen below).
    2023-09-25 20:00:00:296|1|32|Order='c978a4731c1e49e58fdc2469b413ea61/SimLongSim' Name='Profit target' New state='Working' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=1 Type='MIT' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:296|1|32|Order='b110d771b22a460985752965098c5725/SimLongSim' Name='Profit target' New state='Working' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=2 Type='MIT' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:310|1|32|Order='c978a4731c1e49e58fdc2469b413ea61/SimLongSim' Name='Profit target' New state='Filled' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=1 Type='MIT' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=1 Fill price=14860 Error='No error' Native error=''
    2023-09-25 20:00:00:311|1|32|Order='eddbf2ffb726444d8e2dfb070e5542dc/SimLongSim' Name='Stop loss' New state='Cancel submitted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:311|1|32|Order='eddbf2ffb726444d8e2dfb070e5542dc/SimLongSim' Name='Stop loss' New state='Cancelled' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=1 Type='Stop Market' Time in force=GTC Oco='8cd1a360c91540b5a32a4d7768f0c8ff' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:311|1|8|Execution='54260f0901b14be886b4f68bdfd363ef' Instrument='NQ DEC23' Account='SimLongSim' Exchange=Default Price=14860 Quantity=1 Market position=Long Operation=Operation_Add Order='c978a4731c1e49e58fdc2469b413ea61' Time='9/25/2023 8:00 PM'
    2023-09-25 20:00:00:311|1|64|Instrument='NQ DEC23' Account='SimLongSim' Average price=14861.75 Quantity=2 Market position=Short Operation=Update
    2023-09-25 20:00:00:345|1|32|Order='b110d771b22a460985752965098c5725/SimLongSim' Name='Profit target' New state='Filled' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14399.75 Quantity=2 Type='MIT' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=2 Fill price=14860 Error='No error' Native error=''
    2023-09-25 20:00:00:345|1|32|Order='541971a0f553412ca6852949f1794f90/SimLongSim' Name='Stop loss' New state='Cancel submitted' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=2 Type='Stop Market' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:345|1|32|Order='541971a0f553412ca6852949f1794f90/SimLongSim' Name='Stop loss' New state='Cancelled' Instrument='NQ DEC23' Action='Buy to cover' Limit price=0 Stop price=14869.25 Quantity=2 Type='Stop Market' Time in force=GTC Oco='ae1b3784253b4fa4b61e54b4d82cc6b3' Filled=0 Fill price=0 Error='No error' Native error=''
    2023-09-25 20:00:00:345|1|8|Execution='3e519b1acee4441b8277ad07e75e4130' Instrument='NQ DEC23' Account='SimLongSim' Exchange=Default Price=14860 Quantity=2 Market position=Long Operation=Operation_Add Order='b110d771b22a460985752965098c5725' Time='9/25/2023 8:00 PM'
    2023-09-25 20:00:00:345|1|64|Instrument='NQ DEC23' Account='SimLongSim' Average price=0 Quantity=0 Market position=Flat Operation=Remove​
    Any ideas why this could be happening?

    #2
    Hello jrebollar,

    How are you submitting the target? If your logic is calling the target again that will resubmit the order and change the existing one. If you can provide more detail on what code you tried that would help to narrrow down the problem.

    Comment


      #3
      Good morning Jesse,
      I am submitting the target using SetProfitTarget. No where in my code do I change my target. I do have a variable for profit target that I use to check if it's null/update to GetRealtimeOrder. Other than that, the profit target is unchanged throughout my code.

      Comment


        #4
        Hello jrebollar,

        We would need to see the logic you are using to be able to understand what may be happening. Again if you call the order method again that's going to update the order, that would be expected if your logic is calling the order more than one time.

        Comment


          #5
          Sure, here are the sequence of events in my strategy's logic:
          1. An order is placed with either the EnterLongLimit/EnterShortLimit commands with quantity 3, accompanied by SetStopLoss and SetProfitTarget like an OCO.
          2. Throughout the way to the profit target, the strategy has take profit logic that takes 1 at each of these targets using ExitLong/ExitShort.
          Nowhere in between do I change the profit target order unless its to convert it GetRealtimeOrder. The logs above, are event by event of what happens. It doesn't state why the profit target changed. It changed and took profit in the same second.

          Here is how I set profit target
          Code:
          SetProfitTarget(orderName, CalculationMode.Price, (Math.Abs(zoneRange[0] - zoneRange[1]) * profitTarget) + zoneRange[0], true);
          The profit target is based off of risk/reward and shouldn't have changed to take profit immediately after it had entered.

          Comment


            #6
            Hello jrebollar,

            To change the target you just need to call SetProfitTarget again, if your logic is calling that method again then you should see the target getting updated. Unfortunately this does not help because I cant see where you are calling the method in your logic to know if that may be happening. To further diagnose the problem you will need to add prints and make sure that method is only called once before you call your entry order.

            Comment


              #7
              Good point on the print statements for debugging. I only call SetProfitTarget twice in the script and those are for Long/Short respectively. Those two functions are locked behind a if statement stating that it must be flat in order to make any changes. I've had my orders go to profit target before, I'm just wondering why this is happening now.

              Comment


                #8
                Hello jrebollar,

                I really wouldn't be able to say without seeing the actual code and where you called it, prints are the easiest way to confirm the method is being called only once. Generally you put the target with your entry order to make sure its called first. Your logic would usually look like this:

                SetProfitTarget(...)
                EnterLongLimit(...)

                If you are not using live until cancelled for the entry order you would then need to seperate the target into its own condition so its only called once before the EnterLongLimit is called for the first time.

                Comment


                  #9
                  Ah, I actually have the SetProfitTarget and SetStopLoss after the order is placed. Could this result in this issue happening?

                  Comment


                    #10
                    Hello jrebollar,

                    That would usually just cause old prices to be used but would not cause additional updates unless that is being called multiple times. The reason to call the targets first is to make sure the newly calculated price is used for the upcoming order which will be filling. Once the entry order fills it will trigger the target. If you continue to call the target order method it will resubmit it at that point with the new price at that time.

                    Comment


                      #11
                      Understood. In the guide's notes it mentions, "Should you have multiple Bars objects of the same instrument while using SetProfitTarget() in your strategy, you should only submit orders for this instrument to the first Bars context of that instrument. This is to ensure your order logic is processed correctly and any necessary order amendments are done properly." This means if I have 4 data series being referenced, I should submit orders based on the first referenced data series? The one more precise?

                      Comment


                        #12
                        Hello jrebollar,

                        That note is to ensure that the target is processed in the correct order, that would not relate to calling the target again to update it later. You would still need to try using a print to verify the order method is only being called a single time.

                        Comment


                          #13
                          Okay, I'm not home now. Will send a skeleton of my strategy where all order methods are called then.

                          Comment


                            #14
                            Hello jrebollar,

                            When you get home try to add prints into your existing script before making a test script, prints will let you easily see if that logic is being called more than one time.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by NullPointStrategies, Today, 05:17 AM
                            0 responses
                            50 views
                            0 likes
                            Last Post NullPointStrategies  
                            Started by argusthome, 03-08-2026, 10:06 AM
                            0 responses
                            126 views
                            0 likes
                            Last Post argusthome  
                            Started by NabilKhattabi, 03-06-2026, 11:18 AM
                            0 responses
                            69 views
                            0 likes
                            Last Post NabilKhattabi  
                            Started by Deep42, 03-06-2026, 12:28 AM
                            0 responses
                            42 views
                            0 likes
                            Last Post Deep42
                            by Deep42
                             
                            Started by TheRealMorford, 03-05-2026, 06:15 PM
                            0 responses
                            46 views
                            0 likes
                            Last Post TheRealMorford  
                            Working...
                            X