• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:55pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:55pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

Alternative Trade Management/Money Management Methods 1 reply

Money Management / Risk Management 24 replies

Making a good diversified portfolio 10 replies

Money Management Code? 4 replies

Need help in money management code 1 reply

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
Tags: Diversified EA Money Management Code
Cancel

Diversified EA Money Management Code

  • Post #1
  • Quote
  • First Post: Edited 5:56am Mar 7, 2010 1:13am | Edited 5:56am
  •  PipMasterMik
  • | Joined Nov 2009 | Status: Member | 44 Posts
Hello All,

I currently have a bunch of EAs that operate based on a range of trading strategies (i.e. breakouts, ranging, trend, counter-trend etc) with a range of currencies and I'm trying to work out a way to code a money management function to manage risk between all of these EAs. I'd like to work out an algorithm (I'm happy to code it and share it) for how best to manage risk in this scenario, and I'd like to call on the good people of forex factory to offer their suggestions as to the best way to do this. I know that someone smarter than I has done this before...

As an example, if I have 20% of my account at risk due to 10 breakout trades (different strategies and currencies with a 2% account balance risk on each trade) there may be a substantial risk if the market starts ranging. Hence, in this case I want to reduce the maximum risk exposure due to the breakout EAs (or preferably not get into this situation by using risk management to use smaller lot sizes).

However, if a counter trend EA wants to trade when I'm already heavily invested with breakout orders, I don't want to limit the counter trend EA's lot sizes.

I'd also like to consider spreading the risk across different currencies (i.e. do not have too many order lots on any one currency).

Additionally, it would be nice to make the system try to balance the "EA investment portfolio" to try to maintain a definable level of risk in the market during normal trading times. As an example, trying to maintain 20% of account equity invested during the trading week. This could be tricky as each EA has its own entry/exit criteria and trading frequency, but some kind of approximation method could work quite well.

When I'm finished on this project I'd like to have a library function that is called from any EA and that returns the trade lot size. This library function will store all the risk and money management criteria that will be applied to all EAs. I imagine that I may have to pass some info to this function, such as the type of EA strategy (trending, ranging etc) and the currency that is to be traded.

Has anyone attempted to write something like this before? If so, I'd very much appreciate your feedback and suggestions.

Thanks,

Michael
  • Post #2
  • Quote
  • Mar 7, 2010 8:41am Mar 7, 2010 8:41am
  •  CodeMeister
  • Joined Sep 2009 | Status: Making Code While Making Pips | 1,672 Posts
There are certain things a human should do and other things that a machine can do better. You should leave judgment and subleties in the hands of the humans and never give control of these situations to the machine as you are proposing. If you want to have the machine help you perhaps a dashboard display could help a trader. The trader needs to make the ultimate decision with all factors taken into consideration which something that a machine does poorly.
 
 
  • Post #3
  • Quote
  • Edited 9:07am Mar 7, 2010 8:45am | Edited 9:07am
  •  tdion
  • Joined Nov 2005 | Status: EURUSD Quant FREAK | 3,197 Posts
Disagree, CodeMeister...

If you can have your robot do EXACTLY what you would do in any given situation, a mechanical solution is appropriate.

Just my take.
 
 
  • Post #4
  • Quote
  • Mar 7, 2010 8:53am Mar 7, 2010 8:53am
  •  tdion
  • Joined Nov 2005 | Status: EURUSD Quant FREAK | 3,197 Posts
Well, I have two strategies trading simultaneously myself. I coded both of them into the same EA, so it was simply a matter of defining the logic to manage them with.

I can't really help you with how to manage the trades. For me, I don't do much pyramiding at all. I find it too dangerous. (a few reversals and a pyramid can eat your lunch)

With all that said, the only thing I can offer is to look at all the worst case scenarios that can happen, and write your logic down on paper first. Then code it.

Suppose you have 50K and you want to divide the risk between 3 different EAs. You can use the formula: "double riskCapital = AccountBalance()-33,333" to set your lot size with. All your EAs are trading out of the same account, but you are protecting the other 2 EAs initial capital by hiding it from the other 2 EAs.

Hope this helps.
 
 
  • Post #5
  • Quote
  • Mar 7, 2010 4:51pm Mar 7, 2010 4:51pm
  •  PipMasterMik
  • | Joined Nov 2009 | Status: Member | 44 Posts
Quoting CodeMeister
Disliked
There are certain things a human should do and other things that a machine can do better. You should leave judgment and subleties in the hands of the humans and never give control of these situations to the machine as you are proposing. If you want to have the machine help you perhaps a dashboard display could help a trader. The trader needs to make the ultimate decision with all factors taken into consideration which something that a machine does poorly.
Ignored
Hi CodeMeister,

Thanks for your comment. With a lot of EAs running it is difficult to manage them manually. Hedge funds trading the stock market use similar systems for balancing their portfolios; some funds attempt to cancel out all effects associated with an overall upward or downward movement of the stock market. To balance such a portfolio requires some basic math and becomes a bit trickier when there are many investments (in our case EAs) to think about; you can do it manually but why suffer when a computer can do the calculations for you? I'm trying to do a similar thing here with currencies and trading strategies. The parameters that define the trading lot sizes for each strategy will of course be human controlled.

I think that your dashboard idea is excellent; can you suggest the most useful way of laying this out? What information would you put onto it?

Cheers,

Michael
 
 
  • Post #6
  • Quote
  • Mar 7, 2010 6:04pm Mar 7, 2010 6:04pm
  •  PipMasterMik
  • | Joined Nov 2009 | Status: Member | 44 Posts
Quoting tdion
Disliked
Well, I have two strategies trading simultaneously myself. I coded both of them into the same EA, so it was simply a matter of defining the logic to manage them with.

I can't really help you with how to manage the trades. For me, I don't do much pyramiding at all. I find it too dangerous. (a few reversals and a pyramid can eat your lunch)

With all that said, the only thing I can offer is to look at all the worst case scenarios that can happen, and write your logic down on paper first. Then code it.

Suppose you have 50K and you want to divide...
Ignored
Thanks Tdion for your input.

I don't do any pyramiding either; different strategies have different entry points, hence two strategies may both have an opening position on the same currency in the same direction. None of my individual strategies add on to already open positions.

I've thought about your idea of evenly allocating the account balance between strategies (and currencies). The issue with this is that longer-timeframe strategies and strategies that don't trade very often will be reserved account equity when they don't need them, and the total amount invested at any one time will be quite small. Hence, I suspect that maybe the trading frequency and time in the market for each EA will need to be considered (perhaps by reviewing previous trade history, and upping the overall lot sizes to meet the investment targets?).

Cheers,

Michael
 
 
  • Post #7
  • Quote
  • Mar 7, 2010 8:41pm Mar 7, 2010 8:41pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Quoting PipMasterMik
Disliked
Hello All,

I currently have a bunch of EAs that operate based on a range of trading strategies (i.e. breakouts, ranging, trend, counter-trend etc) with a range of currencies and I'm trying to work out a way to code a money management function to manage risk between all of these EAs. I'd like to work out an algorithm (I'm happy to code it and share it) for how best to manage risk in this scenario, and I'd like to call on the good people of forex factory to offer their suggestions as to the best way to do this. I know that someone smarter than I...
Ignored

General rule of thumb, how much of your account do you stand to lose if the market does action X (action Y?)

There are times when I have 100% of my account in a trade, but rarely are those trades set in such a way that they are correleated with each other.

As for coming up with MM rules, in my trading I already sized each EA's lots so that if every EA were to be in the market at the same time, they would all hedge each other.
 
 
  • Post #8
  • Quote
  • Mar 7, 2010 9:54pm Mar 7, 2010 9:54pm
  •  PipMasterMik
  • | Joined Nov 2009 | Status: Member | 44 Posts
Quoting Ronald Raygun
Disliked
General rule of thumb, how much of your account do you stand to lose if the market does action X (action Y?)

There are times when I have 100% of my account in a trade, but rarely are those trades set in such a way that they are correleated with each other.

As for coming up with MM rules, in my trading I already sized each EA's lots so that if every EA were to be in the market at the same time, they would all hedge each other.
Ignored
Hi Ronald,

Thanks for visiting the thread. I completely agree with the general rule of thumb you mentioned. I might pursue this as the key to how risk is measured, but have some thinking to do as to the best method of implementation.

You mentioned that if all EAs are in the market at the same time they would all hedge each other. Am I correct in assuming that for each strategy you have an equal and opposite counter-strategy? As an example, if the ranging market conditions are met you place a short, but if the trending conditions are met you place a long. Hence, if both strategies were triggered, both with equal lot sizes, you would be perfectly hedged. Is this the kind of thing you are talking about?

In the case of my EAs, I don't have an equal balance between trend and counter-trend styles of trading. Some EAs tend to have higher trading frequencies then others. Hence, I've found sometimes I'm too far invested in a particular market direction that can cause large drawdown when things move the wrong way.

Do you rely on the fact that you have enough EAs with different strategies and currencies that the chance of them all being correlated to a single market event is slim to none?

Thanks again for your input, I'm going to give these ideas some more thought.

Cheers,

Michael
 
 
  • Post #9
  • Quote
  • Mar 8, 2010 6:56am Mar 8, 2010 6:56am
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Quoting PipMasterMik
Disliked
Hi Ronald,


You mentioned that if all EAs are in the market at the same time they would all hedge each other. Am I correct in assuming that for each strategy you have an equal and opposite counter-strategy? As an example, if the ranging market conditions are met you place a short, but if the trending conditions are met you place a long. Hence, if both strategies were triggered, both with equal lot sizes, you would be perfectly hedged. Is this the kind of thing you are talking about?
Ignored
That's very simplistic, but yes. That applies to a two dimensional model, and assumes you only have two trading systems. I have 34 EAs running across 6 trading styles. So, let's say I have 10 trending EAs, 6 ranging EAs, and 4 breakout EAs. Three dimensions in this case, and 20 EAs across all three.

My trending EAs all enter a trend at a different time (stronger trend means more EAs enter). I size the risk of those EAs so that when the trend is quite strong--say 6 trending EAs enter the market--trending EAs will have higher risk compared with all the ranging EAs.

Assume the opposite: My ranging EAs are sized in such a way that if the market is ranging and the trending and breakout EAs keep throwing off false signals, the ranging EAs' profits cover the losses from the other two trading styles. In this instance, the 6 ranging EAs enter the market based on how strong a ranging period is.

Then there's the breakout market: Breakout EAs don't really have that perfect synergy between trending or ranging. They're somewhat a transition between either, in order for a range to become a trend there needs to be a change in direction, and that usually comes in the form of a breakout. The same principles apply: breakout EAs enter the market based on the stregth of the anticipated breakout. They're either early in the breakout or late in the breakout

When you put it all together, we look at a standard market cycle...

 

  1. Ranging

    1. Most ranging EAs would be placing trades here. Some of the trigger happy breakout and trending EAs would be placing trades around this time.

  2. Transition

    1. Ranging EAs would still be placing trades here, however, more and more trending and breakout EAs would be placing trades here as well.

  3. Trending Up

    1. Ranging EAs are almost completely not placing trades here while trending and breakout EAs are raking in money.

  4. Transition

    1. Ranging EAs are again placing more trades and some are beginning to win those trades. Trending EAs are either exiting their positions or will be getting out very soon

  5. Ranging

    1. Ranging EAs are beginning to become more dominant while the trigger happy breakout and trending EAs are beginning to place trades again

  6. Trending Down

    1. As the trend increases, more and more trending EAs are beginning to enter and some of the breakout EAs are beginning to become successful.

  7. Go back to 1

      1. The cycle repeats

I should note that the length of a cycle varies significantly. There are times when a trending/ranging/transition period is so brief that a system designed for that stage in the cycle cannot stand a chance at making money.

Overall, this really is a complexified game of rock-paper-scissors


Quoting PipMasterMik
Disliked
In the case of my EAs, I don't have an equal balance between trend and counter-trend styles of trading. Some EAs tend to have higher trading frequencies then others. Hence, I've found sometimes I'm too far invested in a particular market direction that can cause large drawdown when things move the wrong way.

Do you rely on the fact that you have enough EAs with different strategies and currencies that the chance of them all being correlated to a single market event is slim to none?
Ignored
You don't need an absolutely equal balance between the number of trading systems. Only the risk needs to be relatively equal. Adding more trading systems, allows a more finite adjustment of you overall risk.

I never rely on the fact that I'm spread out across several strategies. Black swans do come every so often, and thus, I am always monitoring my EAs, taking some off the market, putting others on, etc. My EAs are perfectly capable of all running together independently. They'll average a 10-20% return month to month. When I am added to the mix, my account's return can jump into thousand percent returns and higher. It's only capped by the margin restrictions my broker has at different leverage levels. Because I'm able to identify patterns in the market where my cookie-cutter like aspect of my EAs can't fit.

There are 1.17566389 X 10^52 possible permutations of my EAs thus far. That's still not enough to cover every possible market activity. That's why I need to step in from time to time.

Thing about developing a trading system... most developers try to build a system which works in every market, for every pattern, and every situation. I disagree. I design systems to find one specific pattern, to exploit every variation of that one pattern possible and that one pattern only. I can always make another system to take advantage of another pattern.

You seem to be on the right track, pursue that. And while you're at it, learn to make money on a coin toss, that skill helps significantly when you need to intervene.
 
 
  • Post #10
  • Quote
  • Mar 8, 2010 8:35pm Mar 8, 2010 8:35pm
  •  PipMasterMik
  • | Joined Nov 2009 | Status: Member | 44 Posts
Hi Ronald,

Thanks again for your ideas. Your macro description of the market cycle and the EA portfolio is a good one; this has given me quite a few ideas as to how I can better manage risk between different types of EAs, and perhaps also how I can develop new EAs that come into the market cycle at different stages (i.e. early trend, mid trend, late trend... etc).

I'm in perfect agreement regarding having EAs that just trade one strategy each; that's also how I've structured my EAs. Otherwise I have found it is way too time consuming to test them and monitor their performance over time.

I've tried to code my EAs so that they only enter when market conditions are favourable, and when there are false signals the losses are as small as possible.

If you are running all those EAs on multiple currency pairs there would be a lot of EAs to manage simultaneously (lets say 6 currencies x 34 EAs = 204 EAs). That is a lot of EA management decisions per day! Any tips on how you maange this?

I would be ecstatic if my EAs could return 20% per month every month... my hat goes off to you for being able to achieve much more than this.

In regard to the coin toss test, do you do this using an EA or is it manual trading? Do you use a martingale-type strategy to achieve your results? It is interesting what you say about exits being more important, I'll have a think about this and maybe code a random entry EA with some tricky trade management.

Cheers,

Michael
 
 
  • Post #11
  • Quote
  • Last Post: Mar 8, 2010 9:01pm Mar 8, 2010 9:01pm
  •  Ronald Raygun
  • Joined Jul 2007 | Status: 32 y/o Investor/Trader/Programmer | 5,016 Posts
Quoting PipMasterMik
Disliked

If you are running all those EAs on multiple currency pairs there would be a lot of EAs to manage simultaneously (lets say 6 currencies x 34 EAs = 204 EAs). That is a lot of EA management decisions per day! Any tips on how you maange this?
Ignored
They're grouped.

Quoting PipMasterMik
Disliked
I would be ecstatic if my EAs could return 20% per month every month... my hat goes off to you for being able to achieve much more than this.

In regard to the coin toss test, do you do this using an EA or is it manual trading? Do you use a martingale-type strategy to achieve your results? It is interesting what you say about exits being more important, I'll have a think about this and maybe code a random entry EA with some tricky trade management.
Ignored
I have yet to develop an EA which is profitable on a coin toss, so for now, I'm doing this manually.

1) Toss a coin: Heads long, Tails short
2) Manage the trade as you see fit. If you think the trade is bad, exit.
3) When you exit a trade, go back to step 1.

If you can double your account in less than 50 flips, I consider you a good enough trader to go live. I personally average between 20 and 30 flips, and I do it once a week, on the weekends, trading simulated data.

Simulator: (http://www.forexfactory.com/attachme...02008%208:18pm)


You're welcome to try martingale. You'll realize soon enough why it doesn't work.
 
 
  • Platform Tech
  • /
  • Diversified EA Money Management Code
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2023