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

multiple stops and profit targets

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

    multiple stops and profit targets

    Hi

    I am having a very frustrating time getting more than one stoploss or profit target to be activated. I have created a a test strategy to try and solve this issue and it has come pretty close but with no consistency, I need to when working apply this to a real strategy which has the same issue..

    I am creating 2 entry orders of 1 lot each, there then should be 2 stoploss entries with unique signal name and 2 profit target orders again with unique signal names.

    I have observed that both entries are done correctly but when setting the SL and PT orders I have seen the following, from a PRINT statement:
    B stopOrder = orderId='a6558f00d4684659b8dd529d2db716dd' account='Sim101' name='Stop' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1.29184 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=252 time='2017-05-11 12:42:26' gtd='2099-12-01' statementDate='2017-05-11'

    B targetOrder = orderId='ccbd6b1e8ae7435493bc9b2169fc24cd' account='Sim101' name='Target' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Limit' limitPrice=1.29244 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=253 time='2017-05-11 12:42:26' gtd='2099-12-01' statementDate='2017-05-11'

    B stopOrder2 =
    B targetOrder2 =
    *******************************
    These all follow one after the other and as you can see the first orders are fine but the other 2 are not "actioned". I have then seen it on a different entry where it activates all stoploss and profit target orders, but never from the first entry order, as below....

    B stopOrder = orderId='551f0ea2a0024ef8a1d6c0733b284440' account='Sim101' name='Stop' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1.29228 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=268 time='2017-05-11 12:54:47' gtd='2099-12-01' statementDate='2017-05-11'
    B targetOrder = orderId='3085591385d3497cb54b4a5c81adcbcd' account='Sim101' name='Target' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Limit' limitPrice=1.29288 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=269 time='2017-05-11 12:54:47' gtd='2099-12-01' statementDate='2017-05-11'
    B stopOrder2 =
    B targetOrder2 =


    B stopOrder = orderId='551f0ea2a0024ef8a1d6c0733b284440' account='Sim101' name='Stop' orderState=ChangeSubmitted instrument='GBPUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1.29245 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=268 time='2017-05-11 12:55:14' gtd='2099-12-01' statementDate='2017-05-11'

    B targetOrder = orderId='3085591385d3497cb54b4a5c81adcbcd' account='Sim101' name='Target' orderState=ChangeSubmitted instrument='GBPUSD' orderAction=Sell orderType='Limit' limitPrice=1.29305 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=269 time='2017-05-11 12:55:14' gtd='2099-12-01' statementDate='2017-05-11'

    B stopOrder2 = orderId='3fc2f1f6d3be48ad80f02f5fcb6caa03' account='Sim101' name='Stop2' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=1.29245 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=272 time='2017-05-11 12:55:14' gtd='2099-12-01' statementDate='2017-05-11'

    B targetOrder2 = orderId='b384424293474b4b956c93adb111b9d3' account='Sim101' name='Target2' orderState=Submitted instrument='GBPUSD' orderAction=Sell orderType='Limit' limitPrice=1.29325 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=273 time='2017-05-11 12:55:14' gtd='2099-12-01' statementDate='2017-05-11'



    I have also set the entries per direction up to 6 and 10 with unique entries, option, because I am running out of ideas to solve it.

    I have attached the test code strategy and any help will be greatly appreciated.

    Thanks
    Attached Files

    #2
    We will be happy to answer any questions that come up. Since your strategy does several things to manage trades, which adds many points which could cause the behavior you are observing, I have started instead with a known good point. I have built and tested a modified version of this code sample.



    The modified version has 10 stop loss and profit target levels attached to 10 different entries. Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hi Jessica

      Thanks for this.

      Do you have examples that use working orders, eg EnterLongStopMarket. Because as soon as I try to swap the market entries over to working orders it all stops working. I get only "stops" being created.

      So for example I would want both orders to be actioned at the same time, (this works), a few pips above or below the market depending on them being buys or sells.

      Only when the working orders are hit would I want the stops and targets to be connected to the entries. I just cannot understand why the second stops / targets are not initiated as they are meant to be activated immediately after the first set of stops/ targets are initiated.

      I understand there could be reasons why they are not activated but surely the fact they are coded to happen one after the other, and the only difference is the target or loss value and there names, means there should be some record of them being processed.

      Thanks

      Comment


        #4
        I'll be happy to help fishbed. When we put this strategy together, we do need to keep a few rules in mind.

        Originally posted by http://ninjatrader.com/support/helpGuides/nt8/en-us/managed_approach.htm
        Internal Order Handling Rules that Reduce Unwanted Positions

        To prevent situations in real-time in which you may have multiple orders working to accomplish the same task, there are some "under the hood" rules that a NinjaScript strategy follows when Managed order methods are called. For example, if your strategy had a limit order for 1 contract working as a Profit Target, but then your strategy was also programmed to reverse the position at the price very close to the target limit order, then submitting both orders can be risky, since it could lead to a larger position than the strategy is designed to enter if both orders got filled in quick succession by the exchange.



        Note: These rules do not apply to market orders, such as ExitLong() or ExitShort().



        For the most part, you do not need to be intimately familiar with these rules as you develop your strategies. It is all taken care of for you internally within a strategy. If a rule is violated, you will be notified through an error log in the Control Center Log tab.



        Note: To prevent excessive logging which could degrade performance, you will only be notified of the very first order which has violated an order handling rule. Subsequent orders which violate a rule will not be notified through the error log.



        The following rules are true per unique signal name:



        Methods that generate orders to enter a position will be ignored if:
        • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
        • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
        • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
        • The entry signal name is not unique



        Methods that generate orders to exit a position will be ignored if:
        • A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
        • A position is open and an order submitted by a set method (SetStopLoss() for example) is active



        Set() methods that generate orders to exit a position will be ignored if:
        • A position is open and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
        • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active
        If you have looked those over and you are pretty sure your strategy doesn't do any of these things, could you post a modified version of the strategy I sent you with the changes in logic you made to cause it to submit working orders? This will help us determine what's happening and how to work around it.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          SampleMonitorStopProfit.cs Compatibility for NT8

          Originally posted by NinjaTrader_JessicaP View Post
          We will be happy to answer any questions that come up. Since your strategy does several things to manage trades, which adds many points which could cause the behavior you are observing, I have started instead with a known good point. I have built and tested a modified version of this code sample.



          The modified version has 10 stop loss and profit target levels attached to 10 different entries. Please let us know if there are any other ways we can help.
          Hi Jessica,
          I've downloaded your script but in my case it's incompatible with nt8 version I'm using [8.0.6.1 64-bit (Multi-Broker)]. Is there a way to walk around this problem?
          Thanks
          Best,
          Pantelis

          Comment


            #6
            Thank you for your question pantelist. Can you use the attached instructions to generate a report that will show what happens when you attempt to use the script?
            Attached Files
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_JessicaP View Post
              Thank you for your question pantelist. Can you use the attached instructions to generate a report that will show what happens when you attempt to use the script?
              Thanks for the quick reply Jessica!
              Here how it goes to clarify things a bit.
              1a) First I've placed manually the file-script because nt8 import could not recognize any .cs file where I'd saved it in my pc.
              1b) After that I opened it with nt8 script editor, pressed compile and no error -as seen on your image- came up ... instead, a beep sound was played and you can see in the image (#1) what it was found .. if any.
              2) After that I made a zip file with your script and asked nt8 to import it, when I've got the warning you can see in the 2nd image (#2) -- which I guess means that if the script was from start in a zip file, NT8 would not accept it in the first place due to incompatibility.
              I do not know if that helps but I hope it does as I'm completely new in NT platform plus I have no idea about coding.
              Thanks again
              P.

              PS: Forgot to mention that "export" feature was not presented as an option in script editor for this script.(Image #3)

              Image #1:

              Image #2:

              Image #3:
              Attached Files
              Last edited by pantelist; 05-15-2017, 03:43 PM.

              Comment


                #8
                I'm unsure why you were unable to load the script, but I was able to load it into 8.0.6.1 . I have exported this tool as a zip archive which you may have an easier time importing. Please delete any existing versions of this tool on your system before importing the one in this zip.
                Attached Files
                Jessica P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_JessicaP View Post
                  I'm unsure why you were unable to load the script, but I was able to load it into 8.0.6.1 . I have exported this tool as a zip archive which you may have an easier time importing. Please delete any existing versions of this tool on your system before importing the one in this zip.
                  Thank you very much Jessica; your zip installed just fine.
                  Your help is appreciated a lot.
                  Have a great day
                  Best,
                  P.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by maybeimnotrader, Yesterday, 05:46 PM
                  4 responses
                  23 views
                  0 likes
                  Last Post maybeimnotrader  
                  Started by frankthearm, Today, 09:08 AM
                  6 responses
                  25 views
                  0 likes
                  Last Post frankthearm  
                  Started by adeelshahzad, Today, 03:54 AM
                  5 responses
                  33 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by stafe, 04-15-2024, 08:34 PM
                  7 responses
                  32 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by merzo, 06-25-2023, 02:19 AM
                  10 responses
                  824 views
                  1 like
                  Last Post NinjaTrader_ChristopherJ  
                  Working...
                  X