Performance Report: # of Contracts Traded?  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Performance Report: # of Contracts Traded?

Postby furytrader » 17 Feb 2012

Is there some place in the standard performance report to see how many contracts were traded historically? I am testing a system that gets in with 3 contracts, exits 2 contracts at a target price and holds on to 1 contract, with a trailing stop. I can see how many trades there were, but each "trade" may consist of 1, 2 or 3 contracts. Besides counting the individual number of contracts, what's the best way to tell how many contracts were traded?

User avatar
Henry MultiСharts
Posts: 8520
Joined: 25 Aug 2011
Has thanked: 1213 times
Been thanked: 2741 times

Re: Performance Report: # of Contracts Traded?

Postby Henry MultiСharts » 17 Feb 2012

Hello Furytrader,

You can find the contracts amount in:
Performance Report-> Trade analysis->List of trades->Contracts column.

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Performance Report: # of Contracts Traded?

Postby furytrader » 17 Feb 2012

But that doesn't aggregate them. It just says that for some trades, I did 3 contracts, with other trades I did 2 contracts, etc. Is there a way to get a complete tally of the total # of contracts traded?

User avatar
JoshM
Posts: 2089
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1525 times
Been thanked: 1485 times
Contact:

Re: Performance Report: # of Contracts Traded?

Postby JoshM » 18 Feb 2012

furytrader wrote:Besides counting the individual number of contracts, what's the best way to tell how many contracts were traded?

furytrader wrote:Is there a way to get a complete tally of the total # of contracts traded?

Yes, there's a custom way in which you can get the total number of contracts traded. PosTradeCount() and PosTradeSize() are in this regard the keywords that you'll need for this.

However, since there isn't a keyword for the number of positions, you'll need to manually count these (which gives extra code). Then, on the last bar, you'll need to loop through all positions.

You'll need two loops for this: one for the number of positions (which you manually tracked), and one the number of entries in that position (which is given by PosTradeCount). Then you can use the PosTradeSize (which gives the size of each entry order for that specified position) to calculate the number of contracts traded.

Perhaps you already know this, but just to be complete, if you enter a trade with 4 contracts (so one entry order), and then have two separate exit orders each for 2 contracts, according to the PosTradeCount keyword, you have had two entries. (somewhat counter-intuitive :), but I suppose it's needed for order matching). Anyway, also see this wiki article for a better example of that.

If I understand you correctly FuryTrader, the code example should get you started. It performs the actions that I described above:

Code: Select all

[IntrabarOrderGeneration = True]

Variables:
   x(0), y(0), 
   IntrabarPersist NumberOfPositions(0),         // Positions <> TotalTrades
   IntrabarPersist MPPosSize(0),
   IntrabarPersist PrevMPPosSize(0),
   numOfContracts(0);

// Get current position
MPPosSize       = CurrentContracts * MarketPosition(0);

// Look for a recently closed position
if ( (PrevMPPosSize < 0) and (MPPosSize > 0) ) or          // Previous position was short, now long
   ( (PrevMPPosSize > 0) and (MPPosSize < 0) ) or          // Previous position was long, now short
   ( (PrevMPPosSize <> 0) and (MPPosSize = 0) ) then begin   // Previous position was not flat, now flat

   NumberOfPositions = NumberOfPositions + 1;

end;

// Start counting the number of contracts
if (BarStatus(1) = 2) and (LastBarOnChart_s = True) and (GetAppInfo(aiOptimizing) <> 1) then begin

   Print("*************************");
   Print("Total trades executed by ", GetStrategyName, ": ", NumToStr(TotalTrades, 0));
   Print("Total number of positions: ", NumToStr(NumberOfPositions, 0));
   
   numOfContracts = 0;
   
   // Loop through positions
   for x = 0 to NumberOfPositions begin
   
      // Loop through trades of the position
      for y = 0 to PosTradeCount(x) - 1 begin
      
         numOfContracts = numOfContracts + PosTradeSize(x, y);

      end; //: Trades loop
      
   end; //: Position loop

   Print("Total number of contracts traded: ", NumToStr(numOfContracts, 0));
   Print("*************************");
end;

// Store current position size for comparisons
PrevMPPosSize = MPPosSize;


This gives here the following output:

Code: Select all

*************************
Total trades executed by TestStrategy6: 4389
Total number of positions: 1463
Total number of contracts traded: 4392
*************************

(The difference of 3 contracts is due to there being a open position with 3 contracts open at the end of the backtest).
These users thanked the author JoshM for the post (total 2):
furytraderMydesign

User avatar
furytrader
Posts: 353
Joined: 30 Jul 2010
Location: Chicago, IL
Has thanked: 154 times
Been thanked: 215 times

Re: Performance Report: # of Contracts Traded?  [SOLVED]

Postby furytrader » 18 Feb 2012

This is great - thank you very much for taking the time to do this. However, it sounds like this would be something relatively easy to add to the performance report. I am going to add a request in the project manager and see if they add it - thanks again Josh!
These users thanked the author furytrader for the post:
JoshM


Return to “MultiCharts”