Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget Not Working

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

    SetProfitTarget Not Working

    Hi,

    I'm currently trying to create a strategy that enters if price hits a certain percentage pull back of a candle from several candles ago thus I need to use Limit Orders. I think this might be causing an issue with my SetProfitTarget orders because my profit target calculations are accurate but they don't get filled during the backtest. I've provided a section/sample of my code that shows what I'm talking about. Could you please help me figure out what my issue is?

    Code:

    bullTarget = (((entryPrice - longCloseStopWickSL) * RProfitMultiplier) + entryPrice);
    bullTarget2 = (((entryPrice - longCloseStopWickSL) * RProfitMultiplier2) + entryPrice);

    Print("The target price for this trade is: " + bullTarget + " Time: " + Time[0]);
    Print("The stop loss for this trade is: " + longCloseStopBodySL + " Time: " + Time[0]);

    SetProfitTarget("Long", CalculationMode.Ticks, bullTarget);
    SetStopLoss("Long", CalculationMode.Ticks, MaxSL, false);

    SetProfitTarget("Long2", CalculationMode.Ticks, bullTarget);
    SetStopLoss("Long2", CalculationMode.Ticks, MaxSL, false);

    Long1 = EnterLongLimit(0, true, DefaultQuantity, entryPrice, "Long");
    Long2 = EnterLongLimit(0, true, DefaultQuantity, entryPrice, "Long2");​

    Thank you!

    #2
    Hello rjm1903,

    Thank you for your post.

    In backtest, intrabar granularity is needed for accurate order fills. However, with Set methods these cannot use an additional data series to calculate so we usually suggest using Exit methods instead of Set methods for backtesting purposes so you can submit them to the 1-tick series and have more accurate order fills.

    This is discussed here in the section 'Note on Set methods':

    https://support.ninjatrader.com/s/article/Developer-Guide-Improving-backtest-order-fill-accuracy-with-intrabar-granularity

    Please let us know if you have any further questions.

    Comment


      #3
      I don't think it is an issue of tick granularity because there are times when the profit target wouldn't be hit for many candles and it still doesn't trigger. Would there be a reason why the EnterLongLimit order being tagged to an actual order name prevents my SetProfitTarget from being placed correctly?

      Comment


        #4
        Nevermind. I figured it out. I was accidentally using CalculationMode.Ticks instead of .Price because I carried code over from a different area. Thank you for your assistancne!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        43 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X