RISK WARNING : Devido ao factor de risco ser muito alto no trading no mercado Forex, somente os fundos livres devem ser usados para este trading. Se você não tiver o capital extra, que pode perder, não deve fazer trading no mercado Forex. O trading no Forex é conveniente somente para os traders institucionais ou traders privados experientes que podem resistir a perdas financeiras e que podem exceder o valor de margem ou depósitos. O investimento implica riscos substanciais, incluindo a possibilidade de perda total de capital e outras perdas que podem ser inaceitáveis para muitas pessoas. O governo não protege investimentos de perdas no mercado, diferentemente de poupança e de contas correntes num banco. Vários instrumentos de mercados financeiros têm diferentes tipos de riscos e de vários níveis. Trading em sistema electrónico pode ser diferente não somente de trading num mercado de leilão, mas também de outros sistemas de trading electrónico. Se você executa transacções usando um sistema electrónico de trading, estará exposto a riscos relativos a este sistema, incluindo falhas de software e hardware (programas de computador). O resultado desta falha pode ser que sua ordem não tenha sido efectuada conforme as suas instruções ou não tenha sido executada. Transacções realizadas em mercados de jurisdições estrangeiras, incluindo os mercados anteriormente ligados a um mercado nacional, podem expor você a riscos adicionais. Tais mercados podem estar sujeitos a regras e leis, que oferecem outras condições de protecção ou debilitá-los. Sua autoridade reguladora local não será capaz de forçar o cumprimento das regras das autoridades reguladoras, ou dos mercados em outras jurisdições onde suas transacções foram efectuadas. Você precisa obter a informação completa sobre tipos de compensação existente, as regras aplicáveis na jurisdição do seu país e outras jurisdições relevantes, antes de começar a fazer trading. Nenhum sistema de negociação "seguro" foi descoberto/reconhecido e ninguém pode garantir lucros ou liberdade de perda. Qualquer desempenho apresentado neste blog, não garante resultados futuros. Nenhuma representação é feita que qualquer conta é susceptível de obter lucros ou perdas semelhantes aos mostrados. De facto, existem diferenças acentuadas entre os resultados de desempenho anteriores e os resultados futuros subsequentemente alcançados por qualquer configuração de conta particular. Existem inúmeros outros factores relacionados com os mercados em geral ou com a implementação de qualquer configuração de conta específica que não possa ser totalmente contabilizada na preparação de resultados de desempenho anteriores e que possam afectar negativamente os resultados futuros de negociação. Uma vez que a negociação com êxito depende de muitos elementos, incluindo mas não limitado a uma configuração de conta . Por favor, perceba o risco envolvido como qualquer investimento e consulte Profissionais de Investimento antes de equacionar investir/operar.
Because the risk factor is very high in Forex trading, only free funds should be used for this trading. If you do not have the extra capital that you can lose, you should not do trading in the Forex market. Forex trading is only convenient for institutional traders or experienced private traders who can withstand financial losses and who may exceed the margin amount or deposits. The investment entails substantial risks, including the possibility of total loss of capital and other losses that may be unacceptable to many people. The government does not protect investments from losses in the market, unlike savings and checking accounts at a bank. Several financial market instruments have different types of risks and different levels. Trading in electronic systems may differ not only from trading in an auction market, but also from other electronic trading systems. If you execute transactions using an electronic trading system, you will be exposed to risks related to this system, including software and hardware failures (computer programs). The result of this failure may be that your order has not been carried out according to your instructions or has not been carried out. Transactions in markets of foreign jurisdictions, including markets formerly linked to a domestic market, may expose you to additional risks. Such markets may be subject to rules and laws, which offer other conditions of protection or weaken them. Your local regulatory authority will not be able to force you to comply with the rules of regulatory authorities, or markets in other jurisdictions where your transactions were made. You need to get complete information on existing compensation types, applicable rules in your country's jurisdiction and other relevant jurisdictions, before you start trading. No "safe" trading system has been discovered / recognized and no one can guarantee profits or freedom from loss. Any performance featured on this blog does not guarantee future results. No representation is made that any account is likely to make profits or losses similar to those shown. In fact, there are sharp differences between the previous performance results and future results subsequently achieved by any particular account configuration. There are a number of other factors relating to markets in general or to the implementation of any particular account configuration that can not be fully accounted for in the preparation of past performance results that could adversely affect future trading results. Since trading successfully depends on many elements, including but not limited to an account setup. Please note the risk involved as any investment and consult Investment Professionals before considering investing / operating.
Cumprimentos Marco Henriques

29/11/2020

Automateyourself Well

Automateyourself Well


How to determine if an indicator is suitable for Expert Advisors

Most Expert Advisors use one or more indicators. MetaTrader platform delivers a set of build‑in indicators and additionally a possibility to write own indicators (Custom Indicators). Unfortunately, a lot of indicators that can be found in the Internet can't be used by Expert Advisors, because for example they are badly implemented or they only draw objects and can't be used in a standard way. The other common reason for disqualifying an indicator is the usage of data taken from the future in calculations (not only current and past candles). For example to calculate the value of 5‑period simple moving average for a bar at 2008.01.01 12:00 on a H1 chart, we need bars from 8:00, 9:00, 10:00, 11:00 and 12:00. Now, imagine that certain indicator uses bars from 8:00 to 14:00 to display value at 2008.01.01 12:00. So it uses 2 bars taken from the future. How is it possible? It is possible only on the basis of historical data. In live trading these 2 future bars of course won't be available. That's why this indicator will look different on a historical data and after some time in live trading. Sometimes such indicators change values not only for the most recent bar. We call such behaviour "redrawing". Generally, such indicators aren't suitable for an Expert Advisors. In rare cases, some of indicators that redraw can be used, but it must be fully conscious. A good example of an indicator, that redraws but can be used (but very consciously) in Expert Advisors, is ZigZag, which is provided with MetaTrader terminal.

Below there are 3 steps which will help you test indicators and check if they are suitable for an Expert Advisors.

Step 1 – Data Window

The Data Window can be turned on in MetaTrader terminal by pressing Ctrl + D or via main menu View -> Data Window. In the Data Window quotations and values of all used buffers (in this example all buffers are visualized as lines) of all attached indicators are displayed: Moving Average, Stochastic Oscillator and ADX. Buffer is a series of values that can be visualized in a few different ways: lines, dots, histogram. Moving Average has one buffer, Stochastic Oscillator two (main line and signal line) and ADX has three buffers (ADX, +DI and -DI).

Also Custom Indicators should be displayed in the Data Window. Make sure that option Show in the Data Window is selected in Visualization Tab in indicators' properties.

If, in spite of above setting, an indicator is not displayed in the Data Window, it is generally not suitable for Expert Advisors. Of course, to every rule there is an exception. If your indicator only draws objects (for example Pivot levels for only current day), it won't be displayed in the Data Window. An Expert Advisor can retrieve values from objects but backtesting of such Expert Advisor will be impossible or very limited. In fact, it will be possible only in visual mode after manual attaching this indicator to a chart. Also Optimization won't be possible. That's why such indicators aren't recommended for Expert Advisors. However, they can be successfully used in a manual trading.

Step 2 – Historical view vs. Current view

If analysed indicator passes Step 1, it is time for the next test. Every properly written indicator must look identical after some time of running and just after attaching to a chart. See example:

If we attached this indicator at 2008.08.13, it would look like in the lower chart. But if we attached this indicator at 2008.08.08 and let it run for 3 days, it would look like in the upper chart. The difference is obvious. In live trading this indicator gives only a few signals in spite of many perfect signals on a historical quotations. For a properly implemented indicator, both charts must be identical.

How to conduct such test? Very simple:

  1. Open any chart (lower timeframes are better, because you will see any problems with indicator sooner)
  2. Place vertical line on the latest bar to remember where the beginning of a test is
  3. Attach analysed indicator to a chart
  4. Wait a few hours (this time depends on selected timeframe; the more candles, the better)
  5. Once again attach analysed indicator
  6. Compare how they look; you can use the Data Window to compare all values precisely

For indicators, that are displayed on a main chart just after conducting the whole test, open a new chart and compare both views by switching from one chart to the other.

You don't have to wait a few hours or days for the result. To speed up examination you can use Visual mode in backtester – for example any Expert Advisor, although the best will be one that does absolutely nothing. Download VisualTester that only places vertical line at the beginning (VisualTester.ex4).

Make sure that Visual mode option is selected. Move scrollbar to the left to have time to attach the indicator. You don't have to use Every tick model; for most cases Control points will be sufficient. Click on the Start button and follow points 3 to 6. In point 4 just move scrollbar to the right and after some time move it back to the left.


Step 3 – IndicatorTester

This is the final step. It enables us to eliminate most of wrong indicators that have positively passed two previous steps. IndicatorTester should be used wisely. It simulates the usage of an indicator in an Expert Advisor. With every tick, it compares all indicator's buffers to their previous values and checks how many indicator's values (expressed in bars) have been changed. For most proper indicators the result (called Redraw Factor) will be equal to 1 or 0. Redraw Factor is the maximum amount of changed bars for whole test and all buffers. Redraw Factor = 1 means that the indicator changes only its most recent value. Values of completed bars are not changed. Redraw Factor = 0 means that the indicator never changes its values. A good example of such indicator is the moving average based on open prices (not close prices). Because open price remains unchanged, the result of calculations is also the same.

You can find indicators that are implemented correctly, but their Redraw Factor is equal to 2. These indicators are visualized as one line, but in two colours. For example, one colour corresponds to the rising part of the line and the other colour to the descending part. This is because each colour of this indicator requires separate buffer – this is the only way to implement such visualization in MetaTrader. However, to avoid any ambiguities, such indicators should be visualized as dots in two colours, not lines. Additionally, lines can overlap on each other, which can lead to seemingly strange behaviour of an Expert Advisor. Overlapping of lines can be detected via the Data Window – more than one buffer will be active at the same time. Also indicators, that are based on other indicators from higher timeframes, can have Redraw Factor higher than 1. For example, if an indicator on H1 chart uses other indicator from H4 timeframe, it can have Redraw Factor equal to 4 instead of 1 (there are 4 H1 candles for one H4 candle).

The usage of IndicatorTester needs some explanation. File IndicatorTester.ex4 should be placed as other Expert Advisors in experts subdirectory. As it is a kind of Expert Advisor, which doesn't trade but checks indicators, it also has its own parameters.

  • IndicatorName is the name of analysed indicator. It is simply the name of indicator's file without extension. Examples: ZigZag, Heiken Ashi. Remember to write indicator's name very carefully. A typo totally prevents from working. You can also test build‑in indicators. The full list of build‑in indicators can be found here docs.mql4.com/indicators. These indicators' names start from lower‑case letter i. From obvious reasons indicators iXxxxxOnArray can't be analysed.
  • IndicatorParameters is also very important. Each Custom Indicator or build‑in indicator can have a different number of its own parameters. That's why these parameters are passed in a little bit different way. Simply, parameters are separated by | (pipe sign, broken vertical bar). The order of parameters is very important. Any value, which is not a string, can be passed via this mechanism. True values should be replaced by 1 and False by 0. Examples: Parabolic SAR indicator has two parameters Step and Maximum, so IdicatorParameters field should look like this: 0.02|0.2. For build‑in 14‑period simple moving average from close prices this parameters should look like this: 14|0|0|0. The first 0 means shift equal to zero, the second 0 means that it is a simple moving average, not exponential or something alike, the third 0 means that it is calculated from close prices. The order of parameters and values of methods and prices are taken from the documentation docs.mql4.com/indicators/iMAIf you want IndicatorTester to use default parameters of the indicator, just leave this field empty. Also if the indicator has any string parameter, then you will have to use default parameters, so leave this field empty.
  • RangeBars parameter defines how many latest bars from each buffer are stored in IndicatorTester memory. Bigger value means more comparisons and slower performance, but if potential change occurred beyond RangeBars, it wouldn't be detected.

IndicatorTester should be run for at least 100 bars. The more, the better. It can be used both in live trading and backtester (Visual mode).

Examples:

Note: Analysed indicator is drawn on a chart automatically after the end of a backtest (after clicking on the Stop button). If you want to observe the indicator during test, you have to attach it to the chart by yourself.

  1. 14‑period Simple Moving Average from open prices

    IndicatorName: iMA
    IndicatorParameters: 14|0|0|1
    RangeBars: 100


    According to the theory, moving average from open prices never changes even current value. So Redraw Factor is equal to 0. The name of indicator is yellow, which means that IndicatorTester tests build‑in indicator.
  2. Parabolic SAR with parameters 0.02 and 0.2

    IndicatorName: iSAR
    IndicatorParameters: 0.02|02
    RangeBars: 100


    Just after starting the test Redraw Factor is equal to 0, which means that once placed dot doesn't change its position. But when price crosses the most recent dot, Parabolic SAR moves the dot to the opposite side and Redraw Factor changes its value to 1.
  3. ZigZag indicator with default parameters: 12, 5, 3

    IndicatorName: ZigZag
    IndicatorParameters: 12|5|3
    RangeBars: 100


    The high value of Redraw Factor doesn't surprise. ZigZag indicator can change its swings even after a huge amount of bars. It can be used in Expert Advisors but very consciously, because the most recent or even the previous swing can disappear or ZigZag can place a new swing between them. With every tick current configurations of swings should be read.
  4. Build‑in Fractals indicator

    IndicatorName: iFractals
    IndicatorParameters: (empty field)
    RangeBars: 100


    This indicator doesn't have any parameters. Despite the fact that it is a build‑in indicator, its Redraw Factor is equal to 3. Moreover, values of all buffers for the most recent bar (B#0, B#1, ... B#7) are always equal to 0. What does it mean? It means that all arrows are placed not when the most recent candle is being formed, but after 2 or 3 candles. So in fact, these perfect signals aren't so perfect, because they are drawn with 2 or 3‑bar delay. It doesn't mean that this indicator is useless. Simply, it can't be used in the most intuitive way – as buy and sell signals. For example, it can be used as the detector of swings that will be used for further calculations.

Summary

  1. Step 1 – Indicator's buffers must be visible in the Data Window
  2. Step 2 – Historical and current views must be identical (VisualTester.ex4)
  3. Step 3 – Redraw Factor should be equal to 0 or 1 (IndicatorTester.ex4)
Green pips, Traders.