NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript File Sharing > NinjaScript File Sharing Discussion

NinjaScript File Sharing Discussion Discussion for shared NinjaScript files.

Reply
 
Thread Tools Display Modes
Old 12-13-2007, 05:41 AM   #1
Pete S
Senior Member
 
Join Date: Jul 2007
Location: Fairfax, VA
Posts: 216
Thanks: 0
Thanked 0 times in 0 posts
Default New Optimizer Type: System Quality Number

Updated: please download SQN.cs (for NT version 6.5) from the Genetic Optimizer thread in this forum. I don't want to maintain the file in 2 places and it is required for that optimizer as well. Thanks.

This is a new optimizer type for comparing strategies in the Strategy Analyzer called System Quality Number. The formula is

SQN = sqrt(N) * average("Profit") / stddev("Profit")

where N is the number of trades, which encourages a large number of trades, a large average profit, and a small standard deviation. You can read more about Ragingbull's description of this number in the original thread that I coded the optimizer from here: http://www.ninjatrader-support.com/v...ead.php?t=4320

To install, take SQN6 if you are running 6.0, or SQN if you are running 6.5.

1. Copy this to My Documents/Ninja Trader 6[.5]/bin/Custom/Type
2. Recompile any of your indicators or strategies -- this will cause the optimizer type to be compiled as well
3. "my system quality number" will show up in your list of optimizer types
4. The SQN value shows up in the Performance column on the grid (see attached screenshot)

Keep in mind that as far as I know, this type of customization is not supported by NT, so if anything goes wrong, a reinstall may be your only recourse. Having said that, I have not had any issues thus far.

Feel free to post issues in this thread and I will try to help.
Attached Images
File Type: jpg MACrossResults.jpg (95.9 KB, 464 views)
Attached Files
File Type: cs SQN6.cs (2.2 KB, 227 views)
Last edited by Pete S; 02-12-2008 at 05:47 AM. Reason: Moved SQN.cs to Genetic Optimizer thread
Pete S is offline  
Reply With Quote
Old 12-13-2007, 11:09 AM   #2
ryker
Senior Member
 
Join Date: Dec 2007
Location: Guernsey (UK)
Posts: 152
Thanks: 0
Thanked 1 time in 1 post
Default

Thanks very much for your work and to Raging Bull aswell.
You brought us a nice tool here!
Last edited by ryker; 12-13-2007 at 11:31 AM.
ryker is offline  
Reply With Quote
Old 01-04-2008, 01:23 PM   #3
dwt__
Member
 
Join Date: Nov 2007
Posts: 40
Thanks: 7
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by ryker View Post
You brought us a nice tool here!
AND, a window into just how other fitness functions could be created.

Thanks.

dwt
dwt__ is offline  
Reply With Quote
Old 08-03-2008, 09:27 AM   #4
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default Static class variable

Hi,

I noticed the following 2 declaration in the SQN source file:

public class SQN : OptimizationType
{
public static double sLastSQN;
public static int sMinTrades = 0;


This 2 variables are declared static. If you should ever create more than one instance of this class, then these variables are shared across all class instances. I am not sure this is intended behaviour, especially for sLastSQN.

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 08-03-2008, 10:30 PM   #5
Paul_J
Member
 
Join Date: Jan 2008
Posts: 32
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi,

I'm running NT 6.5 so I need SQN.cs. I did a search but I came up empty. Can someone post a link to that file?

Thanks,
Paul_J is offline  
Reply With Quote
Old 08-04-2008, 01:12 AM   #6
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by Paul_J View Post
Hi,

I'm running NT 6.5 so I need SQN.cs. I did a search but I came up empty. Can someone post a link to that file?

Thanks,
http://www.ninjatrader-support.com/v...+number&page=2
Ralph is offline  
Reply With Quote
Old 08-12-2008, 09:08 AM   #7
latkinso
Senior Member
 
Join Date: May 2006
Location: , ,
Posts: 155
Thanks: 0
Thanked 0 times in 0 posts
Default Error Resolution

Hi

I have attempted to load the update to your optimizer and
receive this error message;

Type\SQN6.cs NinjaTRaderStrategy TradeCp;;ectopm" does not contain
a definition for 'performance" CS0117 Line 41 column 52

And same error message for line 42 column 33

Any Suggestions?

Thanks

Lynn
latkinso is offline  
Reply With Quote
Old 08-27-2008, 02:51 PM   #8
anachronist
Senior Member
 
Join Date: Jul 2008
Posts: 271
Thanks: 4
Thanked 7 times in 7 posts
Default

Quote:
Originally Posted by Pete S View Post
This is a new optimizer type for comparing strategies in the Strategy Analyzer called System Quality Number. The formula is

SQN = sqrt(N) * average("Profit") / stddev("Profit")

where N is the number of trades, which encourages a large number of trades, a large average profit, and a small standard deviation.
That's an interesting idea, but it penalizes you for having a few big profits in your sequence rather than steady profits. Some strategies simply aren't designed that way.

The system quality measure I'm more familiar with (via Van Tharp), described here can be reduced to

SQN = net_profit/average_loss

...where average_loss doesn't include "scratch" losses where you lose only commission and slippage. That formula also encourages maximizing both profit and quantity of trades, and minimizing losses.

Other trading platforms let you define your own custom optimization result. I'm still fairly new to NinjaTrader; doesn't NT let you do that too?

-Alex
anachronist is offline  
Reply With Quote
Old 04-29-2009, 07:43 AM   #9
lgarcia3
Senior Member
 
Join Date: Apr 2008
Posts: 105
Thanks: 0
Thanked 1 time in 1 post
Default

I have a question on the code. When you are going through each trade, you call several methods in the Trade class:

Code:
tradeProf = (t.ProfitPoints * t.Quantity * t.Entry.Instrument.MasterInstrument.PointValue);
Is ProfitPoints the number of points made/lost in the trade?
Quantity? Is that the number of contracts/Stocks traded in that transaction?
How about PointValue? the value per point per contract in currency?

So, say I trade 1 Contract of S&P Emini, at $50/point, and make 5 points that would be:

tradeProf = 5 * 1 * 50 = 250

Is that what it is?

Thanks!
lgarcia3 is offline  
Reply With Quote
Old 05-03-2009, 06:28 PM   #10
lgarcia3
Senior Member
 
Join Date: Apr 2008
Posts: 105
Thanks: 0
Thanked 1 time in 1 post
Default

I was asking about the code before because this SQN number looked familiar. I don't know who this Van Tharp guy is and I have not read his books; but I think he is claiming something that was published back in 1908. At least if he is claiming this as his discovery; but, again, I have not read his books.

What he calls "SQN" number, is actually the Student t statistics. You can read about it here:

Wiki Student T

I don't know, he may have been the first one to relate trading to statistics and that is why he is claiming it with that name (that is giving him the benefit of the doubt). I'm not a judge. But, definitely, it's not something "new".

I can say this, however, it is useful. I don't think it will "increase" the number of trades; at least not in my experience. It does optimize the number of trades though. And I can tell you also that a big "SQN" number is not necessarily good. In fact, a big "SQN" number may be a sign of over-fitting. So, be aware of that.

About the code, I would need to test some more; but I found it to increase rapidly after 2.5 or so and it would jump very fast. I am not sure why, I may be wrong. When I find it I will let you know.
lgarcia3 is offline  
Reply With Quote
Old 10-07-2009, 05:22 AM   #11
magicboiz
Junior Member
 
Join Date: Oct 2008
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

HI everybody

I've developed a futures strategy. After some optimization with the SQN, I get an SQN = 3.4 with 500 trades

¿3.4.....What does it mean? ¿Dollars? ¿Points? ¿Percent..?

¿Is it good or bad? ¿Is SQN a better indicator than sharpe ratio?

Regards
magicboiz is offline  
Reply With Quote
Old 10-07-2009, 05:07 PM   #12
Anagoge
Senior Member
 
Join Date: Sep 2008
Posts: 183
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by magicboiz View Post
¿3.4.....What does it mean? ¿Dollars? ¿Points? ¿Percent..?
¿Is it good or bad? ¿Is SQN a better indicator than sharpe ratio?
The SQN number isn't dollars, percent, or any other normal unit. It is just a unit-less measure of risk-adjusted performance (similar to the sharpe ratio). Higher numbers are better. If you want a more tangible number, look at something like cumulated profit, average trade %, etc. If you can get a 3.4 SQN with a few dozen actual or sim trades using realtime data (not historical data subject to curve fitting), then you are in very good shape. Whether the SQN is better than sharpe ratio is for you to decide based on your preferences for risk and return. In general, I slightly prefer it, since it doesn't penalize occasional very large winning periods the way the sharpe ratio does. My other favorite performance measure is a monthly Sortino Ratio, but it is not built-into NT.
Anagoge is offline  
Reply With Quote
Old 11-25-2009, 10:04 PM   #13
pepelucho
Junior Member
 
Join Date: Aug 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default what is a good SQN

I'm getting an SQN of 6.9 with about 400 trades over 3 years, is that good ?
pepelucho is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimization function - System Quality Number Ragingbull Market Analyzer 32 07-13-2009 12:16 PM
Problem with Optimizer JC_Fernandes Strategy Analyzer 5 10-17-2007 04:55 AM
Optimizer Suggestion NinjaTrader_Josh Suggestions And Feedback 2 08-12-2007 01:31 PM
about the optimizer HelloHello Strategy Development 1 08-11-2007 03:07 AM
Bug in Optimizer NinjaTrader_Josh Suggestions And Feedback 5 05-29-2007 02:02 AM


All times are GMT -6. The time now is 04:11 AM.