Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss, SetProfitTarget modify

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

    SetStopLoss, SetProfitTarget modify

    Hello,

    when I use SetStopLoss in scriptstrategies (instead of ExitLongStop because of OCO string with SetStopLoss) is there a possibility to change stoploss (and SetProfitTarget) in orders tab with "+" and "-"?

    When I increase or decrease it then it jumps back immediately to the position referring the script. OK and clear. One possbililty would be to refer to an ATM in the script but is there a more easy solution for coding in script? I have a setstoploss in initialize and in onbarupdate. What if I move the SetStopLoss and SetProfitTarget to onexecution? It should stay then at the position I moved it in orders tab then during the trade, no?

    If it works this way, I want to ask if there is a possible disadvantage or problem when moving SetStoploss to onexecution from onbarupdate.

    Thanks
    Tony

    #2
    Hi Tony,

    A NinjaScript Strategy is not going to be aware of any changes outside of that instance of the script.

    When the order is getting moved back, likely this is because the script is repeatedly calling the code to place / modify that stop loss.

    Anytime you modify the stop loss in the script the order would get moved back.

    If you would like I can provide an example script that places stoploss and profit targets that you can move and will not be moved back.

    The example uses SetStopLoss and SetProfitTarget in Initialize and then places an order on the first tick of real-time data. Its a very simple script.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      thank you for your reply! Yes, please provide me the sample.

      (my idea with SetStopLoss and SetProfitTarget in OnExecution would not work? There would not be a "reaction" with onbarupdate, only with an Execution, no?)

      Thank you for your support!

      Best regards
      Tony
      Last edited by tonynt; 03-31-2016, 08:36 AM. Reason: translation error

      Comment


        #4
        Hello Tony,

        The stop loss will be created / modified any time you call it. If you want to call this in OnExecution it would be placed / modified when an order fills. This would be up to you. I've set them in Initialize and this seems to do the job. However, you can write your logic how it suits your needs.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          thank you for providing the sample. I have already the stop in Initialize as I wrote. This is the safest way to bring in stop in Initialize and then in OnBarupdate - with my understanding from a thread here in the forum. Would you trade with a script with SetStopLoss only in Initialize?

          Thank you
          Tony

          Comment


            #6
            Hello Tony,

            I am demonstrating that when the stop loss is called is important. The script shows that the behavior is not caused by NinjaTrader but is being caused by the logic in your script.

            Move the orders when you want them to be moved.

            Below is a link to a complex script I have made previously that shows how to move an order as a trail in both OnBarUpdate and OnMarketData.
            http://ninjatrader.com/support/forum...962#post388962
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              thank you for the link of the other thread and the sample - this is how I use the stops now for FX. (depending of certain distances to entry price and using flags). To understand this 100% and what I need for ES please let me jump back to the very simple script above with stops in Initialize only:

              A.) Is it necessary to have the stop also in another section of the script or is it OK to have SetStopLoss only in Initialize? Or is there any reason why stop should be also in another section of the script for safety reasons?

              B.) When modifying SetStopLoss in onExecution from the script (eg with fill of first target) then one can move the stop inside script with condition and from outside in orders tab, no? Of course with next condition in onExecution SetStoploss is modified from script. So, this would be the best of both because stop can be moved with conditions in script and also from outside in orders tab without script calling back stop immediately, no?

              Thanks
              Tony

              Comment


                #8
                Hello tonynt,

                When used in Initialize, SetStopLoss will be managed by NinjaTrader and will be at a fixed amount of ticks or price or percent depending on how it is called.

                When calling SetStopLoss in OnBarUpdate this allows the stop loss to move and can reset the order on each new tick.

                However, I checked out the behavior and inquiried with our lead who let me know it is expected that NinjaTrader will reset the stop and target on each tick automatically when using SetStopLoss and SetProfitTarget.

                This would cause any manual modifications to be undone.

                This means an Exit order should be used, or the unmanaged approach needs to be used to fully control the logic of the stop and target, or Atm Strategy methods could be used to place the orders.

                Attached is an unmanaged version that places a stop loss and profit target when the entry fills. These orders can be modified manually and will not revert to the original prices when the bar closes.
                Attached Files
                Last edited by NinjaTrader_ChelseaB; 04-21-2016, 07:29 AM.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello,

                  thank you for your reply. Its interesting that even when SeProfitTarget is only in onExectuion with fill of entry that it is moved back from script when I change it in orderstab - this move back occurs without an execution. (same in onOrderUpdate)

                  OK, so one can make the following workaround: set a double "profit1" in onExecution with entryprice+InitialProfitTarget and in the script also SetProfitTarget("entry1", CalculationMode.Price, profit1); with profit1=profit1-1*TickSize assigned to a button or horizontal line. This way SetProfitTarget can be moved from outside the script when it is called to action.

                  Best
                  Tony
                  Last edited by tonynt; 04-26-2016, 03:40 AM. Reason: clearifying

                  Comment


                    #10
                    To anyone following this thread:

                    I've made some small adjustments to this script to allow the script to work historically as well as continue to place orders after an Exit on close.
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      I resolved this in the meantime and it is working fine. Again, thank you for your reply.

                      I have another question concerning SetProfitTarget please (when I did the question one time in last 7 years I´m sorry that I didnt find the reply when searching for it):

                      I do the entry with only SetStopLoss. I want to bring in the SetProfitTarget by conditions (eg when cross of an MA and a cycle High then SetProfitTarget 1 Tick above close - this is just to show what I mean how to use).

                      The question is now when I bring in the SetProfitTarget "later" when already in the trade and not together with the entry, does this SetProfitTarget and the SetStoploss for the Position in concern work OCO (same as it would have been when both are there with the entry? Is there an OCO-string then same?

                      Thanks
                      Tony
                      Last edited by tonynt; 10-12-2016, 07:36 AM. Reason: Typing error

                      Comment


                        #12
                        Hello Tony,

                        When using SetProfitTarget or SetStopLoss you are using the managed approach; NinjaTrader will manage the orders for you.

                        Yes, the same OCO string will be used. This is out of your control when using the managed approach and will work automatically on its own.

                        Calling SetProfitTarget when the target is already working simply causes a change order to be submitted. The order will continue using the same OCO string as it was initially submitted with.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,

                          thank you for your reply. There´s a misunderstanding. Sorry if caused by an inaccurate translation from my side maybe.

                          I dont mean when the SetProfitTarget is already there. I wrote "when I bring in the SetProfitTarget by conditions". When doing the entry there is only the SetStoploss. When a certain condition is true then I bring in the SetProfitTarget (I can do, its not the question how to do this). The question is if this SetProfitTarget that has not been there before together with the entry - in one "entry-stop-target-familypack-OCO string" - will work correctly OCO with the corresponding Stop for the Position in concern (as it would have been there immediately with the entry).

                          Thank you
                          Tony
                          Last edited by tonynt; 10-12-2016, 11:28 AM. Reason: clearifiying

                          Comment


                            #14
                            Hello Tony,

                            Yes. NinjaTrader will use the same OCO string if you place a profit target some time after placing the stop loss.

                            This is all managed by NinjaTrader and NinjaTrader will correctly handle the OCO for these orders. You do not have to worry about this when using the managed approach.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by jjanguda, Today, 10:15 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post jjanguda  
                            Started by ScorpioTravis, Today, 09:41 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post ScorpioTravis  
                            Started by DTSSTS, Today, 09:41 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post DTSSTS
                            by DTSSTS
                             
                            Started by Segwin, Today, 06:33 PM
                            1 response
                            26 views
                            0 likes
                            Last Post NinjaTrader_ShawnB  
                            Started by bmaltz, Today, 08:14 PM
                            1 response
                            20 views
                            0 likes
                            Last Post NinjaTrader_ShawnB  
                            Working...
                            X