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

How to Add Breakeven Stop in Strategy Wizard

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

    How to Add Breakeven Stop in Strategy Wizard

    Hey Jimmythesuit,

    Since I am assuming that this can't be done withing strategy wizard, where would you place this code? I've been working on getting a BE stoploss and haven't had much success.

    Thanks for the input,
    Chris

    #2
    Originally posted by chrisca View Post
    Since I am assuming that this can't be done withing strategy wizard, where would you place this code? I've been working on getting a BE stoploss and haven't had much success.
    In your OnBarUpdate.

    Comment


      #3
      So when I run the strategy in replay and an order is triggered, the stoploss is placed at least 15+ points away from entry price even though my stoploss setting is set for 8 ticks. If you could point me in the right direction Sledge, that'd be great.

      Here is how I have the stoploss logic set up:

      // Set 2
      if ((CrossBelow(Close, Bollinger1.Lower, 1))
      && (Stochastics1.K[0] < NumLow)
      && (EventHappenedAlready == false))
      {
      Draw.ArrowUp(this, @" ArrowUp", false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
      EnterLongMIT(Convert.ToInt32(DefaultQuantity), Close[0]);
      }

      // Set StopLoss to BreakEven
      // Once price is 4 ticks profit, set StopLoss to BreakEven
      else if (Position.MarketPosition == MarketPosition.Long && (High[0] >= (Position.AveragePrice + (4 * TickSize))))
      {
      SetStopLoss("", CalculationMode.Price, Position.AveragePrice, true);
      }

      Comment


        #4
        Originally posted by chrisca View Post
        So when I run the strategy in replay and an order is triggered, the stoploss is placed at least 15+ points away from entry price even though my stoploss setting is set for 8 ticks. If you could point me in the right direction Sledge, that'd be great.

        Here is how I have the stoploss logic set up:
        Are you talking initially? Is it using an old stoploss perhaps? You should be able to note where the previous stoploss was and where it is on new entry.


        Maybe seeing the actual #s will help show where the problem is.


        Code:
        // Set 2
        if ((CrossBelow(Close, Bollinger1.Lower, 1))
        && (Stochastics1.K[0] < NumLow)
        && (EventHappenedAlready == false))
        {
        Draw.ArrowUp(this, @" ArrowUp", false, 0, (Low[0] + (-2 * TickSize)) , Brushes.Lime);
        EnterLongMIT(Convert.ToInt32(DefaultQuantity), Close[0]);
        }
        
        // Set StopLoss to BreakEven
        // Once price is 4 ticks profit, set StopLoss to BreakEven
        else if (Position.MarketPosition == MarketPosition.Long && (High[0] >= (Position.AveragePrice + (4 * TickSize))))
        {
        [B]Print ("High[0]="+High[0]);
        Print ("Position.AveragePrice="+Position.AveragePrice);
        Print ("TickSize="+TickSize+ " 4*TickSize="+(4*TickSize) );
        [/B]
        SetStopLoss("", CalculationMode.Price, Position.AveragePrice, true);
        }

        Comment


          #5
          Yes sledge, when I start replay and enable the strategy, the first order triggered places the 15+ point StopLoss in yellow. Things seemed to be running like normal until I went back and adjusted the Profit and StopLoss tick size. I'll add those prints and see what comes up.

          Thanks,
          Chris

          Update: Also, the strategy is now glitching when filling an order and will end up filling hundreds. I got an error saying something about an order being rejected which may have caused it. It may also be because I am trying to use a MIT order for a more precise fill. Ill go back to a standard market order and see if that corrects the glitch.
          Last edited by chrisca; 01-09-2018, 09:58 AM.

          Comment


            #6
            Hello Chris,

            The BreakEvenWizardExample script in post #2 of this thread is a demonstration of a break even movement done with the Strategy Wizard.

            Have you seen the examples I've posted in the links below?




            Regarding the code you have posted, are you certain this is the condition set that is being triggered?

            Have you added prints to ensure no other part of the code is being reached?

            This appears to move to the entry point once in a long position..

            May I have an export of the script to see if I might be able to find another area where SetStopLoss() may be called?

            To export a NinjaTrader 7 NinjaScript do the following:
            1. Click File -> Utilities -> Export NinjaScript
            2. Enter a unique name for the file in the value for 'File name:'
            3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
            4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


            By default your exported file will be in the following location:
            • (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript\<export_file_name.z ip>


            Below is a link to the help guide on Exporting NinjaScripts.
            http://www.ninjatrader.com/support/h...nt7/export.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              At the time, I was sure that the part of code posted was the code when being triggered, until it started glitching on every trade. I can only assume that the MIT order type is to blame. Before the glitch, it appeared that the StopLoss was being moved to BreakEven as hoped, but I can't seem to get the stop to show up on the chart regardless of 'simulated' being set to true or false. I will export the script to you now. It's a NinjaScript 8 just to let you know.

              Thank you,
              Chris

              Comment


                #8
                Hello Chris,

                Thank you for letting us know this is not an NinjaTrader 7 script and is instead a NinjaTrader 8 script.

                I have moved this thread to the NinjaTrader 8 Strategy Development section of forums as the code for NinjaTrader 7 is different than NinjaTrader 8.

                Below I am providing links to examples for NinjaTrader 8.

                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by chartchart, 05-19-2021, 04:14 PM
                3 responses
                577 views
                1 like
                Last Post NinjaTrader_Gaby  
                Started by bsbisme, Yesterday, 02:08 PM
                1 response
                15 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by prdecast, Today, 06:07 AM
                0 responses
                3 views
                0 likes
                Last Post prdecast  
                Started by i019945nj, 12-14-2023, 06:41 AM
                3 responses
                60 views
                0 likes
                Last Post i019945nj  
                Started by TraderBCL, Today, 04:38 AM
                2 responses
                18 views
                0 likes
                Last Post TraderBCL  
                Working...
                X