Share It!

# Trade Recorder Function And Strategy

When developing, testing, or simply tracking an existing trading system it can be helpful to have each individual trade exported to an Excel file. Such data can be useful in analyzing the system performance. For example, the data can be used to calculate the trading system’s Expectancy and Expectancy Score. Or, the data could be used within a Monte Carlo simulation to give you a better idea of how the system may behave when different position sizing models are applied. In this article I’m going to demonstrate two EasyLanguage programs that can be used to export your trade history to an Excel file.

The first program is a TradeStation function called Trade Recorder Function. This was originally released in the fall of 2011 but has now been updated. The second program is a new strategy called Trade Recorder Strategy which will allow you to record the progress of a trading system even if you don’t have access to the strategy code.

What kind of information is tracked within the Excel document? There are several important pieces of information recorded, but one in particular can be very useful when computing the Expectancy and Expectancy Score. Below is an example of the file generated along with a description of each column.

Click On Image To Expand
• Date and Time Open – The date and time when the trade was opened.
• Date and Time Closed – The date and time when the trade was closed.
• P&L – The profit or loss of the trade. Commissions and slippage are removed if you provided such information within the strategy properties.
• Risk – Your initial stop value in dollars.
• Volat – Volatility of the market in dollars when the trade was opened.
• MAE – Maximum adverse excursion. This is the amount of heat your position took while open.
• MFE – Maximum favorable excursion. This is how much money was left on the table after the position was closed.
• BARS – Number of bars your position was open.
• P&L (R) – Your P&L measured in units of risk (R).
Most of the information recorded are straight forward. However, the P&L (R) column may not be familiar for some people. The concept of measuring your profit in units of risk was popularized by Van Tharp in his book, Trade Your Way To Financial Freedom. A unit of risk is defined by your initial stop value which is called your Risk (R). Once a trade is closed we can express your P&L in units of risk by dividing the P&L value by R

P&L (R) = P&L / R

For example, let’s say your trading system has a fixed stop loss of \$300. This value represents your R. Let’s also say your trade closes out with a profit of \$500. This produces a P&L expressed in risk units of…

P&L (R) = \$500 / \$300
P&L (R) = 5/3

P&L (R) = 1.66

This means your P&L was \$1.66 for every \$1.00 you risked. Put it another way, your profit was 1.66 times what you risked. Why would you care to express your P&L in this form? Good question.

The first TradeStation file is a strategy file called Trade Recorder Strategy. This is a strategy which can be loaded into a chart which contains the strategy you wish to track. In essence, you are running two strategies at the same time (in parallel). However, Trade Recorder Strategy does not generate buy and sell signals. It only monitors the trades generated by the other strategy you are testing.
Note, one of the input parameters you will need to enter is the initial stop loss value of the system you are tracking. If you are planning on using this Trade Recorder Strategy on an existing trading system, you will have to know what the stop loss value is. This might not be possible if the trading system uses a variable or dynamic stop loss. If you do not know the initial stop loss value you can do two things:

1) Use the trading system’s average loss. Simply review the system’s performance report and find the average loss value and use this number as the initial stop loss value. By doing this however, you are now estimating your expectancy and not computing the true expectancy. But your value will be a good estimate and that’s  better than nothing.

2) If you have access to the code you can use the Trade Recorder Function (described below). Using the function provides you with a lot more flexibility including the ability to plug-in the exact stop loss value even if it varies on each trade. This will allow you to calculate the true expectancy of your system.

The second option is obviously a better idea for system developers who have access to the trading system code. However, if you don’t have access to the code you will have to use the first option.

### Trade Recorder Strategy Video Tutorial

This video explains the Trade Recorder Strategy and demonstrates how to use it.

The Trade Recorder Function allows you the most flexibility as stated above. It’s a function that can be added to any trading system. Simply place the function at the end of your strategy code and populate the input parameters within the required fields.

Here is an example of using Trade Recorder Function in your own code:

RetVal = TradeRecorder( WriteToFileFlag, FileName, SystemName, SystemVersionNumber, StopLoss\$, ATR );

WriteToFileFlag is a switch that allows you to enable or disable the TradeRecorder function. Set to true and all trades are recorded to the Excel file. Set to false and none of the trades are sent to a file.
FileName is the filename and location of where to put the generated Excel file.
SystemName is the name of the system you are recording.
SystemVersionNumber is the version of the system you are recording.
StopLoss\$ is the total dollar amount you are risking on a single trade.
ATR is the volatility measured at time of opening the position. I would like to use an Average True Range.

Here is an example of a Trade Recorder Function being called.

RetVal = TradeRecorder( true, “C:\breakout_test”, “Open Range Breakout”, “1.0”, myStop * numContracts, myATR );

The return value is meaningless. All TradeStation functions must return something. In this case, Trade Recorder Function always returns a zero. Once you have generated your results you can simply open the file with Excel or Open Office.

### Trade Recorder Function Video Tutorial

This video explains the Trade Recorder Function and demonstrates how to use it.

### Conclusion

With these two tools system developers can better understand their trading systems. All the files in this article are available below as free downloads. If you found an error in any of the files or have an idea to improve them, please leave your comments below.