Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy exit and stoploss move to BE+1

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

    Strategy exit and stoploss move to BE+1

    Hi, i am new in this forum and
    I am trying to make a strategy, but i cant find out, how to make my stoploss move to BE+1 after 12ticks?
    And second problem, i dont know how to make exit strategy based on this rules:
    In a long position (in open profit), when first red candel is shown, place (or move) stoploss (from BE+1) 3 ticks below previous bar (this bar must be green-rising). When the stoploss is not reached and price is moving up again, move stoploss as i wrote before, again. I hope you understood what i tried to say, if necessary i cant post image.
    Can I do this in strategy wizard, is it possible?
    I appreciate any help, thaks
    Mike

    #2
    Hello,

    Thanks for the forum post and welcome to the NinjaTrader support forums.

    This can be done although it cannot be done inside of the strategy wizards stops and targets page, it has to be done inside of the Conditions page with the set 1 tabs.

    You will need to create a new set the has the condition of if Market Position equal to Market Position.Long. Then Exit Long Position by a stop order. You will want to make sure that this strategy is run Calculate On Bar Close = False however this way your stop order will be submitted immediately after you enter a long position.

    Then you will want to create a variable that you will set when you enter long that has the trigger price of your breakeven. So you will then do a set for if the Close price is greater then your set variable0 then you will want to move the stop up.

    Let me know if you have any questions on this.

    Comment


      #3
      Thank you Brett for your help, i followed your instructions but i cant move over the second article (Then you will want to create a variable.....), could you be more specific with this procedure please?
      I am really newie in this.

      Here is my progress with this strategy, i hope it is right like you wrote before.

      /// <summary>
      /// Enter the description of your strategy here
      /// </summary>
      [Description("Enter the description of your strategy here")]
      public class SCentry1 : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int moveSLafteronBE = 9; // Default setting for MoveSLafteronBE
      private int sL = 12; // Default setting for SL
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (Open[0] > Open[1]
      && Open[0] > Close[1]
      && Close[0] > High[1]
      && Open[0] < Close[0])
      {
      EnterLongStop(DefaultQuantity, Close[0] + 1 * TickSize, "Entry Long");
      }

      // Condition set 2
      if (Position.MarketPosition == MarketPosition.Long)
      {
      ExitLongStop(SL, "Exit Long", "0");
      }

      }

      Comment


        #4
        Hi mike900,

        I recommend taking a look at the dedicated sample for this, available here:


        You can import and use it is a template for a breakeven stop loss strategy.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thank you RyanM.

          Comment


            #6
            I have one more question for you, the stoploss or trailstop conditions must be defined in set1 or anywhere else?

            Comment


              #7
              Hello,

              They are actually defined in the next page of the strategy wizard. CLick next one more time to get to the Stop Loss and Profit target page to set these.

              Let me know if I can be of further assistance.

              Comment


                #8
                Thanks Brett, i got it.
                So i define the numbers for PT and SL, but the conditions for moving the SL must be defined in the "set´s"?

                Comment


                  #9
                  Hello,

                  Sorry need to backup. I answered without first reviewing the full thread.

                  So forget about the stops and targets page of the wizard as this does not do what you need.

                  You will be working completely in the set tabs. Does not have to be in set tab 1 it can be in any tab.

                  You will use ExitLongStop for your command for the stop order you will put a variable in as the input for the stop price. THen you can change this variable and it will change the stop loss price on each calculation.

                  Let me know if I can be of further assistance.

                  Comment


                    #10
                    Thanks Brett,
                    i´ll try to handle it.

                    Comment


                      #11
                      I made - market position=market positon long
                      exit long by a stop order, i defined myinputs for size of the stoploss, i put it in the stop price box, but it doesnt work. I made an backtest, but still exiting on market close.
                      here is the code, is it set right? I am running on demo, can this cause any problems with running the strategy right?
                      thanks for reply

                      // Condition set 2
                      if (Position.MarketPosition == MarketPosition.Long)
                      {
                      ExitLongStop(SL, "SL", "");
                      }
                      SL - myinput size 12

                      Comment


                        #12
                        Hello,

                        When you do your backtest make sure you disable the Exit On close setting in the settings for when you start the backtest. THis needs to be set to false.

                        Let me know if I can be of further assistance.

                        Comment


                          #13
                          Still cant figure out, how to make it work.
                          I read the help guide, followed your advice step by step, its the same. In the backtest i changed "exit on close" false. But the stoploss doenst enter, when my long order is filled. When the -exit on close- is set to false, it makes only 1trade with close on the last day, which i selected. Posting the code again

                          /// <summary>
                          /// Enter the description of your strategy here
                          /// </summary>
                          [Description("Enter the description of your strategy here")]
                          public class Znova1pokus : Strategy
                          {
                          #region Variables
                          // Wizard generated variables
                          private int sL = 12; // Default setting for SL
                          private int pT = 60; // Default setting for PT
                          private int bE = 8; // Default setting for BE
                          private int quantity = 1; // Default setting for Quantity
                          private int pTsmall = 20; // Default setting for PTsmall
                          // User defined variables (add any user defined variables below)
                          #endregion

                          /// <summary>
                          /// This method is used to configure the strategy and is called once before any strategy method is called.
                          /// </summary>
                          protected override void Initialize()
                          {
                          CalculateOnBarClose = false;
                          }

                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {
                          // Condition set 1
                          if (Open[0] > Open[1]
                          && Open[0] > Close[1]
                          && Close[0] > High[1]
                          && Open[0] < Close[0])
                          {
                          EnterLongStop(Quantity, Close[0] + 1 * TickSize, "EntryOrder");
                          }

                          // Condition set 2
                          if (Position.MarketPosition == MarketPosition.Long)
                          {
                          ExitLongStop(SL, "Stoploss", "EntryOrder");
                          }

                          Comment


                            #14
                            mike900,

                            Please check your Control Center logs for errors. Putting in an SL price of 12 literally means you have a stop loss at the exact instrument price of $12. This likely would not make sense in a lot of cases unless you are trading something that actually has prices around $12.
                            Josh P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by inanazsocial, Today, 01:15 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post inanazsocial  
                            Started by trilliantrader, 04-18-2024, 08:16 AM
                            5 responses
                            22 views
                            0 likes
                            Last Post trilliantrader  
                            Started by Davidtowleii, Today, 12:15 AM
                            0 responses
                            3 views
                            0 likes
                            Last Post Davidtowleii  
                            Started by guillembm, Yesterday, 11:25 AM
                            2 responses
                            9 views
                            0 likes
                            Last Post guillembm  
                            Started by junkone, 04-21-2024, 07:17 AM
                            9 responses
                            70 views
                            0 likes
                            Last Post jeronymite  
                            Working...
                            X