• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss after price movement

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

    SetStopLoss after price movement

    Hi,

    I'm using an automated strategy and (for example) enter a long position through the following statement:

    EnterLong("MyLongOrder", CalculationMode.Price, dCurrentMarketPrice);

    I don't set an immediate stoploss but want to set the stoploss after price has hit a specific level.

    I want to use:
    SetStopLoss("MyLongOrder", CalculationMode.Price, dEntryPrice, false);

    How would I accomplish this?

    I am using CalculateOnBarClose = false

    So I was thinking I have to check if the "MyLongOrder" position is not null and then set the stop loss. I dont know how to check for this state.

    Another option, I don't know if this is possible, is to use some kind of stop on SetStopLoss, so only set the stoploss once a certain price has been triggered. Does some method like SetStopLoss(....,....,...., stopprice) exist?

    Thanks
    Last edited by siroki; 07-01-2014, 07:20 AM.

    #2
    Hello siroki,

    Thanks for your post and question.

    If you want to use SetStopLoss method, you can set the stoploss in initialize at one value and then later on, in OnBarUpdate, you can modify the stop loss value. The advantage here is that the stoploss is automatically generated on entry, so you are protected at all times and is a simple approach. Important to note that you would want to reset stoploss when you are flat. Here is the help guide on SetStopLoss: http://www.ninjatrader.com/support/h...etstoploss.htm

    Here is a reference example from the forums: http://www.ninjatrader.com/support/f...ead.php?t=3222

    Otherwise you can use a more advanced managed approach using ExitLongStop or ExitShortStop. Please see: http://www.ninjatrader.com/support/h...r_handling.htm and http://www.ninjatrader.com/support/h...itlongstop.htm and http://www.ninjatrader.com/support/h...rshortstop.htm

    Please let me know if I can be of further assistance.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer Paul. But how do I check whether a named long/short position is active? Because I should only move the stoploss to a specific level once a position has been filled and has moved in my direction for a specific amount.

      Example:

      I got long EURUSD at 1.3500
      I want to set my stoploss to breakeven once EURUSD has touched 1.3525

      Sure I can set the stoploss in OnInitialize() to lets say 1.3400 but I should only move it to 1.3500 when:
      1) EnterLong() has been filled
      2) Market price >= 1.3525

      I have the solution in my mind, i just need to find a way how to check if ID "LongPosition" is not null.
      Last edited by siroki; 07-01-2014, 09:15 AM.

      Comment


        #4
        Hello siroki,

        Thanks for your post.

        If you are only dealing with single positions then you can use Position.MarketPosition to determine if you are Flat, long or short and your logic to determine price distance from entry.

        ie:
        if (Position.MarketPosition = MarketPosition.Long)
        {
        // modify stop loss based on your current price to entry price logic
        }

        Please let me know if I can be of further assistance.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          If life were only that simple huh?

          I think I might have found a way through the use of IOrder ..

          I set IOrder1 = EnterLong(SignalName1) and then check for IOrder1 = null etc

          Comment


            #6
            Hello siroki,

            You can certainly use Iorder and you will want to do so from OnOrderUpdate or OnExecution.

            http://www.ninjatrader.com/support/h...tml?iorder.htm

            http://www.ninjatrader.com/support/h...rderupdate.htm

            http://www.ninjatrader.com/support/h...nexecution.htm

            Please let me know if you have any further questions.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sisenberg, Today, 07:29 AM
            1 response
            4 views
            0 likes
            Last Post sisenberg  
            Started by Oceans, Today, 02:22 AM
            2 responses
            21 views
            0 likes
            Last Post Oceans
            by Oceans
             
            Started by sisenberg, Yesterday, 08:06 PM
            1 response
            14 views
            0 likes
            Last Post sisenberg  
            Started by PLeary, Today, 06:25 AM
            0 responses
            10 views
            0 likes
            Last Post PLeary
            by PLeary
             
            Started by sergey_z, Today, 06:17 AM
            0 responses
            4 views
            0 likes
            Last Post sergey_z  
            Working...
            X