Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

setstoploss - settrailstop

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

    setstoploss - settrailstop

    Hello,
    I´m using NT live-license for one week now and I want to code in my strategy setstoploss and settrailstop. I´ve read the video-library referring to this issue before writing that post and I understand that I can´t use both stoploss and trailstop - of course - not for the same positon. But when I name the entries different it doesn´t work too. The entry2-position is closed with profit-target or stoploss.

    SetProfitTarget("Entry1", CalculationMode.Ticks, 10);
    SetProfitTarget("Entry2", CalculationMode.Ticks, 50);
    SetStopLoss("Entry1", CalculationMode.Ticks, 15,true);
    SetTrailStop("Entry2", CalculationMode.Ticks, 9, true);

    Doesn´t this work this way? Thank you for help.

    Best regards
    Tony
    Last edited by tonynt; 08-05-2010, 03:22 PM. Reason: typing error

    #2
    Hello tonynt,

    Yes, it should work this way. Are you getting both entries filled? What settings do you have set for entryHandling and entriesPerDirection?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      setstoploss - settrailstop

      Hello Ryan,

      thank you for your reply. I have set

      SetStopLoss("Entry1", CalculationMode.Ticks, 15,true);
      SetTrailStop("Entry2", CalculationMode.Ticks, 8, true);

      CalculateOnBarClose = true;

      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;

      Thanks.
      Tony

      Comment


        #4
        I'm not sure why you're getting those results. Can you please attach the complete strategy file and I can test here? You can find the .cs file in My documents\NinjaTrader\bin\custom\strategy
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thank you for your reply.
          I could do it with this , don´t know where the error has been - on my end. For trading live with Ninja finally I have one question referring modifying stoploss and trailstop. I have checked the strategy sample and I have done correctly (and this works for only stoploss)
          if(Position.MarketPosition == MarketPosition.Flat)
          { SetStopLoss(CalculationMode.Ticks, 10);}

          else if (Position.MarketPosition == MarketPosition.Long)
          {if (Close[0] > Position.AvgPrice + 10 * TickSize)
          {SetStopLoss(CalculationMode.Price, Position.AvgPrice);}

          My question referring to the beginning of this thread is now: how can I change the "normal" stoploss and the trailsstop. I have tried several times (I have read of course in the help topics that stoploss and trailstop can not be used for same position, this is not what I want). I want to change our initial stoploss and the trailstop both referring to different positions.
          Thanks
          Tony
          Last edited by tonynt; 08-10-2010, 03:12 PM. Reason: error typing

          Comment


            #6
            tonynt, you can call SetStopLoss() whenever you want to change the stop loss' price. Here is the reference sample for changing the price of stop losses and profit targets.
            AustinNinjaTrader Customer Service

            Comment


              #7
              change stoploss

              Austin,

              I wrote that I know this sample. But this sample does not help to do changing both, the stoploss and the trailstop. Do you know it or you send out the sample when maybe matching a word with the question? I asked for how to change stoploss and trailstop those have been coded referring to this thread.
              Best
              Tony

              Originally posted by NinjaTrader_Austin View Post
              tonynt, you can call SetStopLoss() whenever you want to change the stop loss' price. Here is the reference sample for changing the price of stop losses and profit targets.

              Comment


                #8
                Tony, I'm sorry I guess I don't understand your question then. Can you please clarify?

                I saw in your previous posts that you had read the help guide entries for SetStopLoss(), but nothing about the reference sample that actually demonstrates this concept. We read each and every post, and suggest the references when we think it would be appropriate. There is no automated matching of keywords.

                If you look through the sample, it definitely goes over how to change the stop loss price. Changing the trailing stop parameters will be exactly the same procedure, but be sure to reset the prices when the position is flat.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  stoploss - trailstop

                  Austin,

                  you say that you saw "nothing about the reference sample.." I wrote that I know the sample and I also posted to code - exactly to avoid such discussions as now. Did you see the code??? This is the code copied from the sample!

                  In this sample it´s clear how to change 1 stoploss - I mentioned, too.

                  But it´s not a help when using both - stoploss and trailstop - in a strategy.

                  And this is exactly what I write now 3rd time - clear to understand. (First time now after done many compliments to support of NinjaTrader I also should have purchased MultiCharts.)

                  You mentioned in your 2 replies that there is shown how to change stoplosses - I have said this already - clearly! And I told you that I know. And your support is to tell me that it works with stoploss - this was my post.




                  Originally posted by NinjaTrader_Austin View Post
                  Tony, I'm sorry I guess I don't understand your question then. Can you please clarify?

                  I saw in your previous posts that you had read the help guide entries for SetStopLoss(), but nothing about the reference sample that actually demonstrates this concept. We read each and every post, and suggest the references when we think it would be appropriate. There is no automated matching of keywords.

                  If you look through the sample, it definitely goes over how to change the stop loss price. Changing the trailing stop parameters will be exactly the same procedure, but be sure to reset the prices when the position is flat.
                  Last edited by tonynt; 08-11-2010, 12:13 AM. Reason: without "LOL"

                  Comment


                    #10
                    Hi Tony,

                    Let's get back on track to your original issue. Here's my understanding:
                    • Submitting two entries - one has a stop loss and the other a trail stop.
                    • You're modifying stop loss orders after you're in a position.
                    • Both entries are closed when a target or stop loss is reached.
                    Can you clarify if this is what are you seeing and provide a file or code snippet that demonstrates?

                    Edit:
                    One property you may need to check here is stop and target submission - Make sure it's set to PerEntryExecution.
                    Last edited by NinjaTrader_RyanM1; 08-12-2010, 11:41 AM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Cancel StopLoss or Convert to TrailStop

                      I implemented the code sample for moving stoploss to breakeven after a threshold profit is achieved. I would like to then convert the breakeven stop to a trailing stop. Is there a way to programatically cancel a stop loss and/or convert it to a trailing stop?
                      Thanks
                      DaveN

                      Comment


                        #12
                        Hello DaveN,

                        Unfortunately not. If you're using both SetStopLoss and SetTrailStop, it will use instead the stop loss.

                        You can program a trailing behavior with your SetStopLoss though. Instead of using CalculationMode.Ticks, which is in relation to your entry price, you could use CalculationMode.Price and then specify the price you want your order to be.

                        This sample helps with modifying stop loss orders dynamically:
                        Strategy: Modifying the price of stop loss and profit target orders
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Thank you so much Ryan... After 2-3 hours, I saw this post and it solved my problem!!! You guys rule!

                          Comment


                            #14
                            Set Stop/Trailing Stop

                            Rather than start a new thread, this is another question on the same subject.

                            1 I want a max loss on a trade to be (say) 8 ticks. I therefore set a stoploss of 8 ticks. Then if PA moves in profit 4 ticks, I want a trailing stop to cut in and trail the PA as it rises. This requires SL and TS to be both active but you say that they cannot both be set at the same time?

                            The Wizard has coded:

                            SetProfitTarget("", CalculationMode.Ticks, Profittarget);
                            SetStopLoss("", CalculationMode.Ticks, StopLoss, true);
                            SetTrailStop("", CalculationMode.Ticks, TrailingStop, true);

                            in my strategy which indicates that they can if fact be set concurrently? It seems to be working the way I want it to. Is the Wiz wrong?

                            2 The next part of my strategy is to limit the cumulative total profit and/or loss on the instrument for the day. I have seen code to do that for a single instrument but is it possible to do that for an account that is trading several instruments at the same time so that if the total for the day on the account is reached it flattens everything that is open or pending? The strategy code applied to each instrument would require that on OnBarUpdate, it would check on the overall total so that if hit, any instrument could call the "All out" signal and everything would flatten for the day?

                            3 I saw somewhere a question on this asking if there could be a trailing stop on this total cumulative profit so that cumulative profit could be locked in and not whittled away as the trading session continued. The total cumprofit set may not be reached but nearly, only to then see the profit eaten away - very unpleasant to say the least? I cannot locate it again to see if there was an answer.

                            Thanks
                            Karl

                            Comment


                              #15
                              Hi Karl, to answer your questions:

                              1. I don't recall the exact circumstances, but sometimes these two do not work together at all.

                              2. Each strategy only knows about positions opened by itself, so you would need to code up a "master strategy" with every instrument you're trading controlled by it and then you could keep track of the "portfolio" profit/loss instead of the individual instruments.

                              3. This is similar to #2 - you'd need to keep track of all profit/loss together and then somehow figure out a way to do a "portfolio-wide stop loss".
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              666 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              377 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X