Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Only One Strategy on PnL Limit in NinjaTrader 7/8

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

    Stop Only One Strategy on PnL Limit in NinjaTrader 7/8

    Hello,

    I am developing a strategy in NinjaTrader 8 that includes daily profit and loss limits (DailyProfit and DailyLoss). The goal is to stop only the specific instance of the strategy when it reaches its daily PnL limit, while allowing other running instances of the same strategy to continue trading independently.

    The issue:
    • When one instance of the strategy reaches its PnL limit, all instances stop trading, instead of only the one that hit the limit.
    • I suspect the issue might be related to the use of SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit, as it might be considering all trades across the account, rather than just those of the individual strategy instance.

    What I have tried:
    • Using SystemPerformance.StrategyTrades.TradesPerformance .Currency.CumProfit, but I want to ensure this works across all versions of NinjaTrader 8 (both old and new).
    • Implementing this.Disable(), but I need confirmation that it stops only the current strategy instance and does not impact others.

    How can I modify my strategy to ensure that each instance tracks its own PnL separately and stops only when its own daily limit is hit, without affecting other running instances?

    Below is my current code for pnl

    // PnL
    YesterdaysPNL[0] = YesterdaysPNL[1];
    StrategyTotallPNL[0] = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;

    if (CurrentBars[0] < 1)
    return;

    //
    if (Bars.IsFirstBarOfSession)
    {
    YesterdaysPNL[0] = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
    Print(@"*** First Bar of Session ***");
    Draw.Text(this, @"DailyPNLexample Text_1 " + Convert.ToString(CurrentBars[0]),
    @"TotalRealizedPNL= " + Convert.ToString(SystemPerformance.AllTrades.Trade sPerformance.Currency.CumProfit),
    0, (Low[0] + (-9 * TickSize)));
    Draw.Text(this, @"DailyPNLexample Text_2 " + Convert.ToString(CurrentBars[0]),
    @"Prior SessionPNL = " + Convert.ToString(DailyPNL),
    0, (Low[0] + (-5 * TickSize)));
    DailyPNL = 0;
    }
    else
    {
    // PnL
    DailyPNL = (StrategyTotallPNL[0] - (YesterdaysPNL[0]));
    }

    // DailyLoss и DailyProfit
    if (DailyPNL <= DailyLoss || DailyPNL >= DailyProfit)
    {
    Print($"Strategy stopped for this instance. Account: {Account.Name}, DailyPNL: {DailyPNL}, DailyLoss: {DailyLoss}, DailyProfit: {DailyProfit}");
    return; //
    }

    //
    Print(Convert.ToString(Times[0][0]) + @" TotalPNL: " + Convert.ToString(StrategyTotallPNL[0]) +
    @" YestredaysPNL: " + Convert.ToString(YesterdaysPNL[0]) +
    @" DailyPNL: " + Convert.ToString(DailyPNL));​

    Any guidance or best practices would be greatly appreciated! Thank you.

    #2
    Hello ilaniko,

    The SystemPerformace values only apply to each strategy instance, strategies cannot see what other strategies are doing. If all of your instances are stopping that would indicate that each strategy had met the condition you created. You would have to use a Print to get a better idea how the logic of each strategy is evaluating when run to see why they may all be stopping.

    You can find a sample of working with a strategies individual PnL in the following link.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    63 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X