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

reset setstoploss

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

    reset setstoploss

    Hello,

    I have an error-message with an entry triggered in a script. I dont need to post the messages because I found out what is the reason:

    the script entered long in CL at 22.57 and I got the message that stopmarket and can not be above, clear of course. When going over the executions I recognized that this script has done a long entry at 22.97 today few hours ago. The stop wth 22.93 was from this entry it seems. Why isnt the script setting the appropriate stop for that trade when I have in the script in onececution "if (entryOrderLr1a == execution.Order)
    {
    if (execution.Order.OrderState == OrderState.Filled)
    {
    SetStopLoss("Lr1a", CalculationMode.Ticks, 4, false);
    SetProfitTarget("Lr1a", CalculationMode.Ticks, 4);
    ...

    Why is there the stop of the trade before with that script?

    Thank you!
    Tony

    #2
    Hello Tony,

    Thanks for your post.

    Set methods prep NinjaTrader to submit your stop loss or profit target when a Managed Approach order comes back as filled. They should not be used in OnExecutionUpdate.

    If you want to use OnExecutionUpdate to submit your stop loss, you will want to use Exit methods, or use the Unmanaged Approach if you want to include OCO functionality.

    An example that submits targets and stops in OnExecutionUpdate an be found here - https://ninjatrader.com/support/help...and_onexec.htm

    A strategy that modifies a stop loss dynamically by calling SetStopLoss in OnBarUpdate will need to call SetStopLoss when the strategy is flat, and before the next entry is submitted.

    Reset Stop Loss to initial level - https://ninjatrader.com/support/help...of_stop_lo.htm

    Please let us know if you have any questions.
    Last edited by NinjaTrader_Jim; 04-13-2020, 01:14 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello Jim,

      thank you for your reply. OK, but exit methods do not work OCO I recall from a prior thread.

      What is the best place to have setstoploss please (so that a.) its working correctly with every entry and the value in price or ticks it should have and b.) so that its there 100% and not having a naked trade: in initialize or onbarupate or....?

      Thank you!
      Tony

      Comment


        #4
        Hello Tony,

        Unmanaged Approach would need to be used for OCO since Exit methods do not use OCO

        SetStopLoss should be reset to an initial level when the strategy is flat and before the next entry is submitted. See the SamplePriceModification strategy linked in post #2. (2nd link.)

        Please let me know if you have questions on the linked examples.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello Jim,

          thank you for your reply. I do have the samples, I only was not aware that setstoploss does cause this false behavior with value from another trade.

          I do not have questions to the samples, I did my question above where to have setstoploss it the best way because I recall from a thread few years ago for NT7 that there are differences if it is in initialize or in onbarupdate and therefore I asked now to have it updated for NT8 and write to my notes.

          Thank you!
          Tony

          Comment


            #6
            Hello Tony,

            If you want the stop loss to be static, call SetStopLoss in State.Configure. If you need to update it in OnBarUpdate, please follow the SamplePriceModification example.

            Let me know if anything else needs clarification.
            JimNinjaTrader Customer Service

            Comment


              #7
              Hello Jim,

              I can not find the thread now from where I got the reply or idea to have setstoploss in onexecution as this is the most "save and accurate" (my words here as I recall the topic - and you know english is not my language) because it is set for sure with the entry. Therefore I have coded this in all scripts in onexecution.

              Let me ask this way please: when I continue with setstoploss in onexecution and I add in onbarupate "if ..flat then setstoploss(...ticks...) will this work ok (and will this work ok when the setstoploss has been modified in the trade before from ticks to price - when putting it above high or low of a bar)?

              It should (in my humble knowledge) do as you suggested to reset in onbarupdate and after the reset the difference from the samples is then that I do not have it onbarupdate (if..short/long then setstoploss) but in onexecution (which also allows me to handle it then in onbarupdate with bools)

              ??

              Thank you!
              Tony
              Last edited by tonynt; 04-14-2020, 02:43 AM. Reason: translation error

              Comment


                #8
                Hello Tony,

                I would advise against using it in OnExecutionUpdate since the method is designed to prep NinjaTrader for the submission of the stop loss when the entry comes back as filled, not to submit the stop loss once the strategy sees the execution of the entry order.

                If you do not want to update the Stop Loss dynamically, I.E. you just want a Calculation Mode of Ticks, I would suggest leaving the Set method in OnStateChange under State.Configure. If you are submitting a stop loss that would change dynamically, (I.E. calling SetStopLoss again for an auto breakeven/auto-trail, or if you want to place the stop loss using a Calculation Mode of Price) then SetStopLoss should be called in OnBarUpdate, and you should ensure that it is reset to an initial level when the strategy is flat and before the next entry is submitted. (See SamplePriceModification for an example.)

                Let me know if you have any additional questions.

                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hello Jim,

                  thank you for your reply. One question to the setstoploss in onbarupdate please: you write "... when the entry comes back as filled..." When the setstoploss is in Onbarupdate and the script is running with COBCtrue will then the stoploss ALWAYS be immediately after the entry or maybe only after close of bar, because of COBCtrue?

                  Thank you!
                  Tony

                  Comment


                    #10
                    Hello Tony,

                    The Set methods tell NinjaTrader to submit the order when NinjaTrader sees the order filled. The order will be submitted immediately by NinjaTrader and it will not wait for the bar to close.

                    We look forward to assisting.
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Aviram Y, 08-09-2023, 09:04 AM
                    10 responses
                    298 views
                    0 likes
                    Last Post MrHump
                    by MrHump
                     
                    Started by jpapa, Today, 07:22 AM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by kevinenergy, 02-17-2023, 12:42 PM
                    116 responses
                    2,758 views
                    1 like
                    Last Post kevinenergy  
                    Started by franatas, 12-04-2023, 03:43 AM
                    7 responses
                    106 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by Jltarrau, Today, 05:57 AM
                    3 responses
                    9 views
                    0 likes
                    Last Post Jltarrau  
                    Working...
                    X