Algorithmic and Mechanical Forex Strategies | OneStepRemoved

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

What makes a successful trader?

February 24, 2015 by Eddie Flower 7 Comments

The percentage of successful forex traders is relatively small, yet they share certain similarities: A well-built trading system, plus the right combination of personality traits and learned behaviors.

Of course, the tools are important – Regardless of a trader’s personal characteristics, a successful trader always builds, uses or finds a good Expert Advisor (EA). Most people believe that if they just find the one magic bullet, then everything will be fall into place. As Shaun discusses in the forex robot secrets report, that’s almost never the case.

Characteristics of successful traders

Traders and EA developers who succeed are usually found at one of the two extremes of intelligence: Either they’re highly intelligent, or they’re extremely dim witted. There doesn’t seem to be much middle ground in which “average” developers succeed.

On the one hand, it seems easily explainable that sharp developers should be more successful than “average” ones. Yet, those at the other intellectual extreme are often also more successful than the typical developer.

Why?

One theory to explain the trading success stories of traders and EA developers who are outside-the-ordinary is illustrated by this anecdotal experiment: If a mouse is placed into a cage where cheese is found on a particular side of the cage 60% of the time, and 40% of the time on the opposite side, every mouse will eventually learn to choose the side of the cage where cheese is found 60% of the time.

mouse and cheese

In other words, mice are at least intelligent enough to stop guessing and simply choose the pathway which is more often successful. In contrast, humans generally try to improve their success by finding and improving on some sort of pattern in randomness, even when it’s not there.

This theory may explain why less-intelligent traders can be successful by sticking to a system based on simple rules that win more often than they lose. Of course, “home-run” systems that are over-optimized in an attempt to “win everything every time” usually fail.

From the perspective of the mice described in the above experiment, it’s not about getting all the cheese every time, it’s about getting enough cheese more often than not.

A trading success story is based on more than just brain power

An automated trading success story may begin with brainpower, but it doesn’t end there. Brainiacs tend to build trading systems based on deep technical analysis. Theories are developed and modified as testing reveals strengths and weaknesses in a given system.

If a mouse is placed into a cage where cheese is found on a particular side of the cage 60% of the time, and 40% of the time on the opposite side, every mouse will eventually learn to choose the side of the cage where cheese is found 60% of the time.

But, there are plenty of intelligent, well-educated traders, and many of them don’t thrive when they’re involved in day-to-day trading. Significantly, winning traders’ ideas tend to become simpler over time instead of more complex.

An EA can be too powerful

Being too smart is a handicap that can keep traders from winning, and the power of EAs can also work against them. EA-focused traders tend to drift off course instead of remaining focused on the simple pathway toward trading success.

Without consistency, it’s difficult make any progress, nor measure results effectively. Too many indicators and too many pathways to explore may tempt EA traders to go astray, and wander away from the simple, basic rules that win.

Trading is a process, not a destination

When the trader approaches system design as a process rather than as a fixed destination, the outlook becomes much better. Success is relative, and improvement is ultimately more important than perfection.

For example, when a trader focuses on a system’s accuracy, the trade-off usually comes in the form of accepting a less-profitable exit point from a given trade. So, a trader’s urge to win a slightly-higher percentage of trades often erodes the system’s performance.

In contrast, process-oriented system designs let traders assess how making slight changes in the trade-entry protocol affect the system’s efficiency. And, using expert money-management methods can help by reducing the emphasis on entry and exit protocols.

Emotion in trading can’t be denied, yet it can be channeled appropriately

Emotion is impossible to separate from trading. But, it shouldn’t be the reason for trying to develop a winning Expert Advisor.

Instead, rational reasons for building an EA include situations in which a trader has been trading a given system long-term and wants to automate a proven winner, or finding ways to automate one’s trading based on narrowly-targeted indicators that win more often than not, even without generating perfect signals.

The question isn’t how to to remove emotion – Instead, the question is how to channel it appropriately, especially when the trader or EA developer has made a huge investment in time spent developing a system.

The goal is to develop and implement a consistent system – not a perfect system. When traders swing back and forth between winning and losing, the lack of consistency makes them feel less confident in their systems.

When a trader is “married” to a supposedly perfect system, there isn’t likely to be any trading success story in his or her future.

Work with professional EA developers

Designing a winning trading system takes hundreds of hours of time, plus at least a decade of experience. As mentioned earlier, system development is a process instead of an endpoint. Still, there’s a way to expedite the process – work with a professional developer like OneStepRemoved.

Where are you in your trading journey? Share your ideas below for you how “find more cheese” in the markets.

Filed Under: Trading strategy ideas Tagged With: accuracy, EA, emotion, expert advisor

Position Sizing for the Scalper EA

April 2, 2013 by Shaun Overton 10 Comments

Andrew posted a great comment on the Scalper EA noting how he increased profits dramatically with position sizing. You can think of the expert advisor as the orange and the potential profit as the juice. We want to squeeze out every last drop.

Orange juice squeeze

Squeeze more profit out of your expert advisor with position sizing rules

I always talk about winning percentage and the R multiple together. It doesn’t matter that if win 99% or 15% of the time. It matters how much you win compared to how much you lose. Winning frequently does not correspond to profitable trading.

Only when you know the percent accuracy and R multiple can you determine expectancy: do I expect to make a profit or not following this expert advisor?

The explanation reveals two assumptions:

  1. I know the real accuracy of the system
  2. I know the real R multiple
Accuracy and R Multiple

NinjaTrader backtest reports show the percent accuracy and the R Multiple (ratio of avg win to avg loss)

I don’t know either for a certain fact. The real accuracy and real R multiple may be above or below the numbers seen in backtesting.

It’s important that we consider how we developed these numbers. I found them after analyzing an entire year’s worth of chart data. There’s a real risk that they overestimate future performance.

The forward test for 2012 discounted that notion – the R multiple and percent accuracy numbers actually improved on the blind data. But, as most of you know, I’m extraordinarily risk averse.

I assume the worst case scenario in nearly everything that I do. If the worst case isn’t so bad and the average case is fantastic, that’s the only threshold that pushes me past my risk inhibition. It has to be a really amazing opportunity for me to pull the trigger.

A pessimist’s view on position sizing

The goal is not to maximize profits. It’s more complex than that. The real goal is to maximize profits with a view to how many losses you can stomach.

That number is pretty low for me. Use bigger numbers if you can tolerate more pain.

I operate with the same attitude when selecting my position sizing strategy. It’s important to make reasonable, yet pessimistic, assumptions when selecting your money management approach.

Step 1: Decrease the strategy’s accuracy by 5%

Strategies vary in their accuracy with the chart and instrument where it operates. I have not done an analysis, but my rule of thumb is that accuracy fluctuates ±5%. The worst percent accuracy seen is usually within 5% of the best percent accuracy seen.

The rule generally holds across multiple instruments and time frames. Once you get a feel for the accuracy, you take the observed accuracy and subtract 5%.

The scalping strategy profited 75.93% of the time after including trading costs. Removing 5% off of that number leaves a reasonable worst case assumption of 70.93% accuracy.

Step 2: Decrease the R multiple by 20%

The method used here depends on the expert advisor’s trading style. Range trading expert advisors usually come out with an R multiple (average win/average loss) within a consistently narrow band. Trending EAs exhibit wild fluctuations in the R multiple.

This should make sense to readers with several years of trading experience. Range trades earn profits on the majority of trades. No individual trade contributes dramatically to the final outcome.

Trend trades do exactly the opposite. A small handful of trades contribute enormously to the overall result. The traders faces the risk of overemphasizing how well volatility played to his in advantage in the past. If trends of similar magnitude fail to materialize, the trader’s estimate for the R multiple will be wildly off the mark.

Rules of thumb for adjusting R multiple assumptions:

  1. Cut the observed R multiple for a ranging strategy by 20%
  2. Cut the observed R multiple for a trending strategy by 33-50%

The scalper EA trades ranges and showed an R multiple of 0.53. Cutting that number by 20% reduces it to 0.424.

Apply pessimistic assumptions to model money management

The adjusted numbers for the scalping strategy are 70.93% accuracy and an R multiple of 0.424. I can now take these numbers and start playing with the money management software.

The first thing that I did was to reduce the number of trades in the test to 100. That equates to roughly 1 year of trading, which is a meaningful period of time for this expert advisor.

Fixed fractional money management using 1% risk and the pessimistic assumptions puts the trader slightly ahead of breakeven after trading costs (a 1% profit). The worst case scenario shows an annual loss of 25%. Nobody wants a loss like that. But, it’s something that I can handle as a plausible worst case.

Final numbers

Pessimistic position sizing assumptions

The pessimistic money management assumptions still show an average profit.

Increasing the percent number to 2% doubles the minimum and maximum outcomes. Tripling it to 3% triples the worst and best outcomes. You should select a number whose worst outcome strikes you as something personally acceptable to you.

I selected 1%. The worst case scenario is something that I can handle. The next step is to split the difference between the observed numbers and the pessimistic number for the percent accuracy and R multiple.

The numbers are 73.43% accuracy and 0.477 for the accuracy and R multiple. When I plug the numbers into the software, it spits out an average return of 8.9% with a maximum upside of 40.9% after 100 trades.

Moderate position sizing assumptions

Moderate assumptions for position sizing show an average return of 8.9%.

Using fixed fractional money management squeezed more juice out of the orange. We brought the worst case scenario up to -25% and the best case scenario on moderate assumptions to over +40%. More importantly, the average return increases without affecting the best and worst cases.

What position sizing ideas do you have? Leave your thoughts in the comments section below.

Filed Under: Stop losing money Tagged With: backtesting, EA, expert advisor, money management, position sizing, R multiple, scalping

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

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

Too Many Charts

July 5, 2012 by Shaun Overton 2 Comments

A million charts on the screen. It looks like a blob of every known currency pair with a mix of every time frame added for good measure. You, my friend, suffer a nightmare juggling the EA settings on all these charts.

The idea of running a single Expert Advisor that trades all charts and multiple time frames stands out as an obvious solution. It’s not a good one, though. The way that MetaTrader 4 is designed prevents this setup from working smoothly.

The start() function in MQL4

MQL4 Expert Advisors only run in one of three different ways. The init() function is called when you load the EA onto a chart. The deinit() function operates whenever you remove the EA. That leaves the start() function. It’s like the beating heart of all MQL4 programs.

Incoming ticks tell the chart to notify an attached expert advisor about the updated price. When that occurs, the expert advisor runs the start() function. That function contains all of the code that traders associate with expert advisors: placing trades, implementing trailing stops, etc. All of those actions depend on incoming ticks.

The organization of MQL4 creates a problem for the goal of creating an EA that places trades for all charts. Expert advisors only update when a tick comes in. If I wanted to trade the GBP/JPY from a chart attached to the EUR/USD, any delay in EUR/USD ticks causes a delay in executing GBP/JPY trades.

This probably does not seem like a big deal. It isn’t a big deal – most of the time. It can, however, create a nagging problem of wondering why a noticeable percentage of trades seem to execute late. Traders on one minute charts would even notice missed signals. Although it’s not frequent, even the major pairs often go longer than one minute in between ticks.

Work-arounds

One idea to reduce the number of open charts while ignoring the incoming tick problem is to create an EA that trades on multiple time frames for the currency pair where it’s attached.  If I wanted to trade the AUDCAD on M30, H1, H4 and D1 charts, then I could place the EA on one of the those charts but have it look for trades on the selected time frames. This type of solution could decrease the number of open charts by 75% or more.

The idea of controlling everything from a single chart is very similar to the market scanning indicator that we created several months ago. There is really no difference between that indicator and the expert advisor proposed here. I feel that missing an indicator signal is of far less consequence than missing trade signals. Expert advisors are more likely to perform extra, ongoing operations like trailing stops that indicators completely ignore. The consequence of delayed ticks is far less significant for an indicator than it is for an EA.

Filed Under: MetaTrader Tips Tagged With: EA, expert advisor, indicator, metatrader, mql, multiple time frame, scanner, start

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

Magic number in MetaTrader

March 20, 2012 by Shaun Overton

The magic number is a Metatrader concept used to track the open positions of an EA. The concept allows the Ea to distinguish the trades that it opened versus those that it did not.

Each car uses a license plate. When you detect a car in a different state or even a different country, you observer that every plate that you come across is unique. Law enforcement can utitlize the number to determine who owns the car.

Magic numbers function like the license plates for expert advisors. When an expert advisor detects an open trade, called a ticket, it repeatedly asks for its magic number. If the magic number of the ticket is identical to the number that the expert advisor expects, then it knows to manage the position.

Magic numbers are helpful, particularly when you want to trade multiple time frames of the same forex pair. Traders often use settings that differ from those on M1 prices versus those that they would use on the daily chart. If they used the Expert advisor with the same magic number on all different time frames, the result would be chaos. The expert advisor would open and close positions with no rhyme or reason. Setting every Expert advisor to emply an unique magic number disallows the robots from interfering with the others.

Magic number factoids

The magic number of a manually opened trade is 0.
The number that you use for a magic number must be a number ranging from 0 and 2147483647. The MQL programming language assigns that last number EMPTY_VALUE and protects the name as an integer value.

OneStepRemoved.com is a company that specializes in programming an expert advisor for traders. Shaun Overton is the company owner.

Filed Under: How does the forex market work? Tagged With: EA, expert advisor, magic number, metatrader

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

Reverse engineer expert advisor

January 27, 2012 by Shaun Overton 2 Comments

I guarantee that you are not the first trader to consider the idea of reverse engineering an expert advisor. The idea pops up most frequently among traders that don’t want to pay for a commercial expert advisor. Alternatively, they want to use the same strategy when another trader that doesn’t want to share the idea. The motivations for reverse engineering remind me of decompiling EAs, making me leery of the idea.

Reverse engineering a strategy only stands a chance when some parameters are known about the strategy. If, for example, you knew that the strategy involves MACD and moving average crossovers, it at least provides a reasonable starting point. The programmer could write software which combines every possible combination of two moving averages of various types with every known type of MACD. The programmer could then make guess about which types of signals might result in a buy or sell decision. If the guesses are not very good, then the outcome of the reverse engineering attempt is certain failure.

Then you have the problem of guessing on which chart to base the decisions. Many traders use standard charts like the M1 and M15, but many others use less common options like an M3. If the trader uses multiple charts like an M2 and M10, the resulting trade history would clutter together. Good luck trying to pry apart the different series.

Making things worse is if the trader uses a chart that doesn’t depend on time at all. Tick charts are the most common, although you occasionally see less orthodox options like Point and Figure charts and Kagi charts. Time is irrelevant. You wouldn’t have any idea on which charts to run the test.

This approach of making somewhat intelligent guesses while throwing mud at the wall is called a brute force attack. You literally designate every unique possible combination, then see which one opens the metaphorical safe. Some results will bear no resemblance at all to the actual results. If you get extraordinarily lucky and/or have fantastic intelligence, then you might find a close replica of the strategy.

It would be possible to study the correlation of the tested values with the values in the supplied account statement. You would ideally want to find data clusters with similar variable settings that do not dramatically alter the correlation between the reverse engineered strategy and the actual account statement.

If you don’t know very much about the strategy, or if what you think you know turns out to be wrong, then you stand no chance at all of reverse engineering the expert advisor. For all that you know, the EA that you thought used RSI might turn out to run on phases of the moon (yes, there are real strategies that do that) or that make decisions based on coin flips.

Most people assume that they know more than they really do. I would discourage all but the most fool hearty or stubborn from making the attempt, unless you had a very good reason for doing so.

Filed Under: MetaTrader Tips, NinjaTrader Tips, Trading strategy ideas Tagged With: EA, expert advisor, reverse engineer

Scripts in MetaTrader

January 26, 2012 by Shaun Overton Leave a Comment

Scripts are executable files in MetaTrader that only run one time. They are perfect for tasks that are routine but time consuming or unpleasant to do. The most advantageous use of scripts is that they do not rely on incoming price ticks in order to run. The script executes the moment that the trader drops it onto a chart.

An expert advisor runs continuously, but it relies on incoming ticks to know that it should update itself. The frequency that the market changes price varies with the time of day. This means that the period between updates for an expert advisor is highly unpredictable. The predictability of a script’s timing – it runs immediately – makes it more suitable for some trading tasks than an EA.

Script examples

A scalper wants to open a trade quickly. He routinely applies a 20 pip stop loss and a 3 pip take profit. His usual process would involve:

  1. Click inside of MetaTrader to open a trade
  2. Select the correct forex pair
  3. Wait for the trade to open
  4. Frantically add the take profit as quickly as possible

Alternatively, the trader could keep his chart open and the scripts window nearby. Whenever he decides to trade, he drags the script onto the chart. The steps above still occur. The critical difference is that they happen in a fraction of the time. The script runs once, then it removes itself from the chart.

Some tasks require a tiresome amount of clicking rather than speed. Scripts are also useful in that scenario. A lot of MetaTrader users like to stack multiple pending orders above and below the market in a grid pattern. An example would involve placing 10 orders above and below the market at different prices. Doing this manually would take a few minutes.

The alternative is to run a script that does it one time for you. Scripts can display input screens just like expert advisors. That way the user can control the settings.

When the trader is ready to bracket his orders, he drags and drops the script onto the chart. The orders show up on the screen at the requested prices. The total time takes a few seconds instead of several minutes.

Other script uses

The most common, though unorthodox, use of a script is to feed prices into the History Center for a custom offline chart. The script is programmed to run at a set interval such as every half second. The script samples the price, then records the information where the historical prices are kept. The offline chart then re-reads the information and updates the price.

MQL programmers elect to use a script instead of an expert advisor because they are setting an infinite loop. Although scripts technically run once, this script is never allowed to finish its first run. It keeps waiting every set interval to update the price. EAs would not work well here because new, incoming ticks would create a backlog of occasions where the EA is supposed to have run. I would expect MT4’s memory use to eventually get out of control and crash the program if someone elected to take this approach. Even though it is not an ideal solution, scripts update historical prices successfully without the tick backlog concern.

Filed Under: MetaTrader Tips Tagged With: EA, expert advisor, history center, metatrader, pending order, scalper, script

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