Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Same strategy, different ninjascript, different results
Collapse
X
-
-
-
I compiled the code. I have made the changes, there are changes in results but not close to my friend's results.
Code:protected override void OnBarUpdate() { //Enter long if(Close[0] > SMA(200)[0] && RSI(2, 0)[0] <= 10); { EnterLong(DefaultQuantity, "Long"); } //Enter short if(Close[0] < SMA(200)[0] && RSI(2, 0)[0] >= 90); { EnterShort(DefaultQuantity, "Short"); } //Exit long if(RSI(2, 0)[0] > 50); { ExitLong("Exit Long", ""); } //Exit short if(RSI(2, 0)[0] < 50); { ExitShort("Exit Short", ""); } }
Comment
-
That code is now completely equivalent to your friend's code. The only possible reason that you do not get the same results is because your data is different.Originally posted by NGorodzhiy View PostI compiled the code. I have made the changes, there are changes in results but not close to my friend's results.
Code:protected override void OnBarUpdate() { //Enter long if(Close[0] > SMA(200)[0] && RSI(2, 0)[0] <= 10); { EnterLong(DefaultQuantity, "Long"); } //Enter short if(Close[0] < SMA(200)[0] && RSI(2, 0)[0] >= 90); { EnterShort(DefaultQuantity, "Short"); } //Exit long if(RSI(2, 0)[0] > 50); { ExitLong("Exit Long", ""); } //Exit short if(RSI(2, 0)[0] < 50); { ExitShort("Exit Short", ""); } }- Do you two use the exact same data provider?
- Are your test "date ranges" exactly the same?
If your comparison tests are actually all on your own computer, rather that a comparison of your friend's to yours, you might try downloading all data afresh before you run the tests.
The only other suggestion is to compare the trades that are being taken. They will not be the same, and likely they will not even be the same number of trades. Once you have that data, you should be able to see what is really going on. Sometimes it does get hairy trying to track this stuff down. Just keep at it.
Comment
-
Results are still different. I am testing everything from the same computer, connected to Kinetick. I uploaded charts from the different strategies. "Radin - chart" is my friend's, "Nikita - chart" is mine. Maybe by looking at the charts you will figure out how to solve this. Thanks for the help.
Comment
-
Please help me fix it, the results are still different. I am getting frustrated because I and everyone thinks the ninjascript is the same, but the results are coming out different.
Comment
-
I am trying to enter a position long when a the close price is larger than the 200 period SMA and when the RSI is below 10. I would exit when the RSI is above 50. When going short, everything is reversed. The problem is that it is avoiding the SMA and still entering the trades. How to fix it? I have attached an image so it is easier to understand.
Comment
-
That's because the two pieces of code are not the same.Originally posted by NGorodzhiy View PostI compiled the code. I have made the changes, there are changes in results but not close to my friend's results.
Code:protected override void OnBarUpdate() { //Enter long if(Close[0] > SMA(200)[0] && RSI(2, 0)[0] <= 10); [COLOR=Red]// <-- remove ; here[/COLOR] { EnterLong(DefaultQuantity, "Long"); } //Enter short if(Close[0] < SMA(200)[0] && RSI(2, 0)[0] >= 90); [COLOR=Red]// <-- remove ; here[/COLOR] { EnterShort(DefaultQuantity, "Short"); } //Exit long if(RSI(2, 0)[0] > 50); [COLOR=Red]// <-- remove ; here[/COLOR] { ExitLong("Exit Long", ""); } //Exit short if(RSI(2, 0)[0] < 50); [COLOR=Red]// <-- remove ; here[/COLOR] { ExitShort("Exit Short", ""); } }
Remove the semi-colons from the end of the conditionals of all your if statements.
Seriously (not trying to be sarcastic) learn about C# programming. It is obvious that you have little experience programming, this is a very VERY rookie mistake. To correct that brain deficiency, you should spend a few hours using google, and do some reading. There are tons of useful and helpful websites just waiting to teach you basic rules of C# programming.
http://lmgtfy.com/?q=c%23+programming+tutorial
For ex, start with "The Basics" on the right hand side of this page:
http://csharp.net-tutorials.com/basics/if-statement/
or download their entire tutorial as a PDF (see upper right link).
If you didn't know before that C# is VERY specific about where you place semi-colons, well, now you know.
Comment
-
Thank you so much! I know I am bad at C#, I just started learning. I am learning via Microsoft virtual school, they have great tutorials. Thanks for the tips anyways.
Comment
-
Look here,
scroll down to "The Phantom Semi-Colon" ...
Comment
-
No problem.
As a beginner, I cannot stress enough the importance of indenting your code to recognize control flow. As you learn and grow, you should adopt a personal mandate to always write correctly indented code, as well as fix indention of code sent to you for consultation *before you start reading it*.
For that last part, there are actual programs that will auto-indent your code, they're known as code "beautifiers" or code "pretty-printers".
So, if you had to beautify 1000s of lines of code, say, to fix the indention, you'd want an automated way to do that.
My point is: such an automated program immediately points out this kind of rookie mistake of the phantom semi-colon.
My second point is: use this feature of a C# beautifier program to help you find problems with your code. When it's 2am and your eyes (and your friend's eyes) can't find it, such a program could be very useful.
Look at the search results for:
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
91 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
48 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
31 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
34 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
69 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment