private int firstRun=0; protected override void OnBarUpdate(){ if(firstRun<15){ firstRun++; return; } Print(HighIn(3)); } private double HighIn(int bars){ if(bars <= 2){ return High[bars]; } double value = HighIn(bars--); if(value>High[bars]){return value;}else{ return High[bars];} }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Fresh eyes needed for rucursive method
Collapse
X
-
Fresh eyes needed for rucursive method
My coding skills are pretty rusty. Can someone find the error in the recursive method HighIn().
Code:Tags: None
-
Hi
So first and foremost the -- inCode:bars--
Example
Code:int i = 3; Console.WriteLine(i); // output: 3 Console.WriteLine(i--); // output: 3 Console.WriteLine(i); // output: 2
I would introduce an extra variable though to keep the value of --base to have control and make debugging easier.
- Likes 1
Comment
-
Hello Chippy,
If the method crashes the platform that means you entered an infinite loop. You would need to use prints to identify what the problem is with the way you have called the method recursively. One problem may be that you are trying to decrement a passed in variable. I am not sure what your goal was with the method to comment on a possible solution however using a Print with the variables you are using should help to identify what the problem is before the crash.
If possible I would suggest to avoid recursive functions and use a standard finite for loop.
Please let me know if I can be of additional help.
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by MJ123, Today, 04:06 PM
|
2 responses
15 views
0 likes
|
Last Post
![]()
by MJ123
Today, 09:46 PM
|
||
Started by Skifree, Yesterday, 01:33 PM
|
5 responses
50 views
0 likes
|
Last Post
![]()
by Skifree
Today, 09:24 PM
|
||
Started by dgutz15, 12-12-2022, 11:50 PM
|
4 responses
62 views
0 likes
|
Last Post
![]()
by drsclaud23
Today, 08:50 PM
|
||
Started by xtremel, Today, 08:48 PM
|
0 responses
14 views
0 likes
|
Last Post
![]()
by xtremel
Today, 08:48 PM
|
||
Started by SilverSurfer1, Today, 08:27 PM
|
0 responses
5 views
0 likes
|
Last Post
![]() |
Comment