Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter Stop Profit Timing

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

    Enter Stop Profit Timing

    Hi, I have a question about the timing on when\how the profit target is implemented. This is during live trading on a sim account. I'm using a limit order for entry, but also setting a stoploss and profit target. All three calls happen seconds before the limit order entry is tripped. The entry always seems precisely on the limit order price and at the time expected. The profit target seems to be frequently missed but triggererd in a following bar, so I know it's active. The time between entry and passing the profit target is likely < 1 second. Everything works perfectly in simulation and backtesting. Is there a delay between the entry and the profit target order? Would it be better for me to catch the entry fill in OnOrderUpdate and place a profit target sell limit?

    Thanks.

    order = EnterLongLimit(1, myLimitPrice, myOrderName);
    SetProfitTarget(order.Name, CalculationMode.Price, myTargetPrice);
    SetStopLoss(order.Name, CalculationMode.Price, myStopPrice, true);

    #2
    Hello athyssen,

    Thank you for your note.

    When using Set orders for stops and targets you should call these prior to the entry order as you may experience odd behavior if they aren't called until after the entry is made.

    So, try it like this:

    Code:
    SetProfitTarget(order.Name, CalculationMode.Price, myTargetPrice);
    SetStopLoss(order.Name, CalculationMode.Price, myStopPrice, true);
    order = EnterLongLimit(1, myLimitPrice, myOrderName);
    Does this seem to help the behavior you're seeing?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thank you. I flipped the order as you recommended and am still seeing the issue. I've logged the OnMarketUpdate Ask,Bid,Price,Time and the OnOrderUpdate events for the candle in question. In the candles where I see a difference between realtime fills and historical fills, in the historical fills it looks like the profit target is triggered prior to the entry getting filled, and then once the entry fill occurrs it instantly exits at the profit target price even though the current ask/bids are at the entry limit price. Here's an abbreviated timeline.
      • First Tick of Bar (15sec MNQ), SetProfitTarget (target), EnterLongLimit (limit)
      • ask,bid,price goes above (target) at some point before the entry limit is met
      • ask,bid,price goes below (limit), and the Long Entry is Filled
      • After the entry, the ask,bid,price never goes above (target) and yet the trade is immediately exited at the profit target price.
      In the image the left side was from realtime this morning at 9:17 CST. The right side was from then running the strategy again on the non-realtime data. I've attached a log that shows the details of the L14946 order. I believe the realtime fill is correct and the logic for the historical fill is incorrect.

      . Click image for larger version

Name:	CandleComparison.PNG
Views:	140
Size:	32.7 KB
ID:	1189295



      [ATTACH]n1189294[/ATTACH]

      Comment


        #4
        Hello athyssen,

        Thank you for your reply.

        You should expect that a strategy running real-time (live brokerage account, live market simulation, Market Replay etc...) will produce different results than the performance results generated during a backtest in the Strategy Analyzer or on Historical data on a chart. This difference may be more easily seen on certain Bars types (e.g. Point and Figure) than others due to their inherent nature in bar formation.

        During a backtest you can select conservative or liberal fill algorithms which will produce different results. Fills are determined based on 4 data points, OHLC of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known. What you're seeing on historical data is occurring because the simulator does not know when exactly during the bar price actions occurred and it sees the range of the bar as being within a range that would hit the target.

        Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

        Also, here is a link to the differences on real-time vs backtest (historical).
        http://ninjatrader.com/support/helpG...ime_vs_bac.htm

        Adding intra-bar granularity can help with this.

        Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades by supplying the correct price at the correct time for the order to fill with.

        In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add this secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (TickReplay).

        Here is a link to our forums that goes into depth on using Order Fill Resolution and Tick Replay to ensure your backtests are as close to real time results as possible:

        https://ninjatrader.com/support/foru...mance?t=102504

        High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically.

        Please let us know if we may be of further assistance to you.

        Thanks in advance; I look forward to assisting you further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        71 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        143 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        76 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        47 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        51 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X