- CableTrader007
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Inline Strategy Metrics
Collapse
X
-
Thank you for the code sample. In using the code I receive the following error message: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart. Any thoughts on how to fix or added check in place before the code section. With this code commented out I do not get any errors with the working strategy I am adding this to.
- CableTrader007
-
Hello CabelTrader007,
Thank you for your response.
I have corrected the for loop below, you will also want to ensure 30 bars have processed with CurrentBar:
Code:protected override void OnBarUpdate() { if(CurrentBar <= 30) return; if(Performance.AllTrades.Count > 30) { for(int i = 30; i > 0; i--) { totProfit[i-1] = Performance.AllTrades[Performance.AllTrades.Count - i].ProfitCurrency; } double totAvgProfit = SMA(totProfit, 30)[0]; double totStdDev = StdDev(totProfit, 30)[0]; double perfMetric = totAvgProfit / totStdDev; } }
Comment
-
Thank you for the quick reply. Please explain why the check for 30 bars. The calculation already has a check for 30 trades which does not have anything to do with the number of bars.
Comment
-
Hello CableTrader007,
Thank you for your response.
The DataSeries totProfit is synced to the primary bar series you apply the strategy to via the line in the Initialize() method that reads totProfit = new DataSeries(this);. So the totProfit would not have all the values we want before 30 bars have processed.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment