• 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

How to move stop orders after 15 ticks of profit?

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

    How to move stop orders after 15 ticks of profit?

    Hi,

    I am trying to code this in my strategy but want to figure out the correct way to do it. Basically, if long/short I want to move my stop order to break even + 1 tick if my current profit is currently at 15 ticks in profit. Then continue to move 1 tick for ever 3 tick that moves in positive direction.

    This goes same for shorts.


    if (Position.MarketPosition != MarketPosition.Flat )
    {


    if long () & (currently +15 ticks) then:
    {

    SetStopL(????) + 1 ?
    }

    if short () & (currently +15 in ticks) then:
    {
    }


    }


    How do i do this correctly?

    #2
    Hello priceisking,

    Thanks for your post.

    To answer your question: SetStopLoss(CalculateMode.Price, Position.AveragePrice + 1 * TickSize); // for long or SetStopLoss(CalculateMode.Price, Position.AveragePrice - 1 * TickSize); // for short

    Position.AveragePrice is the average price of the entry. If trading 1 contract it is the entry price.

    NOTE: If using the SetStopLoss() method an important note is to make sure that you set/reset the stoploss value before placing the entry next order as the SetStopLoss()method retains the last value used.

    References:
    https://ninjatrader.com/support/help...etstoploss.htm
    https://ninjatrader.com/support/help...erageprice.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you for answering this. It helped a lot. I had a quick question on this. If I set this at say:

      if long () & (currently +15 ticks) then:
      {
      SetStopLoss(CalculateMode.Price, Position.AveragePrice + 1 * TickSize);
      }


      And i want to cancel this stoploss and change it to a trailing stop? To continue to trail by SetTrailStop(CalculationMode.Ticks, 12);
      How can I cancel the SetStopLoss and change it to SetTrailStop? or will it auto update when i set the trailstop?

      just a little confused on setting trail after +15 locked in.

      Comment


        #4
        Hello priceisking,

        Thanks for your reply.

        You would not be able to use SetStopLoss() and SetTrailStop() on the same order. You also cannot cancel either set method. This means you would have to use one set method or the other on a given order if you did use both on the same order, the SetTrailStop() will be ignored.

        Alternatively, you can code your own trail stop using SetStopLoss() and some logic controls. Here is a very simple pseudo code example:

        if price > entryprice + variable1 ticks above my entry price
        set stop loss at variable2 ticks + entry price
        increment variable1
        increment variable2

        The difference between variable1 and variable2 is how far behind the trail could be.

        For a trailing stop, keep in mind that it will only be updated when the code runs (this is true for the set methods as well) so if your strategy uses Calculate.OnBarClose then the stop would be updated only at the end of the bar. For this reason, you may want to use Calculate.OnPriceChange so that you get intrabar updates to the trail stop.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Steve L, Today, 11:32 AM
        0 responses
        2 views
        0 likes
        Last Post Steve L
        by Steve L
         
        Started by prabbala, Today, 10:41 AM
        0 responses
        1 view
        0 likes
        Last Post prabbala  
        Started by bebbus, Today, 10:36 AM
        0 responses
        3 views
        0 likes
        Last Post bebbus
        by bebbus
         
        Started by edmata1109, Today, 10:18 AM
        0 responses
        6 views
        0 likes
        Last Post edmata1109  
        Started by futurenick, Today, 06:26 AM
        0 responses
        5 views
        0 likes
        Last Post futurenick  
        Working...
        X