April 12


Trade Recorder Function And Strategy

By Jeff Swanson

April 12, 2021

automated trading, Automated Trading Development, EasyLanguage, Jeff Swanson, trade recorder, Video

When developing, testing, or simply tracking an existing trading system it can be helpful to have each individual trade exported to a text file. Such data can be useful in analyzing the system performance in Excel. 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

Another common use for exporting your trades to a text file is importing your trades into a third party application. For example, you may want to import them into a Monte Carlo program or an application like Build Alpha to analyze and attempt to improve the performance. Often these third party tool want you to import your trades in a specific format. Well, if you know EasyLanguage you can do just that!

What Will We Track?.

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.

Trade Recorder Results

  • 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. 

After many trades you can plot a scatter graph of your P&L (R) values. This is somewhat helpful. A healthy scatter graph of P&L (R) values should have very few if any plots beyond negative one and should have a good number of plots well above positive one. But perhaps a more interesting number is the average of your P&L (R) values which is your Expectancy. If you will recall, within a previous article I showed you how to estimate expectancy. However, by using this method of calculation we are actually computing the true expectancy of our trading system. This is easy with the use of Trade Recorder because once you have your trades listed, you simply take the average of the P&L (R) and you have your Expectancy. Simple! From the Expectancy number you can then compute the Expectancy Score. If you’re not familiar with either Expectancy or Expectancy Score please review this article.

Trade Recorder Function

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 for 2021

The Trade Recorder Function allows you the most flexibility. 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 similar program.

EasyLanguage Trade Recorder Strategy

The second EasyLanguage program is a 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.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. 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.


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

Jeff Swanson

About the author

Jeff has built and traded automated trading systems for the futures markets since 2008. He is the creator of the online courses System Development Master Class and Alpha Compass. Jeff is also the founder of EasyLanguage Mastery - a website and mission to empower the EasyLanguage trader with the proper knowledge and tools to become a profitable trader.

  • Will the trading recorder strategy record manual trades or only strategy trades? I am looking for an alternative to TS TradeManager Analysis since it often has many errors related to run-up and draw-down.

      • looks like it does not work. some of the reserved words and functions seem to be specific to strategies. I wonder if it is possible to modify it for live trades.

          • I know it wont record manual trades but as a followup question, will it record live strategy trade data? For example the strategy order and the actual trade fill are often different due to slippage. which order values does the recorder function capture, strategy or the actual live trades? Thank you

  • the value of the MAE and the MFE are exported incorrectly in some trades.
    If we compare the columns (drawdown and runup) of the tradestation report with the values present in the respective columns of the report .csv generated by the function, you will notice that in some cases the values are different.
    anything know how to fix?
    thank you

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Learn To Code & Build Strategies
    Using EasyLanguage.