I'm curious is there any feature for counting the number of trades per day besides the "Orders" or "Executions" tabs(which are not easy to read) ?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Trade Counter
Collapse
X
-
Trade Counter
Hi,
I'm curious is there any feature for counting the number of trades per day besides the "Orders" or "Executions" tabs(which are not easy to read) ?Tags: None
-
Hello itrade4food,
Welcome to the NinjaTrader forums.
Below is a link to a forum post with helpful information about getting started with NinjaScript development and c#.
Are you trying to achieve this in a NinjaScript Strategy that is placing the orders, or are you counting all orders to an Account object including manually placed orders?
Chelsea B.NinjaTrader Customer Service
-
-
Hello itrade4food,
This would use the Addon approach to detect manually placed orders.
You could have a List<order> object with orders added in the <Account>.OrderUpdate event handler method when the OrderState is Accepted or Working and removed when the order is Cancelled, Filled, or Rejected. The list Count would be the number of active orders. Or you could have an integer that is incremented and decremented.
Below is a link to an example you may find helpful that does work with orders in the Addon approach.
Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
NinjaTrader_ChelseaB Hello,
Can you please provide/refer to a quick sample for strategies counting/incrementing a counter after each trade gets closed?
I found this:
How to get all trades for the day and count it? What would you use as the simplest way to do this?Last edited by PaulMohn; 09-09-2024, 08:46 AM.
Comment
-
Hello PaulMohn,
Thank you for your post.
The simplest way is to access the TradeCollection.Count, if you are strictly looking for that strategy instance's trades.
If you want to keep track of the value from a certain point, like the start of the session, save the count to a variable and create a condition which compares the current value of the collection to your saved value.
Comment
-
NinjaTrader_Gaby Hello,
Do you mean from the documentiton, something like this:
SystemPerformance.AllTrades.TradesCount
https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?tradecollection_trad escount.htm
Do you have a quick sample for reference not to reinvent the wheel?
If not already available, can you please build one? The documentation is not detailed enough as is to do it on our own.
Do you have some pseudocode for the trades count for the day?
I mean each day the counter should start over counting the trades to be taken for that day.
Comment
-
Hello PaulMohn,
TradesCount is a property of the TradesCollection.
What specifically are you wanting the sample to show? The Help Guide has sample code showing how to access these properties. Are you needing something more specific?
You could detect if isFirstBarOfSession and reset your counter variable to 0 and have another variable which saves the current TradesCount value (currentTrades).Do you have some pseudocode for the trades count for the day?
I mean each day the counter should start over counting the trades to be taken for that day.
Then check TradesCount - currentTrades and assign that to your counter variable.
If you would like a sample script demonstrating this please let me know.Last edited by NinjaTrader_Gaby; 09-09-2024, 01:14 PM.
Comment
-
How do you reset this?
SystemPerformance.AllTrades.TradesCount
Do you mean something like:
/// Class Variable
private int currentTrades;
/// In OnbarUpdate
currentTrades = SystemPerformance.AllTrades.TradesCount;
If (isFirstBarOfSession)
{
currentTrades = 0;
}
Comment
-
NinjaTrader_Gaby Hello and thanks so much,
I added days of week and hours filters for easier testing.
That seems to work. I'll test further asap.
Tests ok:
Attached FilesLast edited by PaulMohn; 09-10-2024, 02:25 AM.
Comment
-
https://forum.ninjatrader.com/forum/ninjatrader-8/add-on-development/1167848-trade-counter?p=1317512#post1317512
Code:// https://forum.ninjatrader.com/forum/ninjatrader-8/add-on-development/1167848-trade-counter?p=1317512#post1317512 // Copyright (C) 2024, NinjaTrader LLC <www.ninjatrader.com>. // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release. // #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class _TradesCountTest_DaysandHoursFilter : Strategy { private SMA smaFast; private SMA smaSlow; private int DailyTrades; private int SessionStartTradeCount; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver; Name = "_TradesCountTest_DaysandHoursFilter"; Fast = 10; Slow = 25; // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = false; #region 00. Day and Hours Time Filters DayFrom = DayOfWeek.Monday; DayTo = DayOfWeek.Friday; HourFrom = DateTime.Parse("09:00"); HourTo = DateTime.Parse("18:00"); #endregion } else if (State == State.DataLoaded) { smaFast = SMA(Fast); smaSlow = SMA(Slow); smaFast.Plots[0].Brush = Brushes.Goldenrod; smaSlow.Plots[0].Brush = Brushes.SeaGreen; AddChartIndicator(smaFast); AddChartIndicator(smaSlow); } } protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; bool dayTimeFilter = ( Time[0].DayOfWeek >= DayFrom && Time[0].DayOfWeek <= DayTo ); bool hoursTimeFilter = ( // Format example /// ( ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 240000 ) /// || ( ToTime(Time[0]) >= 140000 && ToTime(Time[0]) < 154500 ) ( ToTime(Time[0]) >= ToTime(HourFrom) && ToTime(Time[0]) < ToTime(HourTo) ) ); if(Bars.IsFirstBarOfSession) { //reset daily trades counter DailyTrades = 0; //currentTrades holds the value of AllTrades.Count at the time of session start SessionStartTradeCount = SystemPerformance.AllTrades.TradesCount; Print(" "); Print(Times[0][0] + " Reset on start of new session. DailyTradesCounter: " + DailyTrades); Print(Times[0][0] + " Reset on start of new session. SessionStartTradeCount: " + SessionStartTradeCount); } //calculate DailyTrades value Print(" "); Print(Times[0][0] + " SystemPerformance.AllTrades.TradesCount: " + SystemPerformance.AllTrades.TradesCount); Print(Times[0][0] + " SessionStartTradeCount: " + SessionStartTradeCount); DailyTrades = SystemPerformance.AllTrades.TradesCount - SessionStartTradeCount; Print(Times[0][0] + " Current TradesCounter value: " + DailyTrades); if ( dayTimeFilter && hoursTimeFilter ) { //logic to enter and exit trades, just so we can see our counter update if (CrossAbove(smaFast, smaSlow, 1)) EnterLong(); else if (CrossBelow(smaFast, smaSlow, 1)) EnterShort(); } } #region Properties [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)] public int Fast { get; set; } [Range(1, int.MaxValue), NinjaScriptProperty] [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)] public int Slow { get; set; } #endregion #region Properties [Display(Name="Day of Week From:", Description="", Order=0, GroupName="00. Day and Hours \n Time Filters")] [RefreshProperties(RefreshProperties.All)] public DayOfWeek DayFrom { get; set; } [Display(Name="Day of Week To:", Description="", Order=1, GroupName="00. Day and Hours \n Time Filters")] [RefreshProperties(RefreshProperties.All)] public DayOfWeek DayTo { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")] [Display(Name="Hour From:", Description="Start time", Order=2, GroupName="00. Day and Hours \n Time Filters")] public DateTime HourFrom { get; set; } [NinjaScriptProperty] [PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")] [Display(Name="Hour To:", Description="End time", Order=3, GroupName="00. Day and Hours \n Time Filters")] public DateTime HourTo { get; set; } #endregion } }
Comment
-
NinjaTrader_Gaby Hello again,
Please see this:
The script is attached.
From this:
int lossesCount = SystemPerformance.AllTrades.LosingTrades.Count;
int winsCount = SystemPerformance.AllTrades.WinningTrades.Count;
double tradesProfits = SystemPerformance.AllTrades.TradesPerformance.NetP rofit;
int bottomLineTrades = (-1 * lossesCount) + winsCount;
Draw.TextFixed(this, "tradesstats",
"\n"+"Up/Down Trades Count: "+bottomLineTrades.ToString()+"\n"+
"Total Profits: "+tradesProfits.ToString(),
TextPosition.TopRight, Brushes.Magenta,
tradesstats, Brushes.Transparent,Brushes.Black,100);
It Shows:
Up/Down Trades Count: -6
Total Profits: -2940.08
I have selected the Hours from 10:25 to 11:00.
At 10:21:50 the Count and Total Profits should be 0 and 0 (the strategy hasn't executed any trades yet and would start at 10:25).
I don't get why it does not reset these values.
Can you please take a look at the script and advise on the simplest solution to this?
Comment
-
New Prints and script:
Enabling NinjaScript strategy '_TradesCountTest_DaysandHoursFilter/333889295' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
10/09/2024 10:47:00 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:00 SessionStartTradeCount: 4
10/09/2024 10:47:00 Current TradesCounter value: 0
10/09/2024 10:47:00 1. lossesCount: 4
10/09/2024 10:47:00 1. winsCount: 0
10/09/2024 10:47:00 1. tradesProfits: -2561.72
10/09/2024 10:47:00 1. bottomLineTrades: -4
10/09/2024 10:47:10 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:10 SessionStartTradeCount: 4
10/09/2024 10:47:10 Current TradesCounter value: 0
10/09/2024 10:47:10 1. lossesCount: 4
10/09/2024 10:47:10 1. winsCount: 0
10/09/2024 10:47:10 1. tradesProfits: -2561.72
10/09/2024 10:47:10 1. bottomLineTrades: -4
10/09/2024 10:47:20 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:20 SessionStartTradeCount: 4
10/09/2024 10:47:20 Current TradesCounter value: 0
10/09/2024 10:47:20 1. lossesCount: 4
10/09/2024 10:47:20 1. winsCount: 0
10/09/2024 10:47:20 1. tradesProfits: -2561.72
10/09/2024 10:47:20 1. bottomLineTrades: -4
10/09/2024 10:47:30 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:30 SessionStartTradeCount: 4
10/09/2024 10:47:30 Current TradesCounter value: 0
10/09/2024 10:47:30 1. lossesCount: 4
10/09/2024 10:47:30 1. winsCount: 0
10/09/2024 10:47:30 1. tradesProfits: -2561.72
10/09/2024 10:47:30 1. bottomLineTrades: -4
10/09/2024 10:47:40 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:40 SessionStartTradeCount: 4
10/09/2024 10:47:40 Current TradesCounter value: 0
10/09/2024 10:47:40 1. lossesCount: 4
10/09/2024 10:47:40 1. winsCount: 0
10/09/2024 10:47:40 1. tradesProfits: -2561.72
10/09/2024 10:47:40 1. bottomLineTrades: -4
10/09/2024 10:47:50 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:47:50 SessionStartTradeCount: 4
10/09/2024 10:47:50 Current TradesCounter value: 0
10/09/2024 10:47:50 1. lossesCount: 4
10/09/2024 10:47:50 1. winsCount: 0
10/09/2024 10:47:50 1. tradesProfits: -2561.72
10/09/2024 10:47:50 1. bottomLineTrades: -4
10/09/2024 10:48:00 SystemPerformance.AllTrades.TradesCount: 4
10/09/2024 10:48:00 SessionStartTradeCount: 4
10/09/2024 10:48:00 Current TradesCounter value: 0
10/09/2024 10:48:00 1. lossesCount: 4
10/09/2024 10:48:00 1. winsCount: 0
10/09/2024 10:48:00 1. tradesProfits: -2561.72
10/09/2024 10:48:00 1. bottomLineTrades: -4
Comment
-
Hello PaulMohn,
It's not obvious to me why it could be behaving this way. I suggest debugging the script using prints and TraceOrders.
The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.
The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.
Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
https://support.ninjatrader.com/s/ar...nd-TraceOrders
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment