Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
simplify code
Collapse
X
-
Hi user10, thanks for your note.
It's not incrementing because you're initializing the counter class withing OnBarUpdate, so it is deleted when OBU is finished calling. Place this at the class level (the one that inherits the Indicator class) and it will work properly.
Best regards.
- Likes 1
Leave a comment:
-
Try using ++myCounter instead of myCounter++Originally posted by user10 View PostHello to the forum,
I want to outsource recurring calculations from my strategy and simplify my code. That's why I wrote the following code.
Code:protected override void OnBarUpdate() { // create dummy signal to evaluate barCounter++; if (barCounter % 2 == 0) barCounter2 += 2; testSeries[0] = barCounter2; MyHistoricSeries myHistoricSeries = new MyHistoricSeries(); // Does not add! methodCounter = myHistoricSeries.Counter(testSeries); Print (Time[0] + " barCounter " + barCounter + " barCounter2 " + barCounter2 + " methodCounter " + methodCounter ); } } } public class MyHistoricSeries { int myCounter; // Evaluate testSeries public int Counter (Series<int>mySeries) { if (mySeries[0] > mySeries[1]) myCounter++; return myCounter; } }
The testSeries is passed to the Counter method and returns the evaluation.
But I want the methodCounter to cumulate!
Is that basically possible or what other solution is there for my problem?
Many thanks for the support!
Leave a comment:
-
simplify code
Hello to the forum,
I want to outsource recurring calculations from my strategy and simplify my code. That's why I wrote the following code.
Code:protected override void OnBarUpdate() { // create dummy signal to evaluate barCounter++; if (barCounter % 2 == 0) barCounter2 += 2; testSeries[0] = barCounter2; MyHistoricSeries myHistoricSeries = new MyHistoricSeries(); // Does not add! methodCounter = myHistoricSeries.Counter(testSeries); Print (Time[0] + " barCounter " + barCounter + " barCounter2 " + barCounter2 + " methodCounter " + methodCounter ); } } } public class MyHistoricSeries { int myCounter; // Evaluate testSeries public int Counter (Series<int>mySeries) { if (mySeries[0] > mySeries[1]) myCounter++; return myCounter; } }
The testSeries is passed to the Counter method and returns the evaluation.
But I want the methodCounter to cumulate!
Is that basically possible or what other solution is there for my problem?
Many thanks for the support!Tags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
88 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
134 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
68 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
119 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
69 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Leave a comment: