Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:

    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 DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X