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

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 josh18955, 03-25-2023, 11:16 AM
    6 responses
    435 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    3 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    18 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frslvr, 04-11-2024, 07:26 AM
    9 responses
    127 views
    1 like
    Last Post caryc123  
    Started by selu72, Today, 02:01 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Working...
    X