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 and SetProfitTarget

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

    Reset SetStopLoss and SetProfitTarget

    Hello,

    I´m experiencing issues with my orders because it occurs that I´m triggered immediately after entry with StopLoss of ProfitTarget. It seems that SetStopLoss and SetProfitTarget are not "reset" after a trade (sometimes?) so that the next trade there are wrong doubles for the Stop and the Target.

    I have SetStopLoss() and SetProfitTarget in State.Configure and also in OnBarupdate with eg
    if (Positions[1].MarketPosition != MarketPosition.Short)
    {SetStopLoss("Sba1a", CalculationMode.Ticks, 5, false);
    SetStopLoss("Sba1b", CalculationMode.Ticks, 5, false);
    SetProfitTarget("Sba1a", CalculationMode.Ticks, 4);
    SetProfitTarget("Sba1b", CalculationMode.Ticks, 8);}

    What might be the reason for this behavior?

    Thank you!
    Tony
    Last edited by tonynt; 10-08-2019, 09:04 AM. Reason: translation error

    #2
    Hello tonynt,

    May I confirm that the stop and target are being reset before a new entry is being placed and not after?

    Below is a link to an example.


    When you say wrong doubles, what does this mean?
    Are you seeing the stop price of the stop loss is the wrong amount of ticks from the entry fill price?

    If so, what is the entry fill price, what is the stop loss stop price?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      thank you for your reply. I do not know if stop and target are being reset before a new entry or after.
      Therefore I wrote in my question where it is in the script.

      ??

      Thank you!
      Tony

      Comment


        #4
        Hello Tony,

        Are you asking where I am resetting the stop loss and profit target in the ProfitChaseStopTrailSetMethodsExample I have linked you?

        This occurs on lines 96 through 103. The entry takes place after they are reset on line 105.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          thank you again for your reply. I have seen where it is in the sample. And I also have it in onbarupate as posted in my question. I simply do not have == flat but I have !=short and !=long (because with an entry in other direction we are not flat so it would not be reset with "==flat", from my understanding of logic).
          I dont know why you are asking me if it is reset before a new entry or after. How can I know what NT is doin? When I write where it is you will know if it is before or after the entry.

          Thank you!
          Tony
          Last edited by tonynt; 10-08-2019, 09:51 AM. Reason: typo

          Comment


            #6
            Hello Tony,

            Is the code in your script calling SetStopLoss() before or after the entry method is called?

            In the example I have provided you, SetStopLoss() is called before the entry. There is also a note in the script that says this.

            This is not something NinjaTrader has coded in your script. This would be something you have coded in the script.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              the SetStopLoss() is called in line 407.
              The entry method is in line 512. (But it is with "private void OnButtonClick(object sender, RoutedEventArgs rea) {...")
              So maybe this is the reason? Sorry that I did not mention before that the entry is not from onpbarupdate but from OnButtonClick.

              Thank you!
              Tony

              Comment


                #8
                Hello Tony,

                You would need to call the set method from the same method as the entry before the entry is placed.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea,

                  thank you for your reply. OK, but how should this work? (for your info, I´m using the buttons with the logic from the "LongShortToolBarButtons" sample.)

                  Would I need to make a proper button then to click always before the button with the entry? If so, isn´t there a possibility to have the setstoploss and the setprofittarget in another way to avoid this with an additional click?

                  OR

                  Should I remove the setstoploss and setprofittarget from OnBarupdate (and also remove from State.Configure) and move it to OnOrderUpdate or OnExecution?

                  Thank you!
                  Tony

                  Comment


                    #10
                    Hello Tony,

                    You should call set methods like SetStopLoss() in the same method where the entry method is being called.

                    If entry is in a button click even handler method, so should the set method call.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello,

                      thank you, seems working.

                      Tony

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by elirion, Today, 01:36 AM
                      0 responses
                      3 views
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by gentlebenthebear, Today, 01:30 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post gentlebenthebear  
                      Started by samish18, Yesterday, 08:31 AM
                      2 responses
                      9 views
                      0 likes
                      Last Post elirion
                      by elirion
                       
                      Started by Mestor, 03-10-2023, 01:50 AM
                      16 responses
                      391 views
                      0 likes
                      Last Post z.franck  
                      Started by rtwave, 04-12-2024, 09:30 AM
                      4 responses
                      34 views
                      0 likes
                      Last Post rtwave
                      by rtwave
                       
                      Working...
                      X