• 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

Changing the value of a double stop

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

    Changing the value of a double stop

    Hello,
    I am using a private double as the variable for my trailing stop the default value being 20 ticks.
    While trading 3 contracts, I am trying to adjust the value of my Trailer to 15 ticks after the first target, and 10 ticks after the second target.

    See below:

    /* if (Position.MarketPosition == MarketPosition.Flat)
    {
    stop = 20;
    }
    //Adjust the stop
    if (Position.Quantity == 2 && Position.MarketPosition != MarketPosition.Flat)
    {
    stop = 15;
    }

    if (Position.Quantity == 1 && Position.MarketPosition != MarketPosition.Flat)
    {
    stop = 10;
    }*/

    I have tried this under OnOrderUpdate and OnPositionUpdate methods but it is not working for me.
    Also tried OnBarUpdate but it won't work there either. By this I mean, it uses 20 ticks in all trades.

    Q1. Is it really possible to change the value an active trailing stop this way just like in an ATM template ? I want to take advantage of the Set methods and be able to adjust this.

    NB: I am aware of the use of LongStopLimit , ShortStop bla bla bla under OnOrderUpdate methods to emulate an ATM strategy but this negates the use of the Set methods.

    Thanks,
    Kiriru

    #2
    kiriru, it is definitly possible to change the price of a stop just like how an ATM strategy does. Can you please post the full code you're using here so we can see how it all fits together?

    You are correct in that the LongStopLimit and ShortStop order types negate the use of the Set() methods, but they do offer more control and flexibility in implementation.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Here's the code:


      #region Variables

      private double stop = 20;
      private int target1 = 19;
      private int target2 = 29;


      #endregion


      protected override void Initialize()
      {

      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;
      SetTrailStop("", CalculationMode.Ticks, stop, false);

      CalculateOnBarClose = true;
      ExitOnClose = true;
      }


      protected override void OnBarUpdate()


      {

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      stop = 20;
      }
      //Adjust the stop
      if (Position.Quantity == 2 && Position.MarketPosition != MarketPosition.Flat)
      {
      stop = 15;
      }

      if (Position.Quantity == 1 && Position.MarketPosition != MarketPosition.Flat)
      {
      stop = 10;
      }


      // Condition set 1

      if Close[0] > Open[0]


      {
      EnterLong(Quantity, "Long A");
      // EnterLong(Quantity, "Long A1");
      EnterLong(Quantity, "Long B");
      EnterLong(Quantity, "Long C");


      SetProfitTarget("Long A", CalculationMode.Ticks, target1);

      SetProfitTarget("Long B", CalculationMode.Ticks, target2);


      }

      // Condition set 2
      If Close[0] < Open[0]

      {
      EnterShort(Quantity, "Short A");
      EnterShort(Quantity, "Short B");
      EnterShort(Quantity, "Short C");

      SetProfitTarget("Short A", CalculationMode.Ticks, target1);
      SetProfitTarget("Short B", CalculationMode.Ticks, target2);


      }

      }

      Comment


        #4
        Hello,

        Is this code still locked and you can only edit it with the Strategy Wizard have unlocked it to add code?

        I look forward to assisting you further.
        BrettNinjaTrader Product Management

        Comment


          #5
          Hello kiriru,

          What's happening is that Initialize() is not called while you are actively running the strategy. You will have to use the Set statement in OnBarUpdate(). A sample on modifying targets and stop losses with Set statements is available here:
          Strategy: Modifying the price of stop loss and profit target orders
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Thanks Ryan,
            This is we exactly what I needed.
            Thanks indeed.
            Kiriru

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by iq200, Today, 05:47 AM
            0 responses
            0 views
            0 likes
            Last Post iq200
            by iq200
             
            Started by svadukia, Today, 05:41 AM
            0 responses
            1 view
            0 likes
            Last Post svadukia  
            Started by giogio1, 11-10-2019, 11:23 PM
            4 responses
            16 views
            0 likes
            Last Post bltdavid  
            Started by StevenNelson, Yesterday, 07:31 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by dtl-saw, Yesterday, 09:37 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Working...
            X