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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by gustavobp, Yesterday, 05:30 AM
    2 responses
    18 views
    0 likes
    Last Post gustavobp  
    Started by preqc, 04-10-2022, 01:26 PM
    2 responses
    205 views
    0 likes
    Last Post mixedbyclaudio  
    Started by defa0009, 12-13-2024, 09:19 AM
    23 responses
    255 views
    1 like
    Last Post marcus2300  
    Started by srtrader, 02-12-2025, 09:01 PM
    3 responses
    27 views
    0 likes
    Last Post rockmanx00  
    Started by bertochi, 02-14-2025, 05:25 PM
    2 responses
    32 views
    0 likes
    Last Post bertochi  
    Working...
    X