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

Multi-Timeframe ATR-Based TP and SL Help

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

    Multi-Timeframe ATR-Based TP and SL Help

    Hello,

    I am trying to set Profit Targets and Stop Losses according to the Values from an ATR with a user-defined Period. For example, While the strategy is based on Renko, the Stop-Loss and Take Profits are based on a 240-Minute ATR. I have two problems with this:

    1. How do I set the Order Fill Resolution to Ticks when I use the ATR on a second Data Series (I don't see another way to accomplish the task above)

    2. It seems that the Stop-Loss and Take-Profit orders are executing right after the order has been placed (See attachment). How can this be fixed? I have tried Tick- and Pip-based SL and TP Modes.

    I have attached the strategy code, as well as a screenshot from the Strategy analyzer.

    Thanks in advance,
    Marius
    Attached Files

    #2
    Thank you for your query MariusMueller.

    1. How do I set the Order Fill Resolution to Ticks when I use the ATR on a second Data Series
    Order Fill Resolution is a concept that only really has meaning when Ninja has to act as the trade desk during historical or completely simulated trading; in live trading, your orders are filled to the best of the actual live trade desk's ability. With this in mind, high fill resolution is a feature designed to give users more control over this simulated trade desk so they can better make their strategies perform the same way historically that they do live without writing code specifically for historical data processing. Previously users would have to create a multi-timeframe strategy to gain this level of control, and were thus stuck in a situation where they were writing code specifically to handle historical trading, which is of course not a strategy's goal. The primary and ultimate use case for any NinjaTrader strategy is making real money in live trading; performing well during backtesting is only a means toward achieving that goal and should not be a goal into and of itself.

    Since high fill resolution was designed to replace a second data series, if you already have a multi-timeframe strategy, this feature becomes redundant and ambiguous. High fill resolution is equivalent to creating a second data series, excluding all its OnBarUpdate events, and setting your BarsInProgress index to this series' index whenever placing trades; if you are using a multi-timeframe strategy, you need to instead have liberty to decide what each of your timeframes is for, and Ninja creating and using one could cause your strategy to behave unexpectedly. When you create a multi-timeframe strategy, in other words, you are taking both the power and responsibility away from Ninja to determine how your extra data series work. Ninja can only have the necessary full control it requires for high fill resolution if you have a single timeframe strategy.

    If you have a multi-timeframe strategy, you already have everything in place to do this manually :

    Code:
    [FONT=Courier New]
    [B]private int TradeClock = 2;[/B]
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            // ...
        }
        else if (State == State.Configure)
        {
            AddDataSeries(BarsPeriodType.Minute, 1);
    [B]        AddDataSeries(BarsPeriodType.Tick, 1);[/B]
        }
    }
    protected override void OnBarUpdate()
    {
    [B]    if (BarsInProgress == TradeClock) return;[/B]
        EnterLong([B]TradeClock[/B], DefaultQuantity, "");
    }[/FONT]
    It seems that the Stop-Loss and Take-Profit orders are executing right after the order has been placed (See attachment). How can this be fixed? I have tried Tick- and Pip-based SL and TP Modes.
    While reviewing and testing strategy logic goes beyond the scope of the support we may provide, I can list out a few common caveats programmers run into.

    • SetProfitTarget and SetStopLoss are designed to work on the primary data series only. For any multi-series strategy I recommend instead using Exit methods away from the price, such as ExitLongMIT or ExitShortStopMarket.
    • I recommend using SetProfitTarget and SetStopLoss at the exclusion of any Exit methods, and vice-versa. Even if you do not end up violating any Internal Order Handling Rules that Reduce Unwanted Positions, you are more likely to run into situations where your orders enter or exit positions at unexpected times
    • The visual studio debugger is an invaluable tool when chasing down why orders execute when they do. For more information

      http://ninjatrader.com/support/helpG..._debugging.htm

    Please let us know if there are any other ways we can help
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    11 views
    0 likes
    Last Post XXtrader  
    Started by Waxavi, Today, 02:10 AM
    0 responses
    6 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    11 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    2 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by elirion, Today, 01:36 AM
    0 responses
    7 views
    0 likes
    Last Post elirion
    by elirion
     
    Working...
    X