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.

        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 Max238, Today, 01:28 AM
            4 responses
            35 views
            0 likes
            Last Post Max238
            by Max238
             
            Started by r68cervera, Today, 05:29 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by geddyisodin, Today, 05:20 AM
            1 response
            11 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by timko, Today, 06:45 AM
            2 responses
            14 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by habeebft, Today, 07:27 AM
            0 responses
            6 views
            0 likes
            Last Post habeebft  
            Working...
            X