Van Tharp's SQN (system quality number) - futures io
futures io



Van Tharp's SQN (system quality number)


Discussion in Psychology and Money Management

Updated
      Top Posters
    1. looks_one Big Mike with 9 posts (2 thanks)
    2. looks_two Luger with 5 posts (9 thanks)
    3. looks_3 nivi with 3 posts (0 thanks)
    4. looks_4 caprica with 2 posts (3 thanks)
      Best Posters
    1. looks_one RM99 with 2 thanks per post
    2. looks_two Luger with 1.8 thanks per post
    3. looks_3 caprica with 1.5 thanks per post
    4. looks_4 Big Mike with 0.2 thanks per post
    1. trending_up 30,190 views
    2. thumb_up 17 thanks given
    3. group 28 followers
    1. forum 33 posts
    2. attach_file 5 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Van Tharp's SQN (system quality number)

(login for full post details)
  #1 (permalink)
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
 
caprica's Avatar
 
Posts: 155 since Jul 2009
Thanks: 45 given, 112 received

Hello. I just uploaded this to the Ninja Strategies section. It is really a unique method to optimize your strategies on.

This is Van Tharp's System Quality Number (SQN) optimizer type for NinjaTrader. Place the SQN.cs file in your Documents\NinjaTrader 6.5\bin\custom\Type directory and then exit and reload Ninja.

Here is information from Ragingbull on SQN:

Quoting 
The only way to seriously qualify and optimize any system is through its System Quality Number (SQN). I advice you to refer to Van Tharp for reference on the subject.

Assuming a set of N trades (N>30 for being statistically significant), SQN is defined as follow:

SQN= Squareroot(N) * Average (of the N Profit&Loss) / Std dev (of the N Profit&Loss).

The large the N, the more trading opportunities you have.
The large the average P&L, the better you are obviously.
The smaller the Std dev (P&L), the more regular are your results and the smaller are the drawdowns.

Note here that if you optimize for the largest SQN, you maximize in fact the product N*average P&L and you minimize the Std dev (P&L) and the drawdowns at the same time.

This is exactly what all good traders should be looking for their system.

The code itself was written by Pete S all credit to him.

If you want more information on the SQN (System Quality Number) or Van Tharp you can look here:
Definitive Guide to Position Sizing

To use this you need to use Strategy Analyzer and change your "Optimize on..." selection to "my system quality number". This is where you normally choose max net profit, or max profit factor, etc.

Download the file here:

"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

Started this thread Reply With Quote
The following 2 users say Thank You to caprica for this post:

Journal Challenge April 2021 results (now extended!):
Competing for $1800 in prizes from Jigsaw
looks_oneMaking a Living with the Microsby sstheo
(227 thanks from 25 posts)
looks_twoSalao's Journalby Salao
(58 thanks from 12 posts)
looks_3Deetee’s DAX Trading Journal (time based)by Deetee
(48 thanks from 18 posts)
looks_4Learning to Profit - A journey in algorithms and optionsby Syntax
(37 thanks from 15 posts)
looks_5Maybe a little bit different journalby Malykubo
(17 thanks from 16 posts)
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Big Mike in Ecuador
76 thanks
The Crude Dude Oil Trading System
74 thanks
Help improve the FIO community
38 thanks
The New Micro Contract - MICRO BITCOIN coming May 2021
29 thanks
Webinar: Seven Trading Mistakes Solved With Smart Tradin …
26 thanks
 
(login for full post details)
  #2 (permalink)
 caprica 
USA
 
Experience: Master
Platform: NinjaTrader
 
caprica's Avatar
 
Posts: 155 since Jul 2009
Thanks: 45 given, 112 received

Here is a brief PDF that is a sample only of the table of contents from the publisher of Van Tharp's book "Definitive Guide to Position Sizing", to whet your appetitive and interest you in purchasing this book.

Attached Thumbnails
Van Tharp's SQN (system quality number)-table-contents-definitive-guide.pdf  
Started this thread Reply With Quote
The following user says Thank You to caprica for this post:
 
(login for full post details)
  #3 (permalink)
kekkis
Norway
 
 
Posts: 6 since Jun 2009
Thanks: 1 given, 1 received


Hi

Do you have SQN update for ninja 7
thanks
regards

Reply With Quote
 
(login for full post details)
  #4 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
 
Posts: 295 since May 2010
Thanks: 97 given, 322 received


kekkis View Post
...Do you have SQN update for ninja 7...

I'd suggest you see:

Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to fluxsmith for this post:
 
(login for full post details)
  #5 (permalink)
 pengi 
Tokyo, Japan
 
Experience: Intermediate
Platform: NT7
Trading: GC
 
pengi's Avatar
 
Posts: 35 since Jan 2011
Thanks: 26 given, 40 received


caprica View Post
SQN = Squareroot(N) * Average (of the N Profit&Loss) / Std dev (of the N Profit&Loss).

Hi @caprica,

Thanks for your contribution towards helping everyone optimize their systems for SQN. I'm a big fan of Tharp's work as well.

However, I believe the formula you posted above is incorrect, or at least flawed in a big way.

From what I understand, Tharp basis is the risk of each trade, which he calls R. He uses the R-multiple of trades to calculate the SQN. However, the formula you posted doesn't use R at all. Since you are going by what someone else posted, I want to ask you to double check this. Please consider the following method of how I calculate the SQN for my trades. It's my interpretation of Tharp's words, but I may be wrong as well. What do you think?

1) Calculate R, how much you risk per trade. For example, if you risk 2% of your account on each trade, and you have a $10k account, R would be 200.

2) Calculate the R-multiple of each trade. For example, if R is 200 and a given trade had a net profit of 400, then the trade's R-multiple was 2. If it lost 200, then the R-multiple for that trade is -1.

3) Calculate E, the expectancy of the system. I interpret this to be the average R-multiple of all trades. If your system has a positive expectancy, this should be greater than zero.

4) Calculate SQN, the ratio of E to the standard deviation of the R multiples dataset in step 2.

Reply With Quote
 
(login for full post details)
  #6 (permalink)
mehol
United Arab Emirates
 
 
Posts: 2 since Oct 2011
Thanks: 0 given, 0 received

I want to understand how to build up a system as VAN TAHRP talks about low risk idea.

Reply With Quote
 
(login for full post details)
  #7 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received

@Luger,

Regarding the SQN*maxprofit you shared. Years ago I used a similar scoring system, but it also weighted based on trade frequency as well as long vs short. I am having trouble finding my old Optimizer Type code, so thought I would ask if you would code this, since I am so rusty with NT.

The idea is to expand on your SQN*maxprofit, adding:

1) Higher score for more trades per day. I value this because I believe if a system has a true edge, then greater frequency can demonstrate that edge by beating out slippage and commissions, and fight curve fitting.

2) Weight score based on Long vs Short performance. For example, if Long's account for 80% of profit, then this would score badly. Optimal would be 50/50.

Thank you kindly, if you could do this for me.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
(login for full post details)
  #8 (permalink)
 RM99 
Austin, TX
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
 
Posts: 882 since Mar 2011
Thanks: 124 given, 701 received


Big Mike View Post
@Luger,

Regarding the SQN*maxprofit you shared. Years ago I used a similar scoring system, but it also weighted based on trade frequency as well as long vs short. I am having trouble finding my old Optimizer Type code, so thought I would ask if you would code this, since I am so rusty with NT.

The idea is to expand on your SQN*maxprofit, adding:

1) Higher score for more trades per day. I value this because I believe if a system has a true edge, then greater frequency can demonstrate that edge by beating out slippage and commissions, and fight curve fitting.

2) Weight score based on Long vs Short performance. For example, if Long's account for 80% of profit, then this would score badly. Optimal would be 50/50.

Thank you kindly, if you could do this for me.

Mike

Mike, I agree with your effort to sanity check the system and ensure that it's not long or short biased, but how do you account for the dataset bias?

If you were to take an data set for CL from the highs of 2008 till today, featuring a trend trading system, obviously you're going to generate more profit on the short side, simply because the entire market moved short a great deal (macro) from then till now.

I guess I would prefer to use the long/short ratios as a sanity check or post analysis screening criteria rather than an evaluation criteria (depending on the system's approach).

I do the same thing for profit distributions. Rarely (if ever) is a system able to hit high marks on every criteria (drawdown, expectancy, trade sample size, etc) and I find that some systems, I largely rejected simply because it earned too high of a profit% in a couple of months during the sample. Obviously, we'd all love a consistent profit distribution where every month is similar. But in reality, the markets don't feed us that way, and it's difficult to massage a system to vary depending on the market conditions (sometimes).

So now I look at the distributions and as long as all the profit isn't in one or 2 months AND there's little to no negative months, then that's okay. I call it the "fishing" centric systems, that wait (patiently) for those few time periods that really kill it, then during the other time periods they either hold flat or lose a very small amount.

Obviously that's asking a lot (for a trader to sit and fish for months waiting on the whopper months) but it's exactly what a lot of Fundamental traders do. There are a lot of fundamental traders that will make their whole year based on a couple of good months. Which really capitalizes on the concept of big winners and tiny losers.

"A dumb man never learns. A smart man learns from his own failure and success. But a wise man learns from the failure and success of others."
Reply With Quote
The following 2 users say Thank You to RM99 for this post:
 
(login for full post details)
  #9 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


RM99 View Post
Mike, I agree with your effort to sanity check the system and ensure that it's not long or short biased, but how do you account for the dataset bias?

Yes absolutely. I basically write two kinds of strategies, small time frame and big time frame. For the small time frame system I believe the 50/50 split is realistic because the amount of time in the market is minimal per trade, it is not influenced heavily by bigger trends.

I wish I could find my old code, I spent a huge amount of time developing that optimizer type just the way I wanted it. It is in a backup file somewhere.

I cannot remember all the reserve keywords with NT, so am having trouble remembering how I had mine set up.

If there are 100 trades total, 50 long, 50 short, but the 50 longs account for 80% of the profit, I want this to score badly. My strategy is not written well if it takes 50 short trades that only account for 20% of the profit compared to long trades.

I had a lot of code in my optimizer setup to prevent curve fitting. I also prefer to optimize against huge data sets, multi-year of tick data, with thousands of trades per year. I'll keep digging for it.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #10 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 543 received



Big Mike View Post
@Luger,

Regarding the SQN*maxprofit you shared. Years ago I used a similar scoring system, but it also weighted based on trade frequency as well as long vs short. I am having trouble finding my old Optimizer Type code, so thought I would ask if you would code this, since I am so rusty with NT.

The idea is to expand on your SQN*maxprofit, adding:

1) Higher score for more trades per day. I value this because I believe if a system has a true edge, then greater frequency can demonstrate that edge by beating out slippage and commissions, and fight curve fitting.

2) Weight score based on Long vs Short performance. For example, if Long's account for 80% of profit, then this would score badly. Optimal would be 50/50.

Thank you kindly, if you could do this for me.

Mike

I will take a detailed look this evening. #2 should not be hard, with #1 I will have to figure out how to get a proper day count.

Reply With Quote
The following user says Thank You to Luger for this post:
 
(login for full post details)
  #11 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 543 received

@Big Mike

I am attaching your requested optimizer type. The new score considers Max Profit, SQN, Trades per Day, and the ratio of Long Profit to Short Profit.

There is one variable in there for the Long/Short Profit that is easy to change. I was not sure how sensitive you wanted this metric to be. I left comments in explaining.

//This value represents the floor to a divisor representing long short profit split
//0.1 = (60/40 split = 50/50 split = 40/60 split) performance would be halved at (70/30, 30/70)
//For a value of 0.05 (55/45 split = 50/50 split = 45/55 split)
//performance would be halved at (60/40, 40/60)
double rngLongShortBalance = 0.1;
//Actual calculation so that you can see what I am dividing by in the final output.
double rngLSbalance = Math.Max(rngLongShortBalance, Math.Abs(0.5 - (totLongProfit / totProfit)));

Basically, I thought you could use that variable to to set your own acceptable range outside of which there are reductions in the final score.

Otherwise the final score looks like this:

(SQN * Max Profit * Trades per Day) / (Long Short Ratio derivative)

To install place attached file in:
NinjaTrader7\bin\Custom\Type
Open Ninja Trader editor and compile any indicator or strategy

I am also going to take a look at the idea you mentioned about variation around a smooth upward sloping profit line as a possible improvement to the SQN number. Right now I can't visualize if that is going to be an improvement or end up causing problems somewhere.

Attached Files
Register to download File Type: cs SQNlsprofitbalancetraderate.cs (3.8 KB, 100 views)
Reply With Quote
The following 3 users say Thank You to Luger for this post:
 
(login for full post details)
  #12 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


Luger View Post
@Big Mike

I am attaching your requested optimizer type. The new score considers Max Profit, SQN, Trades per Day, and the ratio of Long Profit to Short Profit.

There is one variable in there for the Long/Short Profit that is easy to change. I was not sure how sensitive you wanted this metric to be. I left comments in explaining.

//This value represents the floor to a divisor representing long short profit split
//0.1 = (60/40 split = 50/50 split = 40/60 split) performance would be halved at (70/30, 30/70)
//For a value of 0.05 (55/45 split = 50/50 split = 45/55 split)
//performance would be halved at (60/40, 40/60)
double rngLongShortBalance = 0.1;
//Actual calculation so that you can see what I am dividing by in the final output.
double rngLSbalance = Math.Max(rngLongShortBalance, Math.Abs(0.5 - (totLongProfit / totProfit)));

Basically, I thought you could use that variable to to set your own acceptable range outside of which there are reductions in the final score.

Otherwise the final score looks like this:

(SQN * Max Profit * Trades per Day) / (Long Short Ratio derivative)

To install place attached file in:
NinjaTrader7\bin\Custom\Type
Open Ninja Trader editor and compile any indicator or strategy

I am also going to take a look at the idea you mentioned about variation around a smooth upward sloping profit line as a possible improvement to the SQN number. Right now I can't visualize if that is going to be an improvement or end up causing problems somewhere.

You rock!

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #13 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 543 received

I am attaching the Perfect Equity Curve (PEC) variants as well.

PEC
PEC * Max Profit
(PEC * Max Profit * Trades per Day) / (Long Short ratio derivative)

I would stay with the SQN and variants. The PEC versions truly do favor smoother curves at the expense of many other considerations. This ended up mostly an academic exercise, and I am posting just for anyone that is curious. Though I guess it could be used to check a smaller optimization field once the larger population has been narrowed down.

For example, I optimized one variable on my bot with just PEC. Usually the top few choices run from 58k-63k profit. Pure PEC gave me 22k for the first three, then got to some in the mid to upper 50k.

Attached Files
Register to download File Type: cs PEC.cs (2.2 KB, 70 views)
Register to download File Type: cs PECmaxprofit.cs (2.4 KB, 56 views)
Register to download File Type: cs PEClsprofitbalancetraderate.cs (3.9 KB, 50 views)
Reply With Quote
The following 4 users say Thank You to Luger for this post:
 
(login for full post details)
  #14 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


Luger View Post
I am attaching the Perfect Equity Curve (PEC) variants as well.

PEC
PEC * Max Profit
(PEC * Max Profit * Trades per Day) / (Long Short ratio derivative)

I would stay with the SQN and variants. The PEC versions truly do favor smoother curves at the expense of many other considerations. This ended up mostly an academic exercise, and I am posting just for anyone that is curious. Though I guess it could be used to check a smaller optimization field once the larger population has been narrowed down.

For example, I optimized one variable on my bot with just PEC. Usually the top few choices run from 58k-63k profit. Pure PEC gave me 22k for the first three, then got to some in the mid to upper 50k.

Thanks for this. What kind of sample size and trade frequency did you use in your test? I can imagine the fewer the trades, the more this will not make any sense.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #15 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 543 received

It was small numbers compared to what I know you are planning...lol

Range was from 60 to 170 trades for those weird results. The PEC results in general, even for the variants, are certainly much more rigid than SQN. Instead of comparing to trade results to average profit and compiling, you are comparing current cumulative profit to where current cumulative profit should be based on average profit (average profit * trade number) and compiling. Effectively the variance can accrue trade to trade.

Reply With Quote
 
(login for full post details)
  #16 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


Luger View Post
I am attaching the Perfect Equity Curve (PEC) variants as well.

PEC
PEC * Max Profit
(PEC * Max Profit * Trades per Day) / (Long Short ratio derivative)

I would stay with the SQN and variants. The PEC versions truly do favor smoother curves at the expense of many other considerations. This ended up mostly an academic exercise, and I am posting just for anyone that is curious. Though I guess it could be used to check a smaller optimization field once the larger population has been narrowed down.

For example, I optimized one variable on my bot with just PEC. Usually the top few choices run from 58k-63k profit. Pure PEC gave me 22k for the first three, then got to some in the mid to upper 50k.

So far the PEC model seems to be performing very well. I am still wet behind the ears when it comes to Ninja and C#, I am having to re-learn stuff all over again after being out of it for years. But it seems that your code works. Once I get some more complex strategies converted, I'll know for sure

In my testing, the PEC model produces quicker [genetic time] and more desirable results than the other SQN types you provided.

Looking forward to it, and really want to thank you again.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #17 (permalink)
 NW27 
Newcastle, Australia
 
Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker: IB
Trading: SPI,FTSE100, 6E, 6A
 
Posts: 285 since Oct 2010
Thanks: 108 given, 186 received

Hi
Im very interested in this topic but Im a multicharts user.
Would you have this code in a pseudo form so that I can generate easylanguage code?

Regards,
Neil.

Reply With Quote
 
(login for full post details)
  #18 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


NW27 View Post
Hi
Im very interested in this topic but Im a multicharts user.
Would you have this code in a pseudo form so that I can generate easylanguage code?

Regards,
Neil.

The source was posted already, MultiCharts uses C# for its optimizer type thing (whatever it is called). They don't document anything, so good luck finding the right keywords. It is not EasyLanguage.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #19 (permalink)
 Silver Dragon 
Legendary Data Wizard!!!
Cincinnati Ohio
 
Experience: Intermediate
Platform: TastyWorks
Broker: TastyWorks
Trading: FX, Stocks, Options
 
Silver Dragon's Avatar
 
Posts: 2,012 since Feb 2011
Thanks: 5,770 given, 4,887 received


Luger View Post
I am attaching the Perfect Equity Curve (PEC) variants as well.

PEC
PEC * Max Profit
(PEC * Max Profit * Trades per Day) / (Long Short ratio derivative)

I would stay with the SQN and variants. The PEC versions truly do favor smoother curves at the expense of many other considerations. This ended up mostly an academic exercise, and I am posting just for anyone that is curious. Though I guess it could be used to check a smaller optimization field once the larger population has been narrowed down.

For example, I optimized one variable on my bot with just PEC. Usually the top few choices run from 58k-63k profit. Pure PEC gave me 22k for the first three, then got to some in the mid to upper 50k.

@Luger

Trying to understand the code; What does this part of the code do?

SD

 
Code
for (n = 0; n < Strategy.Parameters.Count; n++)
		{
		if ("SQNMinTrades".CompareTo(Strategy.Parameters[n].Name) == 0)
			{
				minTrades = (int)Strategy.Parameters[n].Value;
				break;
			}

nosce te ipsum

You make your own opportunities in life.
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #20 (permalink)
 Luger 
Nashville, TN
 
Experience: Intermediate
Platform: NinjaTrader
Broker: IB
Trading: NQ ES
 
Posts: 468 since Feb 2011
Thanks: 323 given, 543 received


Silver Dragon View Post
@Luger

Trying to understand the code; What does this part of the code do?

SD

 
Code
for (n = 0; n < Strategy.Parameters.Count; n++)
		{
		if ("SQNMinTrades".CompareTo(Strategy.Parameters[n].Name) == 0)
			{
				minTrades = (int)Strategy.Parameters[n].Value;
				break;
			}

It was in the original SQN code so I left it. If there are less than 30 trades, then SQN returns zero due to too small of a sample. I think that part also checks the number of parameters in the strategy and if there are more than 30, then that number becomes the floor.

I could be totally wrong. It would be nice to have someone who is a better coder to evaluate that section because it may just be wasting cpu cycles.

Reply With Quote
The following user says Thank You to Luger for this post:
 
(login for full post details)
  #21 (permalink)
 NJAMC 
Atkinson, NH USA
 
Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker: NinjaTrader Brokerage
Trading: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,965 since Dec 2010
Thanks: 3,035 given, 2,379 received


Luger View Post
It was in the original SQN code so I left it. If there are less than 30 trades, then SQN returns zero due to too small of a sample. I think that part also checks the number of parameters in the strategy and if there are more than 30, then that number becomes the floor.

I could be totally wrong. It would be nice to have someone who is a better coder to evaluate that section because it may just be wasting cpu cycles.

Hi @Luger,

Not sure if it still matters, but happen to be pointed to this thread for your PEC, but in the Loop, it appears this is scanning for a parameter named "SQNMinTrades", when if finds the parameter, it sets minTrades equal to that value and the bails out of the loop with the break statement. So, if there are 100+ parameters, and the 2nd parameter is found to be "SQNMinTrades" it retrieves the value and then exits the For loop, saving 98 or so useless comparisons as there is likely an assumption the parameter is unique int he list.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #22 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


Luger View Post
I am attaching the Perfect Equity Curve (PEC) variants as well.

PEC
PEC * Max Profit
(PEC * Max Profit * Trades per Day) / (Long Short ratio derivative)

I would stay with the SQN and variants. The PEC versions truly do favor smoother curves at the expense of many other considerations. This ended up mostly an academic exercise, and I am posting just for anyone that is curious. Though I guess it could be used to check a smaller optimization field once the larger population has been narrowed down.

For example, I optimized one variable on my bot with just PEC. Usually the top few choices run from 58k-63k profit. Pure PEC gave me 22k for the first three, then got to some in the mid to upper 50k.

@Luger,

Would it be possible for you to make a small edit to these please?

I need to discard runs that result in an "Infinity" score, ie 100% percent profitable. What's happening is sometimes the optimizer is finding a magic combination that gives it extremely low trade frequency (ie 50 trades) but 100% winners, and it's overriding the trades I really want (ie 5,000 trades @ 40%).

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #23 (permalink)
 Outlier 
Germany
 
Experience: Advanced
Platform: TradeStation
Trading: Futures
 
Posts: 88 since May 2012
Thanks: 53 given, 93 received


Big Mike View Post
@Luger,

Would it be possible for you to make a small edit to these please?

I need to discard runs that result in an "Infinity" score, ie 100% percent profitable. What's happening is sometimes the optimizer is finding a magic combination that gives it extremely low trade frequency (ie 50 trades) but 100% winners, and it's overriding the trades I really want (ie 5,000 trades @ 40%).

Mike

I'd rather implement a minimum number of trades requirement for this type of fitness function. Not dependent on the number of parameters, that doesn't make sense to me, just a user provided value.

Reply With Quote
 
(login for full post details)
  #24 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received


Outlier View Post
I'd rather implement a minimum number of trades requirement for this type of fitness function. Not dependent on the number of parameters, that doesn't make sense to me, just a user provided value.

I am not aware that NT7 has that capability, to pass a user value to the Fitness test. If it does, that would be fine by me as well.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #25 (permalink)
 Big Mike 
Site Administrator
Swing Trader
Data Scientist & DevOps
Manta, Ecuador
 
Experience: Advanced
Platform: Custom solution
Trading: Futures & Crypto
 
Big Mike's Avatar
 
Posts: 50,004 since Jun 2009
Thanks: 32,468 given, 98,283 received

New thread for Optimizer Types



Will update more later.

Mike

We're here to help -- just ask

For the best trading education, watch our webinars
Searching for trading reviews? Review this list

Follow us on Twitter, YouTube, and Facebook

Support our community as an Elite Member:
https://futures.io/elite/

Visit other sites? Please spread the word about your experience with our community!
Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #26 (permalink)
agustinfga
Monterrey Mexico
 
 
Posts: 2 since May 2016
Thanks: 0 given, 0 received


Luger View Post
@Big Mike

I am attaching your requested optimizer type. The new score considers Max Profit, SQN, Trades per Day, and the ratio of Long Profit to Short Profit.

There is one variable in there for the Long/Short Profit that is easy to change. I was not sure how sensitive you wanted this metric to be. I left comments in explaining.

//This value represents the floor to a divisor representing long short profit split
//0.1 = (60/40 split = 50/50 split = 40/60 split) performance would be halved at (70/30, 30/70)
//For a value of 0.05 (55/45 split = 50/50 split = 45/55 split)
//performance would be halved at (60/40, 40/60)
double rngLongShortBalance = 0.1;
//Actual calculation so that you can see what I am dividing by in the final output.
double rngLSbalance = Math.Max(rngLongShortBalance, Math.Abs(0.5 - (totLongProfit / totProfit)));

Basically, I thought you could use that variable to to set your own acceptable range outside of which there are reductions in the final score.

Otherwise the final score looks like this:

(SQN * Max Profit * Trades per Day) / (Long Short Ratio derivative)

To install place attached file in:
NinjaTrader7\bin\Custom\Type
Open Ninja Trader editor and compile any indicator or strategy

I am also going to take a look at the idea you mentioned about variation around a smooth upward sloping profit line as a possible improvement to the SQN number. Right now I can't visualize if that is going to be an improvement or end up causing problems somewhere.

Is there an update of this metric or optimizer fitness for nt8?

Can somebody do that? I have tried but I don't I have enough experience or undestanding

Reply With Quote
 
(login for full post details)
  #27 (permalink)
agustinfga
Monterrey Mexico
 
 
Posts: 2 since May 2016
Thanks: 0 given, 0 received

Do you have an update for NĦinjaTrader 8?

Reply With Quote
 
(login for full post details)
  #28 (permalink)
nivi
Madrid, Spain
 
 
Posts: 30 since Feb 2017
Thanks: 4 given, 6 received

Hello,

I am looking for SQN.cs for NT8. I want to optimize by the SQN ratio with NT8, but I can't find this document anywhere.

Thanks.

Reply With Quote
 
(login for full post details)
  #29 (permalink)
alex224
Madrid
 
 
Posts: 2 since Nov 2018
Thanks: 0 given, 0 received


nivi View Post
Hello,

I am looking for SQN.cs for NT8. I want to optimize by the SQN ratio with NT8, but I can't find this document anywhere.

Thanks.

Hi NIVI

Did you find SQN.cs for NT8?

Thanks

Reply With Quote
 
(login for full post details)
  #30 (permalink)
nivi
Madrid, Spain
 
 
Posts: 30 since Feb 2017
Thanks: 4 given, 6 received

Hello,
I did not find that code.

Some months have passed, I have discovered several important failures in NT8, and also in MultiCharts, and also in other trading programs.

Finally I made the decision to create my own analysis program. I do studies and analysis using only excel.

Soon I will create another excel to launch operations of my real broker account.

Reply With Quote
 
(login for full post details)
  #31 (permalink)
 buzzsaw 
Leesburg, VA
 
Experience: Advanced
Platform: NinjaTrader
 
Posts: 80 since Aug 2010
Thanks: 77 given, 33 received

What are those failures? Will you be sharing your excel replacements?

Reply With Quote
 
(login for full post details)
  #32 (permalink)
nivi
Madrid, Spain
 
 
Posts: 30 since Feb 2017
Thanks: 4 given, 6 received

NinjaTrader Failure:
- Optimize 30min time frame it takes the same time than optimize 1min time frame.
- When you make backtest or optimize and appears a big gap, and there was a limited entry order the entry price does not run at the opening level of the next bar.

Multicharts Failure:
- Using IB with friends and family account, only can see the accound by de "ID" like U1232123, U333444, U565656... You can't personalize the account name, for example: Paul, Enri,... Now imagine that you are working with 10 different accounts
- Using IB with friends and family account then the total money that exists in each account is not truly shown. For example, an account have 30.000€, then get lost 1.000€, logically they should be seen 29.000€, but Multicharts continues showing 30.000€

My personal excel now is only for optimization and backtest. It is simple but work just as I need.
I need SQN? I have SQN.
I do not need to see decimal numbers in the average profit.

Then I see what I want, the way I want it and without mistakes.

Reply With Quote
 
(login for full post details)
  #33 (permalink)
 wolfcuring 
ChangChun+China
 
Experience: Intermediate
Platform: Ninja Trader 8
Trading: Futures
 
Posts: 4 since Oct 2011
Thanks: 1 given, 0 received


caprica View Post
Hello. I just uploaded this to the Ninja Strategies section. It is really a unique method to optimize your strategies on.

This is Van Tharp's System Quality Number (SQN) optimizer type for NinjaTrader. Place the SQN.cs file in your Documents\NinjaTrader 6.5\bin\custom\Type directory and then exit and reload Ninja.

Here is information from Ragingbull on SQN:


The code itself was written by Pete S all credit to him.

If you want more information on the SQN (System Quality Number) or Van Tharp you can look here:
Definitive Guide to Position Sizing

To use this you need to use Strategy Analyzer and change your "Optimize on..." selection to "my system quality number". This is where you normally choose max net profit, or max profit factor, etc.

Download the file here:


Hi everybody, just following up this thread.

In Tharpe's book, he talked about the drawback of the SQN, that it can be distorted by a large number of trades. So, his remedy is to truck number above 100 to 100.

So,
If (Number of Trades >=100)

SQN =10 * Average Profit/StdDev(AllTrades)

While in this case, the favorable number of trades is only between 30 and 100. This range is quite small! And when I used SQN to evaluate the system quality, it seems to have a bias toward small trade numbers between 30-100.

How do you guys think of that? Is there a way to remedy this?

Reply With Quote
 
(login for full post details)
  #34 (permalink)
 asymptote 
Mississauga
 
Experience: Intermediate
Platform: Ninjatrader
Broker: GGI/ Kinetick
Trading: Emini
 
Posts: 9 since Nov 2017
Thanks: 2 given, 3 received

Interesting Point about SQN = Sharp ratio.
https://fxrenew.com/forex-blog/how-to-measure-your-trading-system-quality/

Reply With Quote


futures io Trading Community Psychology and Money Management > Van Tharp's SQN (system quality number)


Last Updated on July 23, 2019


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1,800 in prizes!

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts