Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss not moving

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

    SetStopLoss not moving

    Hello. I have a problem with "SetStopLoss("target1long", CalculationMode.Ticks, 20, true);" not moving my stop.

    I use market orders and my initial set stop loss is working just fine. here is the code I use:
    SetStopLoss("target1long", CalculationMode.Ticks, 250, true);
    entryLongOrder1 = EnterLong(numcontracts, "target1long");

    I call "SetStopLoss("target1long", CalculationMode.Ticks, 20, true);" in my code and I am 100% sure it is being called, however, my stop is not moving from the initial stop loss.
    It doesn't matter what the tick amount is, it never gets set and always reverts back to my initial stop.

    I am running the free sim version of ninjatrader and I connect to an FXCM demo account.

    Thanks for the help!

    #2
    Hello ktmdave,

    It sounds as if the first SetStopLoss is getting called again.

    May I see a reduced version of this code that is able to reproduce the issue?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello, the first set stop loss does not get called twice. I am using if market position is flat.
      Also note, I am using live data, demo account.

      David
      Last edited by ktmdave; 04-09-2014, 10:26 AM.

      Comment


        #4
        Hi ktmdave,

        The usage of SetStopLoss does allow for you to move the stop. I think there is something in your logic that is causing the issue.

        I would need to see the code you are using to understand the issue.

        May we see a reduced version of your code that only has the code necessary to reproduce the situation?

        To export your script 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.zip>


        Below is a link to the help guide on Exporting NinjaScripts.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Here is my entry code:

          if (Position.MarketPosition == MarketPosition.Flat){
          if (
          (WMA(200)[0] > WMA(350)[0])

          ){
          SetStopLoss("target1long", CalculationMode.Ticks, 250, true);
          entryLongOrder1 = EnterLong(numcontracts, "target1long");
          }
          }



          Here is my code to update the set stop loss(this gets called tick by tick):
          if (Position.MarketPosition == MarketPosition.Long)
          {
          pipgain = Math.Round(((Input[0] - Position.AvgPrice)/(TickSize*10)),1);

          if ((pipgain >= 10) && (setbreakeven == 0))
          {
          SetStopLoss("target1long", CalculationMode.Ticks, 20, true);
          setbreakeven=1;
          }
          }//end marketingposition long

          Comment


            #6
            I do see one possible problem, actually, my code to change the stop loss is in a barsinprogress=1 function with a tick period of 1. I am running calculate on bar close=true. I am wondering how the Input[0] is set in a calculate on bar close=true? Maybe I should use Close[0] instead of Input[0]. But this should not matter. I have confirmed that my setstoploss is being called. (I put a print statement in).

            Comment


              #7
              Hi ktmdave,

              When a secondary data series is added this complicates things.

              While I don't see in the code that the stop loss would be reset with a single series, I can see that it may be reset with two data series.

              Once you start using multiple data series, you need to control which BarsInProgess is running. Also you need to reference the data and position of that particular BarsInProgress.

              If you order is placed on BarsInProgresss 0, Positions[0] will be long but Positions[1] will be flat. This means that while BarsInProgress 1 is running the SetStopLoss will be called again.

              Have you put a print in the first condition to ensure that BarsInProgress 1 is not resetting the stop loss?

              May I have the complete reduced code as an export so that I may test this?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                -I have a print statement on the main entry/stop code and I am 100% sure it is being called just once.
                -My entry is on barsinprogress=0
                -My stop loss update code is on barsinprogress=1

                I am only using the barsinprogress=1 to manage my order by calculating pips gained/lost, then modifying my stop.
                So it sounds like I have two options:
                1. move my order management code to barsinprogress=0, and calculateonbarclose=false;
                2. in my Barsinprogress=1, order update code, I would need to change the SetStopLoss statement to reference the order in Positions[0]. What would this look like?

                I am away from my pc right now, so it is really difficult for me to attach my code.
                Can you comment on the options above please?
                I really appreciate your help!

                Comment


                  #9
                  Hi ktmdave,

                  From how you have described your code, the code you have posted in the thread is not similar to this.

                  The code you have posted looks like it will happen all in the same BarsInProgress.

                  It is fine to submit an order with BarsInProgress 0 and then update the stop in BarsInProgress 1.

                  If this is how it is designed to work I wouldn't move it. I can't really comment on it because I cannot see your code that is actually in your strategy.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chelsea , if my initial setstoploss(SetStopLoss("target1long", CalculationMode.Ticks, 250, true)) is 250 ticks back from the order entry price, when I run another setstoploss, (SetStopLoss("target1long", CalculationMode.Ticks, 20, true) at 20 ticks, would this set my stop loss to 270 ticks from the order entry price?

                    Comment


                      #11
                      Hi ktmdave,

                      No, if it is initially at 250 ticks, and you call SetStopLoss("target1long", CalculationMode.Ticks, 20, true); this will place the stop loss at 20 ticks not 270. Also, this would be a simulated stop.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        both of these cases are from order entry price (position.avgprice)?

                        Comment


                          #13
                          Thats mostly correct ktmdave. The SetStopLoss will be a number of ticks from the IOrder.AvgFillPrice.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            So this was my problem. I am now using Calculationmode.price instead. Thank you for helping me understand that.
                            Once more question related to this. When using the simulated=true option on the setstoploss, this is for simulating a stop when not running on a real account, correct? So when I go live with real money, I need to change the simulated to false? What would happen if I left simulated=true and ran live with a real account?

                            Thanks!

                            Comment


                              #15
                              Hi ktmdave,

                              The simulated stop doesn't mean much when using the Sim101 account.

                              A simulated stop is one that rests on your local computer instead of being submitted to the broker until the stop is touched. At that point it will submit either the market order or limit order to the broker.

                              The simulation engine is also on your local machine. Simulated stops are really only useful for live orders to your broker. Using true or false for Sim101 orders won't make any difference.

                              One reason this is used is to hide orders from market or to delay the margin being taken by the order until it is ready to fill.

                              Below is a link to the help guide on Simulated Stop Orders.
                              http://www.ninjatrader.com/support/h...top_orders.htm
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              4 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Brevo, Today, 01:45 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by rjbtrade1, 11-30-2023, 04:38 PM
                              2 responses
                              73 views
                              0 likes
                              Last Post DavidHP
                              by DavidHP
                               
                              Started by suroot, 04-10-2017, 02:18 AM
                              5 responses
                              3,021 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X