Better results with equity control?

Equity control functionality in Quant Analyzer allows you to simulate and test various methods of using equity curve to control trading logic.

What does it mean exactly?
The strategy can look at its own performance in the past (its equity curve so far) and use it to determine how it should trade in the future.
The premise is simple – can we improve the strategy future returns by analysing its past equity?

As an input we need a strategy (results) so we can try to improve its performance. In this post we’ll use the Test_EURUSD_strategy sample strategy with the equity curve displayed below.

When improving strategy performance the default approach usually taken is to try add one or more market filters, improve strategy entries or exits, reduce number of losing trades and increase number of winning trades.

But another interesting option that is the focus of this article is managing the equity curve of the system. In other words, we examine the past strategy performance and use this information to determine if we should take the next trade or not.

Example of Equity Curve management – simple approach using moving average
The idea is simple – add 20 period moving average to the equity curve generated by the strategy. Then employ the rules:

  • If current equity curve is above its moving average and a new trade should be open then take the trade
  • If current equity curve is below its moving average, then don’t take the trade for real, only take a paper trade and update the strategy equity curve

Simulating equity control in Quant Analyzer

Quant Analyzer lets us easily simulate this in its Equity Control tab. Just choose the Equity Control type you want to use, set its parameters and click on Apply.
In our example we’ll use Moving Average with period 20.

After clicking on Apply we’ll get two curves – the original equity curve without any changes and the “Controlled” equity curve where we used these rules in trading.
You can also see the red control line – in our case 20 period moving average of original equity that decides if the trade is taken or not.

Special equity control chart
Please note that the equity curves on the chart are displayed in a special way – every point is a new trade and the equity level at that point is actual account balance at the trade open.
This enables us to control the trades using equity curve – we can decide if to take the trade according to the account balance when opening the trade – just like in reality.

If there are multiple trades opened at exactly the same time, they are all “grouped” to one trade point.

The red thick line on the very bottom of the chart clearly shows periods when the trades were not taken or changed by equity control.

By the look on the chart above we can immediately see that employing equity control this way doesn’t improve the strategy results, in fact it makes it worse. Let’s look at the details and zoom the chart to the first few months.

Both original and controlled equity lines are the same until the point 1. From that day the equities differ:

  • The original equity curve shows that the strategy continues trading and makes a further loss
  • The controlled strategy doesn’t take the next few trades because the current equity at the trade open is below its moving average (red line). So the strategy passes the trades and prevents us to go into deeper loss until the original equity climbs up above its moving average.

So on this zoomed sample we can see that equity control works – it prevented strategy from going into bigger drawdown by missing the trades when original equity curve was below its moving average.

So why is the overall result of controlled strategy worse than the original one?
Let’s look at another section of the chart starting at around March 2010:

Again, both original and controlled equity lines are roughly the same until the point 2.. From then on the “Controlled” strategy starts losing its performance compared to original strategy.

Why is that?
Our rules specify that the strategy doesn’t trade when its equity is below its moving average. This means it might skip some losing trades preventing further loss, but it can also skips some winning trades that helped original strategy to recover from previous losses.

In our case it misses very profitable trades 3., 4. and 5. because at the time when these trades should have been opened the original equity curve was below its moving average.
Controlled strategy will take the next trade only after the original equity climbs back above its moving average.

Conclusions of this example

Our equity control simulation shows that this kind of equity control doesn’t improve anything. In fact it almost always decreases the profit and also increase drawdown if not used right.

But what about if we’ll try something else?
Instead of missing a trade when equity is below average we can double its size. The rules will be simple again:

  • If current equity curve is above its moving average and a new trade should be open then take the trade with its original size
  • If current equity curve is below its moving average and a new trade should be open then open the trade with double size

In this case we are speculating that after few losses there should come a profitable trade and we’d use double size to get double profit from it.

Extending Quant Analyzer
To create new custom equity control function we’ll use extendability of the newest version of Quant Analyzer.
Quant Analyzer v3 now allows you to programm your own equity control function and test your own ideas. In this example we’ll use special equity control function that you can download below.

MovingAverageAddContracts.java

Simply download this file, place it into {Quant Analyzer}/extend/code/EquityControl folder and restart the program.

You should see the new option Moving Avg Add Contracts added in the equity control types selection. You can leave the parameters unchanged, the parameter Coef means the coefficient by which we’ll increase the trade size if equity is below its moving average. It uses formula:

new trade size = coefficient * original size;

By setting it to 2 we’ll double the trade size.
Click on Apply and we can check the simulation results.

We can see that this time the net profit of strategy increased significantly, but it also increased the drawdown a little.
We can take it as an example that there is a room to influence strategy performance significantly by managing the trades using its past equity chart.

Final thoughts

The approach and examples we tried in this article shows just one of the many possibilities of using equity control with your strategy.
Quant Analyzer comes with 2 other equity control functions and it allows you to create your own ones to test your own ideas.

What to watch for
There are some disadvantages of equity control that we should be aware of:

  • It is very difficult to implement in EA – it is easy to simulate this kind of control in Quant Analyzer, but it is another task to implement it in your EA. In fact I don’t know any EA that would use similar approach of managing trades using its equity.
  • It depends on the original strategy logic – it will not work the same on every strategy, it depends on things like Risk-Reward ratio (size of SL vs PT), the “look” and steepness of the equity curve, number of consecutive winning and losing trades, and so on.
  • It sometimes doesn’t work well in “chops” – when the equity goes sideways the controlled strategy might lose more than the normal one, because of its tendency of missing profitable trades because equity is below its average.

Overall, it is a technique worth considering, and Quant Analyzer allows you to simulate the potential results before you’ll start the task of implementing it in your strategy.

Subscribe
Notify of
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Hani Hamdan
11. 12. 2021 10:24 am

Theoretically it is clear, but how this will be executed? can this be done automatically so the strategy will stop trading once the curve crosses an indicator? and how we can do it?

tomas262
Admin
Reply to  Hani Hamdan
13. 12. 2021 5:45 pm

QuantAnalyzer cannot give you codes that manage the equity control trading for you. You have to manually implement equity control function directly into EA

Ed Cas
Reply to  tomas262
21. 1. 2023 7:23 pm

QuantAnalyzer is a great tool, been able to aply equity control curve to real trading is the next step. Please let me know your opinion on Equity control algorithms from trade-station:
https://community.tradestation.com/Discussions/Topic.aspx?Result=1&Topic_ID=119576&SearchTerm=equity+intraday&txtExactMatch=

It si the only algorithm that promises some success so far. The instructions to implement the process must be followed exactly.

Thank you for your input.

Ed Cas
Reply to  Hani Hamdan
21. 1. 2023 7:19 pm

Please see comment image

on tradestaton help forum.

I am experimenting with it at the moment and it appears to work so far.

Ed Cas
21. 1. 2023 7:18 pm

I followed a tread on TS support and found a way to use Equity control on strategies.
Download the Example and follow the directions to install to the T.
At least in the example the code to control the equity line is OK.
Please download , test and report.

https://community.tradestation.com/Discussions/Topic.aspx?Result=1&Topic_ID=119576&SearchTerm=equity%20intraday&txtExactMatch=

comment imagePosted – 04/16/2012 15:02:44comment image  comment image  comment image Equity Curve Trading Template and Example

https://community.tradestation.com/Discussions/DATA/20120418211655EC_BeforeAndAfter_EC Trading Applied.JPG

https://community.tradestation.com/Discussions/DATA/20120416145356goose Equity Curve Trading Architecture.JPG

PURPOSE OF THIS TEMPLATE AND EXAMPLE
The Equity Curve Template & Example posted here is a simple template and example of how equity curve
trading can be done at the tick level using the Global Dictionary, and using the architecture presented
by goose in Topic_ID=119190. The simple algorithm used is intended to be replaced by an algorithm that
applies to the characteristics of the equity curve being traded.

LIMITATIONS OF THIS TEMPLATE AND EXAMPLE
I have this GlobalDictionary solution with TimeStamps working and have used it extensively for EC trading
development. But it is slow and takes an experienced programmer to set it up, and to get the example
working, and to replace the template example strategy code with the user’s strategy code. This is not a
good solution for the general user. As mmillar points out, ELC/ADE is the much preferred solution.

STRATEGY SIMULATION IN FUNCTION, AS AN ALTERNATIVE (update 7/18/2012)
I’ve completed simulating a continuously running strategy that uses limit orders in a function that matches every historical trade of the strategy over a 10 year period. The function continuously runs and forms an EC curve and algorithm that can be used to turn the strategy on and off. To get all the historical function trades to match all the historical strategy trades was not an easy task, and many subtleties and gotchas had to be addressed. The following are a couple of pointers:

1) When a market order is issued, don’t change the CC (variable for current contracts) at the time the market order is issued. Instead, set a flag so that CC is changed on the next bar.
2) When a limit order is detected as filled, change CC at that time, don’t wait until next bar.
3) On several conditions code needs to be added to distinguish between the bar after a condition goes false so that no order is issued on that bar, but a fill can still be detected. This principle applies to conditions such as the trade time condition. There are two sets of trade time conditions for limit orders, one for placing trades, and one which is one bar longer for monitoring if trades are filled.

Now the strategy can call the function and turn itself on and off accordingly. An indicator can use that same function to plot relevant points and indicators.

DESCRIPTION
Equity Curve Trading Template and Example
Version 1.23 (May 8, 2012: Added 2 bar delay to receivers before the first dictionary access,
to allow time for GlobalDictionary to be created and populated before it is accessed.
Coded and tested by ruletrader7320
Date posted: April 16, 2012
Last Update: May 8, 2012
Credits:
   1) goose for Equity Curve Trading Architecture
   2) goose for resolving issue with first argument of GlobalDictionary creations per Topic_ID=120035
Reference thread: Topic_ID=119190
Purpose: template and example for Equity Curve Trading at the tick level, Architecture by goose

Components: The “Equity Curve Trading Template and Example” consists of the following three
strategy files placed in two charts. The _ecStratTemplate&Example strategy is placed
in each chart with a different input setting:

Chart 1:
_ecStratTemplate&Example, with AutoON input always set to false in this chart.
_ecMonitor-sender(IOG) For backtesting set backtestON to true.

Chart 2: (must be identical to first chart)
_ecStratTemplate&Example, with AutoON input always set to true in this chart.
_ecMonitor-receiver(IOG).

Two diagnostic strategies are included to assist in diagnosing problems.

INSTALLATION
1) Upgrade to TradeStation version 9.1 or lastest version if not already there.

2a) Import 5 strategeis: _ecStratTemplate&Example, _ecMonitor-sender(IOG), _ecMonitor-receiver(IOG),
and two diagnostics, from the following ELD:.
Attachment:DATA/20120508184752_EC_EQUITYCURVETRADING_TEMPLATEANDEXAMPLE_V1.23.ELD 40527 bytes

2b) If your strategy uses IntraBarOrderGeneration, then edit ecStratTemplate&Example and change
IntraBarOrderGeneration to true: [Intrabarordergeneration = true]

****** QUICK START TO GET EXAMPLE WORKING ******

3) Form a new workspace with two identical charts side by side, formatted as follows:
      symbol @ES
      60 minute bar interval
      Last Date: 04/12/2012
      5 months back
      Time Zone: exchange (CT)

      After setting up both charts, check the settings in each chart to make sure they were made correctly
      (better to find a problem now, then spend hours later tying to figure out why it doesn’t work later.)

4) Insert the following 2 strategies into the right chart, and set iputs as instructed:
      a) _ecMonitor-sender(IOG), and set input backtestON to true, and then set Status to Off (to save a little time).      
      b) _ecStratTemplate&Example, and set input AutoON to false.. and then set Status back On for the sender.

      NOTE 1: status should be On for both strategies, and your right chart should now show trades.

5) Insert the follwoing 2 strategies into the left chart, and set the inputs as instructed.
      a) _ecStratTemplate&Example, and set input AutoON to true. if not alread set.
      b) _ecMonitor-receiver(IOG), no input settings

      NOTE 2: Now your left chart should show trades (but should be missing some trades shown in the right chart).
      
6) Display the equity curves of the right and left charts. They should show less trades on the left chart
(but this will not match current curves at the top because of changes for IOG).
If this is not working,
      a) Turn off all the strategies in the two charts.
      b) Then turn on the strategies in the right chart, and review the chart for trades.
      c) After trades show in the right chart, turn on strategies in the left chart (receiver).
      d) The curves should be different, with less trades in left chart.
      NOTE: To repeat this, strategies in left chart must be run after strategies in right chart have
      completed and populated the GlobalDictionary. (See next section and steps under part d.)

****** BACKTESTING & LIVE TRADING ******

7) Settings for backtesting and live trading.
   For backtesting:
      a) Set the input backtestON to true in the_ecMonitor-sender(IOG) strategy.
      b) Set automation to off in the receiver chart (chart that contains _ecMonitor-receiver(IOG),
      and contains _ecStratTemplat&Example, and keep input AutoON set to true).
      c) Backtesting cannot be done on a chart receiving live data. Put an end date on the
      chart before the current date if connected to TradeStation.
      d) Steps to perform consecutive back tests with changes to strategy between backtests:
      – 1. On the left chart (receivers) turn off both strategies by setting their Status to OFF
      – 2. Make the desired changes to the strategy (ecStratTemplat&Example), and verify.
      – 3. The strategies in the right chart should be on and should now re-run, so monitor right chart.
      – 4. After the strategies in the right have completed running (and GlobalDictionary now populated),
      —-turn on the strategies in the left chart which will now run against the new GlobalDictionary values.
      – 5. After the strategies in the left chart have run and the performance analyzed, turn off the
      —-strategies in the left chart in preparation to the next cycle (so that these strategies in left
      —-chart will only run after strategies in right chart run). Now carefully repeat the steps.
   For live trading:
      a) Set the input backtestON to false in the_ecMonitor-sender(IOG) strategy.
      b) Set automation to on (Format Analysis … window) in the left receiver chart and keep AutoON set to true.

****** REPLACING EXAMPLE CODE WITH YOUR CODE ******

8) Once the example is working, you can either update the example strategies with you code, skipping
all but the last step d) of this section. Or you can form a new set of strategies identical to the example
strategies, and then update the new strategies with Designer Generated and initialization code, and
with your code according to the following steps:
   a) Form three new strategies and copy and past this example’s exact sender, receiver, and strategy code.
   b) For each strategy, set up the Designer Generated and initialization code as follows:
      1. With the editor window of the new strategy in focus, select “View/Toolbars/Properties”,
      or click on the “Properties Window” icon in the top tool bar. A Properties window should appear.
      2. Click in the “Events” icon (lightning bolt) in the properties window.
      3. Double click in the blank “Value” field to the right of “Initialized” and the following should
      populate that field: “AnalysisTechnique_Initialized …. This will form the Designer Generated Code
      and the initialization event code in the strategy.
      4. Notice the new code block near the top starting with “method void AnalysisTechnique_Initialized …”.
      We’re going to take that line and replace a line further down that may be identical or almost identical
      with that line, and then delete the new code block with the following steps:
      – Delete the old line further down the code that starts out the same way.
      – Copy the new line and past it where the old line has just been deleted.
      – Delete the new code block at the top, all we needed was that one new line.
   c) Now make sure the new set of strategies is working exactly the same way the example is working
   following steps 3 through 6, starting with forming two new charts. (Since you’ve already done
   this for the example, this won’t take long and will confirm your starting point and review making
   the correct backtestON and AutoON settings.)
   d) In the editor window for each strategy, search on REPLACE and replace or update the example
   template code with your own code and settings according to the instructions that follow REPLACE.
      NOTE: this step requires advanced programming skills.

****** PROBLEM RESOLUTION ******

9) DIAGNOSTICS and PROBLEM RESOLUTION: If problems are encountered, first always review the input
settings, the chart settings (should be identical), and repeat the following turn off and turn on sequence:
      – Turn off all the strategies in the two charts.
      – Then turn on the strategies in the right chart (sender), and review the chart for trades.
      – After trades show in the right chart, turn on strategies in the left chart (receiver).

   If the checks and turn on/off sequence doesn’t resolve the problem, perform the following diagnostic test:
      a) Insert _ecDiagnosticSender into the right chart. (already imported in step 2)
      b) Insert _ecDiagnosticReceiver into the left chart. (already imported in step 2)
      c) If no exceptions are thrown, then open the following file using the editor of your choice (ie Notebook):
      c:\ecDiagnosticChart.txt.
      That file should contain the following two lines (with different time stamps).
      1120412 2015 Chart_01 4/19/2012 12:07:54 PM
      1120412 2015 Chart_02 4/19/2012 12:07:57 PM

      d) If the diagnostic file did not throw an exception and the output file shows the correct two lines, then
      the diagnostic test passed and the application should work. Maybe it was installed incorrectly or a setting
      missed. So remove all the installed strategies and charts, then reboot the computer and restart TradeStation
      and carefully do a new installation on new charts.
      
      e) If the diagnostic failed, or a reboot and new installation does not resolve the problem, then request further
      assistance on the forums and PM the author for possible further assistance. Be sure to be very detailed about
      what the problem is, including the exact error message, which step failed, what the input settings are, what the
      chart settings are, what changes have been made to the code if any, etc..
///////////////////////////////////

I have also done it with SPY an it works – I have not used in real trading yet.

comment image

Please let me know your feedback.
So finaly equity control traiding could be possible to implement.

Continue reading