PDA

View Full Version : An easy way to incorporate a strategy performance plot to your strategies...


Elliott Wave
05-09-2008, 04:42 PM
I thought I would share a way to include a PnL plot in your strategies.

I personally find it extremely useful because it allows you to instantly see the results from changing strategy variables and makes it very easy to find the most effective time frame and optimal variables for your strategies.

To add this to your own strategies simply copy the parts in the code between:

//-----Copy this to your own strategy

//-------------


I hope if enough people find this useful that the NT development team will consider adding similar functionality to the strategy wizard in NT7 because its an almost universally useful feature, relatively simple, yet a PITA to add manually to every strategy.

Watch how easy it is to find the optimal time frame right from the chart! :) (might take a moment to load)

http://shup.com/Shup/40697/PnL-plot-Graph.gif

This works the same way for other variables too. Play around with this simple MACD crossover strategy and find the best results for your particular instrument.

Enjoy!

http://www.emofaces.com/en/emoticons/n/ninja-emoticon-black.gif

NinjaTrader_Dierk
05-09-2008, 10:11 PM
Thanks for your contribution. Would you mind posting the file sharing section?

Gumphrie
05-10-2008, 04:09 AM
Thanks Elliott Wave. I can see this can be useful in all sorts of ways.

jriverac
05-10-2008, 06:40 AM
Hi,

I downloaded your PnL test, run it on my NT, but there is no plot...

Any ideas what´s happening?

Thanks!

Elliott Wave
05-10-2008, 07:46 AM
Hi,

I downloaded your PnL test, run it on my NT, but there is no plot...

Any ideas what´s happening?

Thanks!

Check if you have any other indicators on the chart. By default the strategy plot goes to panel 2 but if you have an indicator already on that plot with a different scale, you may not be able to see it, even though its there. If thats the case simply use the 'results panel' parameter and stick it on a new panel.

jriverac
05-10-2008, 10:05 AM
Hi,

There is no other indicator. The scale of the panel nº2 goes from 0 to 1.

Is that correct?

Thanks!!

Elliott Wave
05-10-2008, 10:03 PM
It should autoscale based on the PnL.

I'm not sure what to suggest.

Are you using 6.5?

Have any trades plotted on the chart?

jriverac
05-11-2008, 01:26 AM
Hi,

Yes, I am using NT 6.5 (lastest version, updated 2 days ago), I can see the trades, no other indicators, everything seems to be ok, but no plot...

I have also tried to include your codes in my strategies (i think your idea is GREAT), but no luck...

I do not know what happens, but do not bother too much, I will sort it out!!

Regards

NinjaTrader_Josh
05-11-2008, 03:38 AM
You can try checking the Control Center logs. Perhaps some conflicts have cropped up between indicators.

jriverac
05-11-2008, 02:13 PM
The log is empty, nothing is said there, but the plot is still not there!

Regards,

PrTester
05-11-2008, 04:32 PM
The log is empty, nothing is said there, but the plot is still not there!

Regards,

You can try this version also http://www.ninjatrader-support.com/vb/showthread.php?t=4656

Elliott Wave
05-11-2008, 04:39 PM
Whitmark's code is the basis for this, so the results should be similar, if that one works for you and this doesn't I'd be curious to know why.

That reminds me, maybe I should add the ability to have the PnL plot reset at the start of each day like the original version.

Are other people having issues as well, or does it generally work as expected?

Before adding this to the file sharing section I'd like to make sure it actually works! :p

Elliott Wave
06-10-2008, 03:19 PM
Time for the next episode... :)

I REALLY wish that the strategy performance data could be integrated with the main chart and all of the relevant performance data displayed in a panel below the chart. But in the meantime I've started to use the output window for this task. It's helpful because (like the PnL plot) you can immediately gauge the impact of any changes you make to your strategy.

http://shup.com/Shup/45132/output.jpg

Here's the code. Just add it to the end of the OnBarUpdate section.

Print ("----Strategy Performance (all trades)----");
Print ("Net Profit: $ " + (int) Performance.AllTrades.TradesPerformance.Currency.C umProfit);
Print ("Profit Factor: " + Performance.AllTrades.TradesPerformance.ProfitFact or);
Print ("Sharpe Ratio: " + Performance.AllTrades.TradesPerformance.SharpeRati o);
Print ("Drawdown: $ " + (int)Performance.AllTrades.TradesPerformance.Curre ncy.DrawDown);
Print ("Gross Profit: $ " + (int)Performance.AllTrades.TradesPerformance.Gross Profit);
Print ("Gross Loss: $ " + (int)Performance.AllTrades.TradesPerformance.Gross Loss);
Print ("Profits Per Month: $ " + (int)Performance.AllTrades.TradesPerformance.Curre ncy.ProfitPerMonth);
Print ("Largest Winner: $ " + (int)Performance.AllTrades.TradesPerformance.Curre ncy.LargestWinner);
Print ("Largest Loser: $ " + (int)Performance.AllTrades.TradesPerformance.Curre ncy.LargestLoser);
Print ("Max consequetive losers: " + Performance.AllTrades.TradesPerformance.MaxConsecL oser);
Print ("Max consequetive winners: " + Performance.AllTrades.TradesPerformance.MaxConsecW inner);
Print ("Average Trade Duration: " + Performance.AllTrades.TradesPerformance.AvgTradeDu ration);
Print ("Max time to recover from drawdown: " + Performance.AllTrades.TradesPerformance.MaxTime2Re cover);

I've posted an example strategy in the file sharing section.

http://www.ninjatrader-support.com/vb/local_links.php?catid=2&sort=d

I hope its useful to somebody. Enjoy! :p

r2kTrader
02-27-2009, 07:12 AM
Elliot Wave,

Good stuff. Thank you for sharing.

Why don't we setup a custom class or set this up as a method that can simply be called into any strategy?

Also, I could use some help setting up a method that will prove the unrealized max drawdown. On a per trade basis and total trade basis. Profit Factor should also be based on unrealized max drawdown as well (in my opinion) for a more accurate view of the system's performance

Thanks again!

duck_CA
03-02-2009, 07:26 PM
very nice job.. great tool

J_o_s
11-16-2010, 10:46 AM
Great tool Elliot Wave, and thanks for sharing. :)

I just tried it on NinjaTrader 7.0, but I can’t seem to get it to work. It plots 3 panels below the price panel (instead of the one from the example screen), which are all blank. As far as I can tell, the passing of the value to StrategyPlot has some trouble, because the Print() output of the cumulative profit (i.e. the value that gets plotted) does work. Sadly enough I don’t get an error, so I don’t know what & where it went wrong.

Are other users have the same problem? Any tips or suggestions for solving it? :)

Regards,

MarkT
11-17-2010, 01:07 PM
I have had trouble with using this as well .. though I cant recall the exact problem I had. EW hasnt answered my email from at least a month ago. Also he doesnt appear to be active in the NT community at the current time.