• 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

Trail Stop with a Profit Target

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

    Trail Stop with a Profit Target

    I'd like to have a trailing stop-loss that trails at one tick worse than one candle previous. At the same time I want to have a profit target set. So as the trade progresses, the trail gets closer to the target and it either hits the target or the trail.

    To accomplish this I have a SetProfitTarget in the OnStateChange() under State == State.DataLoaded. I'm not sure why it's there but I saw that's where the Strategy Builder places it.

    Down in the code after processing the conditions I have EnterLong(Convert.ToInt32(DefaultQuantity), "") and I also have an if statement that on each tick it will try to ExitLongStopMarket.

    Either I can have the EnterLong (that uses a static SetStopLoss and a static SetProfitTarget) or the ExitLongStopMarket with no Profit Target at all. I can't have SetProfitTarget and ExitLongStopMarket together. Not sure why this is.

    How can I achieve my objective? of having a trailing stop with a profit target?

    #2
    Hello Bluebeep,

    Thanks for your post.

    The reason that you cannot use both profit target and ExitLongStop relates to the managed approach rules that are to reduce unwanted position. You can review the internal order handling rules here: https://ninjatrader.com/support/help...d_approach.htm Please note that this would be the case using the strategy builder or working directly in Ninjascript.

    As you have observed, in the strategy builder, the SetProfitTarget (and either SetStopLoss or SetTrailingStop) would be set and fixed in State.Configure meaning that when the strategy is run these would not change. IE: with a 10 tick profit and a 10 tick trailing stop, every entry would automatically have a 10 tick stop and a 10 tick trailing stop.
    The SetTrailStop() will automatically trail price as it movies into profit, for each tick increase in profit the stop will move that many ticks closer to current price to keep a 10 tick distance.

    To accomplish your goal of, "I'd like to have a trailing stop-loss that trails at one tick worse than one candle previous. At the same time I want to have a profit target set. So as the trade progresses, the trail gets closer to the target and it either hits the target or the trail.", you would need to unlock your strategy and work directly in Ninjascript (which is based on C# programming language). Then you would be able to use SetStopLoss() in the OnBarUpdate() meaning you can dynamically change the stop loss value at any time so you can create the code to move the stop loss according to your needs. This then allows you to have an OCO tied profit target and your version of a trailing stop.
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by digibob, Today, 02:47 AM
    0 responses
    1 view
    0 likes
    Last Post digibob
    by digibob
     
    Started by NinjaCustomer, Today, 12:57 AM
    1 response
    4 views
    0 likes
    Last Post NinjaCustomer  
    Started by lancasterstephen, Today, 12:09 AM
    1 response
    5 views
    0 likes
    Last Post lancasterstephen  
    Started by liltr3d, Yesterday, 10:52 PM
    0 responses
    4 views
    0 likes
    Last Post liltr3d
    by liltr3d
     
    Started by Longhornmark, Yesterday, 08:25 AM
    3 responses
    13 views
    0 likes
    Last Post bltdavid  
    Working...
    X