Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
TradesPerformance Class 'MaxConsecLoser'
Collapse
X
-
Hello Josh,Originally posted by NinjaTrader_Josh View PostYou can ensure you have some trades by doing a check first.
if (Performance.AllTrades.Count > 0)
Thank you for the help. I've been able to make it work.
Leave a comment:
-
You can ensure you have some trades by doing a check first.
if (Performance.AllTrades.Count > 0)
Leave a comment:
-
Jean-Marc-Molina,
The issue is not with that particular line, it is actually with the first line. Since you do not have a first trade yet you cannot access it. Perhaps this thread will help: http://www.ninjatrader-support2.com/...t=14287&page=2
Leave a comment:
-
BTW thank you for the quick answer.Originally posted by Jean-Marc-Molina View Postsorry : in the log message ...
Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the collection size.
.
Maybe you could Email me a code that works wth the Trade declaration and I'll figure out what's the issue.
Leave a comment:
-
sorry : in the log message ...Originally posted by Jean-Marc-Molina View PostI've check the Log
The issue is with the Index. The message is in french in my log file (I'm french) . I i translate it into English it would be something like
Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the connection size.
I guess it happens when there is still no trade (
Performance.AllTrades.Count - 1) would then be negative. I've replaced it by
int Counter=Math.Max(0,Performance.AllTrades.Count - 1);
Trade lastTrade = Performance.AllTrades[Counter];
but it did not work either. Any idea?
When I remove the two "Trade" lines it works, but then I'm not able to get the information I'd like to get on trade performance.
Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the collection size.
.
Leave a comment:
-
I've check the LogOriginally posted by NinjaTrader_Josh View PostJean,
The word does not need to be in blue. Please check your Control Center logs for errors.
The issue is with the Index. The message is in french in my log file (I'm french) . I i translate it into English it would be something like
Error On Calling OnBarUpdate method for Strategy. The index is outside limits. It should not be negative and must be less than the connection size.
I guess it happens when there is still no trade (
Performance.AllTrades.Count - 1) would then be negative. I've replaced it by
int Counter=Math.Max(0,Performance.AllTrades.Count - 1);
Trade lastTrade = Performance.AllTrades[Counter];
but it did not work either. Any idea?
When I remove the two "Trade" lines it works, but then I'm not able to get the information I'd like to get on trade performance.
Leave a comment:
-
Jean,
The word does not need to be in blue. Please check your Control Center logs for errors.
Leave a comment:
-
getting issue when addig Trade firsttrade and Trade lastTrade
Hi,
I'm getting issue when using the Trade
protectedoverridevoid OnBarUpdate()
{
Trade firstTrade = Performance.AllTrades[0];
Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count -1];
as described in the manual. I'd like to include these in order to track each trade performance in the output file.
1) First of all the word Trade does not appear in blue as it is in the Manual.
2) If I include these lines, my backtest does not work all all. There is NO trade. If I remove them, it works.
Any idea? Thanks.
Leave a comment:
-
UserDefinedFunctions was what I was looking for. hence my virtual "library". I just wanted to centralize the functions for risk/trade management.
Thanks!
r2kTrader
Originally posted by NinjaTrader_Dierk View PostYou may consider locating your "centralized" logic in the UsreDefinedMethods file.
You certainly could go beyond that and build your own "library". However, this would be outside the scope of what we support nor do we recommend it. You would be on your own.
Leave a comment:
-
You may consider locating your "centralized" logic in the UsreDefinedMethods file.
You certainly could go beyond that and build your own "library". However, this would be outside the scope of what we support nor do we recommend it. You would be on your own.
Leave a comment:
-
Ben,
Thank you for the reply. I am actually reading/studying C# so my questions can make more sense. (http://www.csharp-station.com is a great free primer)
What I want to do, is have a library that is centralized and then be able to call in a method/function, etc. from within my strategies and indicators.
For example, my money management library should be centralized and then I can just pass data back and forth from within the strategy and have a standard setup that I use when I build a new strategy.
So my question is, where/how do i put everything? Do I setup a class with methods and then use intellisense from within my strat/ind?
I'm figuring it out. It's not brain surgery, but if there was an example that showed how to do it, it would go a long way to bridging what I am reading on csharp-station.com (tutorial) and how ninja approaches things.
Thanks NT!
R2Ktrader
Leave a comment:
-
Hello,
To set it up as a function just do something like this below the OnBarUpdate() block:
private int FindMaxLosers(...you may want some parameters here...)
{
//some code here to find the max losers and assign it to a variable...say
//my_losers and return that count as an int
return my_losers;
}
Then within the OnBarUpdate() block just call FindMaxLowers() like this, for example:
int loser_count = FindMaxLosers();
Also, this link my help:
Note: I did not study the code posted below your post, but this should answer you question generally.
Leave a comment:
-
Add Consecutive Losers, Consecutive Winners as method/function to library
thank you for sharing your solution!
Ideally, rather than integrating this code with each strategy. What is the best way to set this up as a method (function, whatever they call functions these days, grrrr) so that it can be easily called from within a strategy?
I am more of a kludger than a programmer, so a brief outline would be extremely helpful if you or anyone can lend a hand!
The idea would be
if (maxconlosers)
{
//increase default amount by whatever for next trade.
}
This way, if I am on a losing streak, I can really hammer my account down! lol
[UPDATE]
Also, noob question. The line below is throwing an error. I wrapped it in a try/catch (although I don't know how to show the error (yet)). Anyway, the word Trade does not show up in blue, but when I mouse over, it does say NinjaTrader.Strategy.Trade or whatever, so some intellisense is working. Do I need to include something up top in the Declarations? The usual suspects are there.
Trade firstTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
The line
Thanks
R2KtraderLast edited by r2kTrader; 02-20-2009, 04:33 PM.
Leave a comment:
-
Well I figured out a way around it to anyone that wants this sooner than later:
(region variables
privateint tradecounter = 0;
privateint consecwinner = 0;
privateint consecloser = 0;
(onbarupdate
Trade firstTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];
if (Performance.AllTrades.Count > tradecounter)
{
if (firstTrade.ProfitCurrency >= 0)
{ tradecounter = tradecounter +1;
consecwinner = consecwinner + 1;
consecloser = 0; }
else { tradecounter = tradecounter +1;
consecloser = consecloser + 1;
consecwinner = 0; };
}
else
tradecounter = Performance.AllTrades.Count;
// for debugging
Print("l:" + consecloser + " w:" + consecwinner + " tradecount variable:" + tradecounter);
So the only problem that remains is drawdown and cumulative profit charts in the strategy analyzer.
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
152 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
89 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
131 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
127 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
107 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: