Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SystemPerformance RealTimeTrades in Strategy Analyzer

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

    SystemPerformance RealTimeTrades in Strategy Analyzer

    Hello,
    I am working with a strategy and I want to stop taking trades for the day if a certain daily loss is met or if there are too many trades taken that day. I have tested this to be working in the "Playback" connection as well as in real time and the way I have achieved this is with the following,

    if ((SystemPerformance.RealTimeTrades.TradesPerforman ce.Currency.CumProfit > DailyProfitLimit) || (SystemPerformance.RealTimeTrades.TradesPerformanc e.Currency.CumProfit < DailyLossLimit))
    {
    return;
    }​

    However when I am running the strategy in the analyzer, this condition is not being met because the values returned are 0 for the entire day. Another problem I am having is the number of trades taken per day is also showing up as 0. I have a condition to exit if there are too many trades taken as well that works in playback and real time.

    protected override void OnBarUpdate()
    {
    Print("Cumulative profit " + SystemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit + " " + Time[0]);
    Print("The strategy has taken " + SystemPerformance.RealTimeTrades.Count + " real-time trades.");​

    // do some work here
    }

    Produces the following output
    ...
    Cumulative profit 0 4/2/2024 6:58:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 6:59:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:00:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:00:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:01:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:02:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:03:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:04:00 AM
    The strategy has taken 0 real-time trades.
    Cumulative profit 0 4/2/2024 7:30:00 AM​
    ...

    Based on this output, it appears that RealTimeTrades is not set in the strategy analyzer although I cannot find this in the docs. Does anyone know how to achieve such a limiting condition that will be used in the strategy analyzer? Thanks!

    #2
    Hello dr_cortex,

    To have this work in the backtest you need to change to using the AllTrades collection so historial trades are being counted. You can find a sample that shows how to break the performance down per session when using the AllTrades collection here:

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Working...
    X