- 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 SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
47 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|
||
|
Started by CarlTrading, 07-05-2026, 01:16 PM
|
0 responses
22 views
0 likes
|
Last Post
by CarlTrading
07-05-2026, 01:16 PM
|
||
|
Started by CaptainJack, 06-17-2026, 10:32 AM
|
0 responses
15 views
0 likes
|
Last Post
by CaptainJack
06-17-2026, 10:32 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:15 AM
|
0 responses
21 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:15 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:06 AM
|
0 responses
23 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:06 AM
|

Comment