Calculating 'Perfect Profit' - NinjaTrader Programming | futures io social day trading

Calculating 'Perfect Profit'
 Updated: July 15th, 2010 (07:25 AM) Views / Replies: 5,681 / 6 Created: July 14th, 2010 (12:22 PM) by Jura Attachments: 0

 Welcome to futures io.

# Calculating 'Perfect Profit'

The Netherlands

Favorite Futures: ...

Posts: 774 since Apr 2010

Calculating 'Perfect Profit'

Hi there,

Recently I came across the term 'perfect profit' in Robert Pardo's book The Evaluation and Optimization of Trading Strategies. (Great book btw ). In it, he states:

Quoting
 Perfect profit is a theoretical measure of market potential. It is the total profit produced by buying at every valley and selling at every top that occurs during a historical period of market history. This is obviously impossible in practice, therefore the name perfect profit. Because of the method of calculation, perfect profit will constantly grow from the beginning of the historical test period to its end. (p. 204)

This sounds to me like a good way to provide a benchmark to which a trading strategy can be compared. However, the author doesn't provide the code for such a calculation.

I tried to create a NinjaTrader indicator with this, but I had great problems with 'every valley and every top'. I've used the Swing indicator, Zigzag, and the standard functions as MAX and Highs.

Could someone suggest me a way to create such an indicator? I think it will be quite valuable to give another perspective on the results of a backtest.

I think a strategy with 'perfect profit' isn't possible because the entry and exit prices can't be edited in NinjaTrader. (i.e. you can't sell with hindsight after the top, which offcourse is a nice 'protection' to coding errors).

In the same book the author discusses the use of the 'perfect profit' in correlation with the result of a backtest to get an idea how good the strategy is. Do you guys think such a think can be custom added to NinjaTrader? (such as the Optimizer on this forum)

In my research to create such a indicator I found the following (C++) code in Modeling Maximum Trading Profits with C++ from Valerie Salov:

Code
 ```#include "Prices.h" using namespace PPBOOK; namespace PPBOOK { inline double pardo_potential_profit (const Prices& prices) { double ppp = 0.0 for(size_t j = 1 ; j < prices.size(); j++) ppp += fabs(prices[j] - prices[j-1]); return ppp * prices.tickValue() / prices.tick(); } } // PPBOOK```
Perhaps this gives some better insight in how such an 'perfect profit' can be calculated.

On internet I found an old newletter ("Better optimization in TradeStation, part 2: Breakout Bulletin - June 2005 ) which creates a sort of perfect profit indicator (see the code in that article).

Any thoughts are very highly appreciated,

Regards,

 July 14th, 2010, 12:22 PM #2 (permalink) Quick Summary Quick Summary Post Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500

Posts: 47,612 since Jun 2009

I wrote an indicator that showed the MFE and MAE of each trade using another indicator as a base line. It was last year, but the basic principle was take something like SuperTrend and look for the above/below crossovers. Start counting the MAE and MFE from bar 1, and each new bar adjust it accordingly. When a new crossover occurs, draw a trendline from bar 1 to the last bar, and then drawtext to show the MAE and MFE.

The MAE and the MFE would be calculated by just recording the entry price from bar 1 and then look at the low of each bar (for MAE, on longs) and the high of each bar (for MFE, for longs). If the low or high (in ticks, away from entry price) for the new bar is higher than the previously stored value, store the new value.

It's not perfect but it was simple, a dozen or two lines of code, and it helped with a spreadsheet that I was doing at the time which was for me to record the MAE and MFE for each move based on a mechanical entry set of conditions, then I would compare what I actually got on the trade to the theoretical best.

Mike

 The following user says Thank You to Big Mike for this post:

The Netherlands

Favorite Futures: ...

Posts: 774 since Apr 2010

Fat Tails
 I have not read the book, so I only can suggest how to proceed: The perfect profit would assume a minimum target (to overcome transaction costs), which I would translate into a minimum deviation for the zigzag indicator. First step would be to apply that indicator to a chart. The system would then sell every top (deducting spread and slippage) and buy every bottom (adding spread and slippage). The problem is, that this can only be done with hindsight, so I would not know how to define a strategy, as the information required to sell the top or buy the bottom will only be available later. What you could do is just store the swing highs and lows in a dataseries and calculate the potential profits and display them abóve or below each swing (it is basically the vertical dimension of the swing). THan add those profits up and display them somewhere. You could also try to export the hypothetical profits to an excel file.

Thanks for your reply Fat Tails. I'll look into the ZigZag indicator again, it looks to be the best indicator for such an idea.
Your DataSeries idea is an interesting one, thanks! (sound also complex ). Will look into it when the idea that I'm now using (with MAX and MIN values over an period) doesn't work out.

Big Mike
 I wrote an indicator that showed the MFE and MAE of each trade using another indicator as a base line. It was last year, but the basic principle was take something like SuperTrend and look for the above/below crossovers. Start counting the MAE and MFE from bar 1, and each new bar adjust it accordingly. When a new crossover occurs, draw a trendline from bar 1 to the last bar, and then drawtext to show the MAE and MFE. The MAE and the MFE would be calculated by just recording the entry price from bar 1 and then look at the low of each bar (for MAE, on longs) and the high of each bar (for MFE, for longs). If the low or high (in ticks, away from entry price) for the new bar is higher than the previously stored value, store the new value. It's not perfect but it was simple, a dozen or two lines of code, and it helped with a spreadsheet that I was doing at the time which was for me to record the MAE and MFE for each move based on a mechanical entry set of conditions, then I would compare what I actually got on the trade to the theoretical best. Mike

Great idea Mike, perhaps that can be quite a good substitute for 'perfect profit'. Such an indicator can even be used in realtime to watch the performance of a strategy (how great would that be!). However, my programming skills are not even close to your skills. Can you give some suggestions or tips?

Thanks for your posts Fat Tails and Mike, it gave me some fresh insight into this problem.

Regards,

Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500

Posts: 47,612 since Jun 2009

Sorry, but I am no longer doing any NT programming. I'm sure you can hire it done or if you make a case you might get another person to do it free, specifically posting in the want your indicator created for free thread.

Mike

The Netherlands

Favorite Futures: ...

Posts: 774 since Apr 2010

Big Mike
 Sorry, but I am no longer doing any NT programming. I'm sure you can hire it done or if you make a case you might get another person to do it free, specifically posting in the want your indicator created for free thread. Mike

That's okay Mike, thanks nonetheless.

 futures io > Calculating 'Perfect Profit'

Upcoming Webinars and Events (4:30PM ET unless noted)

Right now

Right now

September

## The Spirituality of Trading w/Dr Brett Steenbarger

Elite only

 Similar Threads Thread Thread Starter Forum Replies Last Post bluemele Psychology and Money Management 53 July 27th, 2014 04:24 PM kbit News and Current Events 1 June 13th, 2011 01:45 PM Saroj NinjaTrader Programming 2 April 6th, 2011 09:44 AM h4cked Reviews of Brokers and Data Feeds 8 December 11th, 2010 02:54 PM nanobiotech NinjaTrader Programming 3 April 6th, 2010 12:35 PM