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

Add autotrail to exit condition

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

    Add autotrail to exit condition

    I would like to add an auto trail to my strategy after making some profit. Can I add a condition with the Wizard that will add and autostop after making say $75 to autotrail 4 ticks below and when I make $150 autotrail at 2 ticks below price? Can I use it as a exit condition with other exit conditions?

    #2
    Hi kelliot,

    Thanks for your post.

    The SetTrailStop in the Wizard is set when the strategy starts and does not get updated after that point.

    To have a dynamic stop that starts after a certain point and then becomes a trail you would need to use an Exit order and use logic to decide at what price to place this exit order (an ExitLongStopLimit would be a stop loss for a long order).

    Attached is an example I have made previously that has a custom trailing exit order made with the wizard as well as a custom breakeven example done with the wizard.

    (updated files)
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 09-08-2016, 09:15 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry for the delay, I have had family visiting and haven't been able to review your comments until now.

      After reviewing the Trail wizard example, can you please clarify the following:

      In set 1 it appears that:

      condition= check to see if we are in a trade
      guessing that we add other condition to enter here

      action=enter long trade named "Entry"
      setting variables 0,1&2 equal to the last close + -15, close + -10 & close +5 (trail distance)

      Questions:
      - Why the - ? Don't we want a + on one and a - on the other?
      - It appears these variables are updated every close, or are they set only at the close at entry and how do you know that?

      In set 2 it appears that:

      condition = we are in a long trade
      condition - if at the last close is greater than variable 2 (which I assume that is is only done at the entry)

      Action = set variable 0 to close + -15 (Based on the new close we are allowing these to change)
      Action = set variable 1 to close + -10

      Questions
      - How can we exit at variable if they are continuing to track the close both up and
      down?

      In set 3 it appears that:

      condition = we are still in a long position

      Action = exit long position when variable 0 or variable 1 is met?

      Question:
      - since var 0 and var 1 are tracking the close, how can the exit conditions ever be met?

      It would be helpful if you could explain each of the steps for a better understanding.

      Comment


        #4
        Hi kelliot,

        The sample I gave actually doesn't trail... I had to correct this script to get the trailing action working.

        With the price of the stop and limit, the stop will need to be below the current price. The limit needs to be lower than the stop or the order will be rejected as the exit in a strategy made by the wizard cannot be a simulated stop.

        These values are updated on every close if Calculate on bar close is set to true. If the script is running with Calculate on bar close set to false, then the script will run on every tick.

        Condition set 2, (Moved to condition set 3 in the new version of the script) is how the trail works.

        We first set the trigger Variable2 (now Variable0 in the new version) to the price at which we want the trail action to trigger. When the close price meets the trigger, we reset where the stop and limit are and bring them closer to the current price.

        You next question I do not quite understand.
        - How can we exit at variable if they are continuing to track the close both up and
        down?
        Can you clarify this for me?

        Condition set 3 (moved to condition set 4) is where the trailing stop gets placed.
        The other conditions can modify where the stop and limit prices will be set, and then the last condition set will place the order.

        (edit)
        I'm also adding a breakeven example to have these in one place.
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 12-13-2017, 08:31 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kaywai, Today, 06:26 AM
        1 response
        5 views
        0 likes
        Last Post kaywai
        by kaywai
         
        Started by ct, 05-07-2023, 12:31 PM
        6 responses
        203 views
        0 likes
        Last Post wisconsinpat  
        Started by kevinenergy, 02-17-2023, 12:42 PM
        118 responses
        2,779 views
        1 like
        Last Post kevinenergy  
        Started by briansaul, Today, 05:31 AM
        0 responses
        9 views
        0 likes
        Last Post briansaul  
        Started by traderqz, Yesterday, 12:06 AM
        11 responses
        28 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X