Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Testimonials
  • Contact

Can my broker steal my expert advisor?

October 17, 2013 by Shaun Overton 4 Comments

I get this question often enough that it’s time to put this out on the internet. There are plenty of reasons for traders to remain wary or suspicious of their broker. If you’re using the broker’s software, can they steal the expert advisors in your account that are making money?

Steal MT4 expert advisor

Can the broker steal your EA for MT4 or MT5?

The answer is an emphatic no. I started my career working as a broker and have been involved with forex for 7 years this month. I’ve seen the backend systems and tools that the MT4 brokers use to manage clients and their positions. I’ve also seen them on the floor of one of the MetaTrader bridge companies.

The brokers use a piece of software called the MetaTrader Manager. The manager is basically a database that tracks the open positions and equity for clients. It does not have a button for sucking MT4 expert advisors from client accounts.

Filed Under: MetaTrader Tips Tagged With: broker, expert advisor, metatrader, MetaTrader Manager, mt4

Automated Trading Part II

January 7, 2013 by Shaun Overton 1 Comment

The second part in Nathan’s interview series with me focuses on the role of high frequency trading in the markets and testing trading strategies. If you missed the first automated trading interview in the series, you can read it here.

Nathan Orange(Nathan):
Do you have any specific thoughts or opinions on HFT (High Frequency Trading)? This is such a hot topic among traders and I would imagine you have a unique insight into algo trading in general.

Do you see machines eventually replacing the “human” trader or could HFT eventually get banned from the markets? At least for day traders it seems to give quite an unfair advantage to the HFT camp for executions?

Shaun Overton(Shaun):
There is a huge difference between algorithmic trading and HFT. HFT is obviously automated due to the speeds involved, but that does not imply that all automated trading is HFT. It’s only a subgroup.

 

Nathan Orange(Nathan):
Sure, there are plenty of automated systems that are not HFT. I bring it up under the context that HFT uses deceptive algorithms for their order posting tactics.

 

 

Shaun Overton(Shaun):
HFT is uniformly destructive to capital markets and their purpose. It nickels and dimes investors and traders through market manipulation. Just last week Nanex detected a single organization that pushed through 4% of all the order flow on US equities quotes. Even worse, not a single one of the orders executed. Posting orders without the intent to trade is blatantly illegal.

The other negative consequence of HFT comes from the rebates that the dark pools and exchanges pay to “liquidity providers,” which are really the HFT bots. The arrangement tangibly alters the motivation for participating in markets. Rather than investing or even speculating on price, the HFT algos generally do not care about market movements. They just want the liquidity rebate.

Nathan Orange(Nathan):
This to me is the bigger issue. The whole arrangement is shady and as you said it alters the motivation for market participation. What steps or changes do you recommend?

 

 

Shaun Overton(Shaun):
The Market Ticker blog is one of my favorites on that subject. Karl Denninger advocates a regulatory rule of a two second minimum order time. I support the idea. Nobody can plausibly claim that an order placed for such a short duration is for any trading purpose. If an order is not intended to be filled, it should be not permitted.

 

Nathan Orange(Nathan):
I cannot argue with that logic. Back to testing, how important is accounting for commissions and slippage to the integrity of any back-testing data in your opinion? To me, as you go down the scale from longer term trading to day-trading the importance grows exponentially.

 

Shaun Overton(Shaun):
I fully agree. The consequences of trading costs pile up with increased frequency. Shorter time frames multiply the frequency, which as you pointed out, grows exponentially.

My personal preference is to skip trading costs and commissions on short time frames so that I can obtain a sufficient sample size for my analysis. I do not foresee myself ever trading on one minute charts, but I almost always use one minute tests to analyze randomness within a strategy. Unlike most systems developers, the profitability of a system is a backseat concern.

I read a newsletter this morning written by a multi-million dollar businessman. He concluded today’s article saying that if you start a business to make a lot of money, you’ll more than likely fail. You have to excel at providing a quality product and service in order to succeed over the long run. When the inherent business excels, only then does the long term money follow.

Trading is a business in precisely the same sense. Most traders rush through the system development process to spit out quick profits. They rarely, if ever, consider a strategy’s performance over a lengthy period of time. Everything is about the here and now. Additionally, good systems frequently lose money. You need something more in the toolkit besides the random scorecard of profit and loss.

Nathan Orange(Nathan):
Good systems do have losing periods, yet many traders seem to be convinced there is a “holy grail” approach out there that will buck this fact. If some of the most successful traders ever have posted losing periods (or even years) and have been around for 20+ years it seems hard to fathom beating their performance from day 1.

Regarding testing platforms, you were one of the first people that really explored the issues with back-testing Forex – can you provide more detail on the problems for those that are interested in developing and back-testing a system for FX (MetaTrader platform)?

Shaun Overton(Shaun):
You’re opening a can of worms on this one. MetaTrader is hands down the worst platform available for backtesting. The data is notoriously unreliable. Even when good data is at hand, the instructions for importing it and turning it into something usable fill a dozen pages of instructions.

You’re much better off doing real analysis in NinjaTrader, TradeStation or MultiCharts. The metrics are vastly superior and require a tiny fraction of the effort. I still think that MetaTrader is sufficient for live trading most strategies.

Nathan Orange(Nathan):
I am a huge fan of live testing/trading alternate strategies. One of my biggest “A Ha” moments came during live testing alternate exit strategies. I traded my account with my original exit approach but also demo traded alternate exit strategies in real time. There is value gained that you don’t always get from a back-testing print out. How do you compensate for slippage when testing a strategy?

 

Shaun Overton(Shaun):
Forex is thankfully unique in that it doesn’t come with unique problems other than rollover. The markets are the most liquid in the world. As a retail forex trader looking at charts longer than five minutes, you can generally assume that the historical prices are reasonably reflective of executable prices for the strategy.

I compensate for slippage and bad ticks by doubling my expected transaction costs. For example, I pay 1.5 pip spread on the EURUSD. When I test a strategy, I demand that it must hold up on 3 pips transaction cost on every trade.

Nathan Orange(Nathan):
Before we wrap this up, are there any specific strategies or common parameters that you have noticed in systems that make it? We both know how small of a percentage of traders become successful, but as it relates to mechanical systems are there recurring themes for those that are profitable?

 

Shaun Overton(Shaun):

No, there are no recurring themes that I see. The lowest common denominator is that they do not overtrade and that they use low leverage. Other than those two items, each successful strategy differs substantially from all the others.

The most important ingredient in system development is the developer. I have yet to program a successful trading system for someone without years of full time trading experience under their belt. You have to go through the school of hard knocks if you’re going to make it. Almost all of us are too stubborn to listen to good advice.

Nathan Orange(Nathan):
Shaun, I can’t thank you enough for providing such honest responses and sharing your insight. If you are interested in learning more or considering coding your system, go to MetaTrader Programming for more information.

Filed Under: MetaTrader Tips, NinjaTrader Tips, Trading strategy ideas Tagged With: algorithm, backtest, HFT, high frequency trading, metatrader, mt4, Nathan Orange, ninjatrader, trading

EA Problem Checklist

January 3, 2013 by Shaun Overton Leave a Comment

It drives me crazy when I call tech support and the customer service person asks, “Is your computer plugged in?” When I step back and think about it, however, they ask dumb questions for a reason. Some people really do forget to check the obvious things.

If you’re stuck trying to load a MetaTrader expert advisor and you cannot get it to trade, this checklist will help you resolve the most obvious problems.

You should see the name of your expert advisor and a smiley face in the top right corner of your open chart. The image below contains a blue line. Everything is correctly displaying above that blue line.

MT4 EA

Expert Advisor Problem Checklist

Do you see the name of your expert advisor on the chart? If yes:

  • If an X appears, then click the big EA button at the center top of the screen. It should appear pressed down
  • If an upside down smile (a frown appears), then right click on the chart. Choose Properties. Click the Common tab. Select “Allow live trading” and “Allow DLL Imports”. Remove the check next to “Confirm DLL Function calls”
  • Click the Inputs tab. Change the inputs to whatever values you desire. Push OK.
  • If a smiley face appears, you’re all done.

Do you see the name of your expert advisor on the chart? If not:
Drag and drop the EA onto the chart.

  1. Click the Common tab. Select “Allow live trading” and “Allow DLL Imports”. Remove the check next to “Confirm DLL Function calls”
  2. Click the Inputs tab. Change the inputs to whatever values you desire. Push OK.

 

MT4 EA Button unpressed

The X appears on the chart because the Expert Advisors button is not pushed down

EA frown

The frown on the chart indicates that “Allow Live Trading” is not enabled.

The EA button correctly pressed

The smiley face appears on the chart after the Expert Advisors button is pushed down.

Filed Under: MetaTrader Tips Tagged With: EA, expert advisor, metatrader, mt4

Custom Indicator MetaTrader

December 27, 2012 by Shaun Overton 1 Comment

If a trader dreams up some information that he’d like to see on the chart, a custom indicator is more than likely the way to go. Custom indicators support the display of

  • Dashboards
  • Buy and sell arrows
  • Any type of line

Custom indicators require programming. That is, after all, the item which makes them custom.

The custom indicator box in MT4

The advantage to developing a custom indicator is that it offers maximum control over the process. The designer controls the inputs, which are the items that the user can change.

Moving averages, for example, offer common inputs such as the type (EMA vs SMA) and the period (a 55 period moving average). If you anticipate changing your mind later, it’s easy to facilitate that from the beginning.

Most traders care most about how the indicator looks on the chart. Whether you tend to focus on colors or prefer arrows over lines, the great thing about the custom process is that you can build the tool to match your tastes.

Some traders prefer the dark black background in MetaTrader. Others prefer lighter colors, which are easier on the eyes. It’s completely up to you, the designer, to dictate how the indicator should display the information.

Do you have a custom indicator that you’d like to create? Email us at info@onestepremoved.com with a description of what you’d like to build.

Filed Under: MetaTrader Tips Tagged With: chart, custom indicator, metatrader, mt4

MetaStock First Impression

December 21, 2012 by Shaun Overton 2 Comments

It’s not that developing for MetaStock is hard, it’s just different.  I am used to working with MetaTrader and more recently NinjaTrader.  MetaStock offers all of the great features one would look for in a trading platform. Navigating around is a bit difficult, though. The biggest obstacle for me is how differently MetaStock handles tasks when compared to other platforms

Of course I recognize comparing anything to MetaTrader isn’t fair in some respects.  MetaTrader is a much simpler platform to be sure.  MetaStock is significantly more robust in its features and abilities. Where MetaTrader instantly opens charts for you right after installation, MetaStock opens to a kind of passive mode. The platform does not display anything until the user requests it.

When I develop for MT4, I only have to locate and copy an EA for delivery to our customers.  That’s not the case with MetaStock.  Thankfully MetaStock, like NinjaTrader, has an import/export tool to help.  In MetaStock you simply run the Organizer and the wizard will guide you through all of the details of creating an export for backup or delivery to another user.

Each of the major trading platforms has its own set of unique features and each has its own quirks.  As noted earlier MetaTrader feels like it’s quicker and easier to get started.  The learning curve is short.  However, in comparison to NinjaTrader and MetaStock, MT4’s feature set is limited.  The best analogy that I can think of is a bike doesn’t take as much skill and practice as driving a car on the highway.

My biggest beef with MetaStock at this point would be the language used for the indicators and EAs.  Compared to MQL and C#, the language feels limited and somewhat clunky. It requires DLL programming much more often than other platforms.

Filed Under: Uncategorized Tagged With: MetaStock, metatrader, mt4, ninjatrader, organizer

Expert Advisor Assumptions

November 20, 2012 by Shaun Overton 3 Comments

Many of our clients are ordering their first custom programming projects. They know the general framework of the expert advisor that they hope to create, but they are not sure of what to ask for specifically. The goal of this post is to outline how an EA functions in relation to the most commonly asked questions.

How do I select the currency pair and time frame that my expert advisor should use for trading?

An Expert Advisor runs on the chart where the user applies it. When you wish to trade an EA on the EURUSD M15 chart, open a EURUSD chart. Change the time frame to M15. Apply the EA. All decisions will be based on the chart.

What are inputs?

Inputs are variables that the user can change without additional programming. Traders often know the indicators that they like using. The settings are often less clear. Inputs allow for tweaking or experimenting without needing to email the programmer every time that you change your mind. A more concrete example is to consider an EA that uses a moving average. Is a 50 period MA better than a 55 period MA? Making the period an input allows the trader to experiment quickly and easily.

How does my EA choose how many lots it should trade?

I assume that you wish to trade fixed lot sizes unless you tell me otherwise. Most of our SOWs include a Lots input. Any trading signals that appear would enter with the amount that you enter for Lots. Clients frequently request other types of money management. You need to explicitly state the type of money management that you wish to include or else it will not be in the expert advisor.

Why does every SOW include a stop and take profit?

Mostly because it does no harm being in there. Setting them to zero will disable each of their functionalities. The vast majority of clients want the ability to select stops and limits. Our programming templates automatically include them to help speed up the development process and to reduce costs for our clients.

What is the difference between a generic trailing stop and a breakeven trailing stop?

A generic trailing stop is what most people think of when the word trailing stop appears. It maintains a set distance from the most favorable price seen. A breakeven trailing stop is more complicated. It was covered in a previous blog post.

What is the purpose of an SOW? Why are you so insistent on pinning down all of the details?

All of our projects are pre-paid. Before we required SOWs for all projects, the expectations between OSR and the client often differed. The customer expected one thing; we expected another. It’s worth taking the extra time to make sure that everyone understands the project and what is expected.

The SOW also allows us to develop a working relationship before any money changes hands. You feel more comfortable with the purchase when you already know that we understand the project from top to bottom.

I want to trade 10 currency pairs at a time. Why can’t a single EA manage all 10 currency pairs?

A single expert advisor technically could manage multiple time frames and multiple currencies. I recognize that the idea is nice; why manage 10 EAs when you could only manage 1 EA? The problem is that MT4 EAs depend on incoming ticks to update. If the expert advisor wants to trade the AUDUSD but it’s applied on the EURUSD, the trade won’t fire off until the EURUSD receives an incoming quote. That’s not good, especially with short time frames. There’s the risk of trades firing off later than expected, trailing stops taking too long to update, etc. More importantly, the execution will always bottleneck because of the trade context is busy error.

I welcome questions on these blog posts. If you’ve always wondered how EAs work and would like your question answered on the blog, then send me an email.

Filed Under: MetaTrader Tips, MQL (for nerds), Trading strategy ideas Tagged With: EA, expert advisor, metatrader, mt4, programming

Triangular Arbitrage

November 8, 2012 by Shaun Overton 23 Comments

Triangular arbitrage is a bit of forex jargon that sounds cool. It represents the idea of buying something and selling it near instantaneously at a profit. Instant, free money appeals to nearly everyone. The theory is sound, but it’s extremely difficult to pull off in real life.

If you are unfamiliar with synthetic currency pairs, I highly recommend that you read my post on the subject from December 2011. None of this explanation will make sense without understanding that the synthetic pair concept.

Triangular Arbitrage

Triangular arbitrage opportunities occur when a currency pair shows a price, while the same synthetic currency pair shows another price. If the asking price for the EURUSD is 1.2820 and the bid price of the synthetic currency pair is 1.2823, a triangular arbitrage opportunity exists.

The synthetic currency pair can involve any medium of exchange. Yen pairs are extremely liquid, so perhaps a may use USDJPY and EURJPY to build the synthetic EURUSD.

The great thing about the triangular arbitrage trade is that there are multiple opportunities using the same instrument. Although the named pair does not change, which in this case is EURUSD, a trader could use any of the other 6 major currencies to shop for the best price on the trade. I listed the examples below using the assumption that we’re buying EURUSD.

Arbitrage currencyAction for arbitraging long EURUSD
JPYSell EURJPY, Buy USDJPY
GBPSell EURGBP, Sell GBPUSD
AUDSell EURAUD, Sell AUDUSD
NZDSell EURNZD, Sell NZDUSD
CADSell EURCAD, Buy USDCAD
CHFSell EURCHF, Buy USDCHF

Example

Assume that the trader spots an arbitrage opportunity in EURUSD and finds that yen crosses offer the best opportunity. The mechanical implementation of the strategy would follow this approximate process:

  1. Buy 100,000 EURUSD at market
  2. Confirm execution of the EURUSD order at or near the requested price.
    • If the order receives poor execution that is worse than the synthetic currency pair or will make the trade too expensive, then close the trade and look for a new opportunity. The cost is the spread and whatever commission was paid.
    • If the order receives reasonable execution, continue.
  3. Choose half of the synthetic leg to fulfill. The order does not matter. If it the EURJPY is the first order to use, then the task is very easy. The EURUSD and EURJPY pairs both use the same base currency. The lot sizes on the trades should be identical. Because we bought the EURUSD in the named currency pair, we will need to sell the EURJPY to hedge out the euro component of the trade. The EURJPY sell for 100,000 should be executed at market.
  4. The remaining leg of the trade is the USDJPY. Buying EURUSD put us short dollars. In order to hedge the dollars, we need to buy dollars. Thus, we must buy USDJPY. We cannot, however, blindly purchase $100,000. Although we bought €100,000, that trade put us short $128,200. The unit size should be a purchase of $128,000 against the yen. The extra $200 is rounded to off due to position sizing restrictions in the forex market. We are forced to accpept the risk on the $200 position
  5. The entire trade has now executed. The exit will occur when the opportunity reverses itself so that the bid is now below the ask, as you would expect in a market. Exit all open trades at market.

Correcting Lot Sizes

It’s hard to grasp the concept of triangular arbitrage from a single example. At the risk of boring my readers, I present a second example below for the sake of thoroughness. The need to correct for lot sizes is what I expect will trip up most traders. Skip this section if you feel like I’m beating a dead horse.

Let’s use the NZDJPY as an off the wall example. The pairs involved are as follows:
NZDJPY, trading at 66.32
NZDUSD, trading at 0.8281
USDJPY, trading at 80.07

The named NZDJPY price is 66.32. The synthetic price, however, is 66.305. An arbitrage opportunity of 1.5 pips exists. This is calculated by:

1 NZD/USD 0.8281 * 1 USD/JPY 80.07 = 1 NZD/66.305 JPY
66.32 – 66.305 = 1.5 pips

The named currency shows a bid price above the ask. This means that we need to sell the named currency and buy the synthetic currency. Assuming that we deal in standard lots on the base currency, the trader executes an order to sell NZD $100,000 at market.

The first task is to buy back the kiwi dollars using NZDUSD. No conversion among units is necessary. Both the named and synthetic currencies share the same base currency, NZD. The last and final step is to sell the JPY that was purchased in the NZDJPY short transaction. Selling JPY using USDJPY involves buying USDJPY. Remember the warning about unit sizes.

We need to purchase NZD $100,000 worth of yen in US dollars. As you can see, it’s complicated. Converting the dollar base currency into NZD is:

NZD $100,000 * USD $0.8281/NZD $1 = $82,810

We need to buy $82,810 worth of USDJPY. The forex market restricts transactions to 1,000 unit increments. The least risk involves purchasing $83,000 USDJPY and accepting $190 in exposure.

Why triangular arbitrage is so common

Almost all retail forex brokers mark up their spreads in lieu of charging direct commissions. The purpose is to camouflage the true cost of trading. Like most gimmicks, however, it creates an unintended consequence. The artificial mark ups in the spread are the reason for many of the triangular arbitrage opportunities.

The broker must decide which side of the spread receives the markup. Occasionally, the entire markup is subtracted from the bid or added to the ask. More often than not, brokers hedge their bets by adding portions of the markup on both sides of the bid and ask.

The markups are invariably higher on the crosses. The extreme differences between the bid and ask make trading those crosses directly undesirable. It’s something of a paradox, but that undesirable trait becomes a positive one in the context of triangular arbitrage. The bid is lower than its real rate. The ask is higher than its real rate. When the majors trade on reasonable spreads, it’s common for the markup to create near permanent arbitrage opportunities on the crosses.

The trade only achieves a realize-able profit whenever the markup begins skewing in the opposite direction. If a broker applies most of the markup on the ask, the triangular arbitrage would not profit until the broker shifted the markup mostly or entirely to the bid. The flip flops typically take several hours to occur, which limits the number of daily opportunities.

Brokerages almost always view arbitrage traders as toxic order flow. Arbitrage only occurs when someone is asleep at the wheel; the profits ultimately come out of somebody’s pocket. Even in the instance where brokerages offer an ECN or pass through execution, they care far more about their relationships with the banks than any individual customer. Brokerages are essentially wholesalers for the trading arms of banks. If the banks cut them off, then they have nothing to sell. Triangular arbitrage in this situation earns its money from the banks. If a trader makes too much money too fast, the trader will get the axe at the bank’s request.

Traders on the FXCM dealing desk or other brokers face no chance of an ongoing relationship. The profits come directly from the broker’s pockets. If they’ve been in business for very long, they will know what you’re up to relatively quickly.

Splitting trades across multiple brokers is the best opportunity for the strategy to succeed. Breaking up the orders creates more opportunities. More importantly, no single entity knows your combined order flow. It makes it much more difficult for the sore loser to track down who is bleeding him dry.

Forex Platforms

MetaTrader

Running triangular arbitrage expert advisors in MetaTrader involves a clunky workaround. The same risks that apply to broker arbitrage also apply to triangular arbitrage. The trade context is busy problem stands out as a primary concern. It might realistically take 3-5 seconds to execute all three orders if done within a single expert advisor. Many bad things can happen in such a large time window. Also, I would expect the broker to catch on quickly to this scheme and shut it down.

The only practical solution is to use three separate instances of MetaTrader running a shared memory DLL. One instance would be dedicated to the “bad” broker marking up its spreads. The other two instances would execute each single side of the synthetic trade with a “good” broker. Executions would obtain the ability to enter simultaneously without queuing. The disadvantage is that the EA would only update on incoming ticks. If a long interval occurs between ticks, it delays one corner of the triangle from entering.

NinjaTrader

NinjaTrader can ideally execute the orders if done within a single brokerage. Again, this makes your tracks pitifully simple to trace. You could build a great strategy with sound engineering that only works in the real world for a few days. You’re then stuck going broker shopping once again.

The best way to trade undetected is to use NinjaTrader with a multi-broker license. Apply one strategy on the bad broker, then apply the second strategy on the good broker. The strategies would also need a way to communicate, perhaps through a shared memory resources or an intranet client-server.

I am interested in building well engineered solutions as products for sale on this web site. If trading something like this interests you, please email me and mention the platform that you prefer. I’m keeping a list to help us prioritize what traders want.

Filed Under: How does the forex market work?, MetaTrader Tips, NinjaTrader Tips, Trading strategy ideas Tagged With: arbitrage, expert advisor, forex, mt4, spread, synthetic currency, triangular arbitrage

MetaTrader Set File

October 8, 2012 by Shaun Overton 2 Comments

Set files in MetaTrader provide traders with an easy way to share the settings used in an expert advisor with a friend. Or in our case, it allows you to share settings with the programming team.

We frequently ask for set files in the course of MQL Debugging. One of the most common sources of frustration for our clients is when we send an EA and they think it doesn’t work for some reason. The most common cause is that the client inputs settings that cause the EA to never find trades.

It seems obvious enough for users to self-report the settings used. Unfortunately, many people overlook settings or sometimes enter them incorrectly without realizing it. Using set files and log files allows us to analyze what occurred for certain instead of what the user believes to have happened.

Creating a set file is very simple.

  1. Place your EA on a chart or open the strategy tester.
  2. You will next see the inputs tab (i.e., EA settings) on the screen. Change the settings to what you intend to use.
  3. On the right side, you will see two buttons. Click on Save. I recommend that you save the file to an easy location such as the desktop.
  4. Reply to your support ticket email with the set file attached.

 

Filed Under: MetaTrader Tips Tagged With: metatrader, mt4, set

Convert to MetaTrader 5

April 17, 2012 by Shaun Overton 2 Comments

Alpari’s recent launch of MetaTrader 5 triggered a small wave of MQL5 translation requests. Most traders assume that MT5 is about to take over the world. Perhaps it’s better to front run any potential problems. I assure you, though, that there’s no need to panic.

The launch mainly signifies that the larger forex firms will start rolling out their own installations of MT5 within the next six to twelve months. Rumor has it that Alpari’s owners are very close to the owners of MetaQuotes. Perhaps this is hearsay, but it’s my impression that Alpari is the first among equals when it comes to MetaQuotes’ clientele. Alpari did pay up the wazoo, however, for their license. Maybe they’re just getting rewarded for adopting the new platform so quickly.

Most brokerages, especially the large ones, are not chomping at the bit to adopt the new release. In fact, most of them hate MetaTrader with a passion. The back office is written largely for brokerages that exclusively want to use MetaTrader. The larger brokers, all of whom invariably offer their own proprietary platforms, have to jump through a lot of hoops to get all the moving parts between separate back office systems working in sync. The rollout will likely embroil their IT staff in problems for months on end. I seriously doubt most CEOs are looking forward to the switch.

Also, offering MT5 as the primary platform does not mean that your brokerage is going to flip the off switch on MT4. They depend on MetaTrader 4 for their cash flow. Brokerages will not sabotage themselves by preventing all of their customers from trading.

Rollouts of new technologies usually occur over a period of 9 months or more. When I worked with FXCM, I remember the handful of clients that refused to switch from Trading Station I to II. It wasn’t until 2 years after the initial release of the new version where the company decided to drag the stragglers kicking and screaming onto version II.

The switch from MetaTrader 3 to 4 worked in much the same way at the brokerages offering it at the time. It wasn’t until two years or so after its initial adoption that version 3 went by the wayside.

You have little to worry about as a retail trader considering the switch over to MT5. If you want to program a brand new EA and your broker already supports MetaTrader 5, then you should definitely program it in MQL5. Otherwise, stick with MetaTrader 4. It still has years of shelf life.

Filed Under: MetaTrader Tips Tagged With: Alpari, brokerage, EA, FXCM, metatrader, MQL5, MT3, mt4, MT5, translate

Optimize an Expert Advisor

February 20, 2012 by Shaun Overton 1 Comment

One of the lesser known features of the MetaTrader backtester is the optimization feature. It’s so small that you could be forgiven for overlooking it.

Optimization is the process to maximize a certain outcome. In this case, it’s profit. Any EA developer wants to maximize the amount of profit made over a given period of time. The MetaTrader optimizer allows the trader to search for the combination of inputs that yielded the maximum profit over a given period of time.

The process is identical to running a backtest, except that MT4 runs multiple backtests at the same time. It then organizes the results and offers up the best combination.

Telling the backtester to run in optimization mode is easy. Simply put a check next to the word Optimization. MetaTrader will then sort through the combinations that you tell it to consider.

MetaTrader EA Optimization option

Place a check in the box next to Optimization in the MT4 backtester

The next step is to click on the Expert properties button to the right. A new window appears that contains three tabs: Testing, Inputs and Optimization. These screens allow the trader to inform MetaTrader which variables to consider for testing and how to weight the results.

Testing

The top of the testing section applies to every type of backtest. Here you can select the starting balance. MetaTrader defaults the option to $10,000, although you can make this any amount of your choosing.

The second default option allows the trader to restrict the direction of trades. It’s a frequent expert advisor programming request. It’s also one that is unnecessary. Both the backtester and expert advisor options screen allow the trader the option of restricting trades to long only or short only without additional programming. If the EA is not well programmed, this setting may cause errors 4110 or 4100 to appear all over the trading journal. It’s harmless. The only effect should be that the backtester slows down. It’s the result of writing to the journal hundreds of times or more.

The testing tab of the MetaTrader backtester

The testing tab of the MetaTrader backtester

A groupbox appears underneath these options that inexplicably relates to the optimization process. You’d think it would make more sense to place it in its namesake tab. That’s typical MetaQuotes logic at work.

The first line contains numerous parameters for choosing the best option. User overwhelmingly select for the largest account balance, but other options include the profit factor, expected payoff, maximum drawdown and drawdown percent.

The last line automatically uses a genetic algorithm. Optimization processes use either brute force methods or genetic algorithms. Brute force strikes most people as intuitive although obviously exhausting. The software tests every combination possible. Genetic algorithm’s attempt to make the process more intelligent. When the software sees that certain parameters almost inevitably lead to a losing performance, the algorithm skips similar tests where it expects to lose.

This is a great idea if you have a quality genetic algorithm. My opinion of the MetaTrader backtester is less than stellar. I don’t feel very confident about the algorithm at all. If you don’t mind spending extra time waiting for test results then I suggest unchecking this option. You don’t want to miss a potentially important combination.

Inputs

Most people find this screen confusing. The first column, called value, strictly controls inputs for simple backtests. The Value column is totally ignored during an optimization run.

The inputs tab of the MT4 backtester expert settings

The inputs tab of the MT4 backtester expert settings

The important columns for this task are Start, Step and Stop. Start is the lowest number that the MT4 backtester will consider. Step refers to the interval between the lowest value and the highest value. Tightly controlling this setting allows the user to gain quick insights into how changing the variable values affects performance without dragging the tests out for a full week. Stop is the highest number that the expert advisor will use.

The most obvious candidate for testing in this example is the Take Profit value. The default setting is listed at 50. If you trade the majors, you might want to consider settings ranging between 10 pips and 200 pips. That means that you set Take Profit row to 10 for the Start column and 200 for the Stop column. The real trick here is selecting the Step. If you choose Step = 1, then MetaTrader will run a separate test for every value between 10 and 200. That’s 190 tests, which is overkill. A step of 10 cuts the total number of tests down to 19.

Optimization

This section is the nit-picky part. If a trader feels it’s unacceptable to have 10 consecutive losses in a row, he can place a check next the the Consecutive wins box. MT4 automatically discards any tests which yield a result that contains anything checked off.

The optimization tab in the MT4 backtester expert properties

The optimization tab in the MT4 backtester allows users to discard tests with undesirable traits.

When you finish going through each of the tabs, push OK in the bottom right corner. It’s time to launch the tests.

Curve fitting in the MT4 Optimizer

A word of warning: my personal opinion is that optimizing an expert advisor is usually a very bad idea. The unique settings that yield the most profit in 2012 are unlikely to yield the most profit in 2013. If you don’t control for random chance, there’s a good probability that the 2012 best combination may result in catastrophic losses in 2013.

I recommend that traders pursue any strategy development work in NinjaTrader. I don’t like the idea of optimizing at all. Instead, I always focus on testing strategies for entry and exit efficiency. I know from years of experience that these values never fundamentally change on instruments of the charts traded. Entry and exit efficiencies make wonderful metrics for automated trading because they are so stable.

Filed Under: MetaTrader Tips, Test your concepts historically, Trading strategy ideas Tagged With: backtest, backtester, brute force, curve fitting, drawdown, EA, expert advisor, genetic algorithm, inputs, MetaQuotes, metatrader, mt4, optimization, optimizer, profit factor, Take Profit, testing

  • 1
  • 2
  • Next Page »
FREE trading strategies by email

Trending

Sorry. No data so far.

Archives

  • Dominari
  • How does the forex market work?
  • Indicators
  • MetaTrader Tips
  • MQL (for nerds)
  • NinjaTrader Tips
  • Pilum
  • QB Pro
  • Stop losing money
  • Test your concepts historically
  • Trading strategy ideas
  • Uncategorized
  • What's happening in the current markets?

Translation


Free Trading Strategies

Privacy PolicyRisk Disclosure

Copyright © 2023 OneStepRemoved.com, Inc. All Rights Reserved.