Saturday 29 April 2017

Forex Trading Markt Analyse

Trading-Signale Diese leicht zu folgen Trading-Empfehlungen sagen Ihnen, wann Sie kaufen, wann verkaufen und wo Sie Ihre Stopps und Grenzen gesetzt. Die Signale werden in Echtzeit, 24 Stunden am Tag, 5 Tage die Woche generiert und aktualisiert. Technical Analyzer Entdecken Sie kritische technische Ebenen auf Diagrammen (drei Stufen der Unterstützung, drei Ebenen des Widerstands). Bleiben Sie informiert über wichtige Indikatoren Crossover wie gleitende Durchschnitte, MACD und RSI. Und sehen Sie signifikante Candlestick-Muster auf Diagrammen. Spekulative Sentiment-Index Dieses leistungsstarke Tool zeigt die Stimmung des breiteren Devisenmarktes (d. H. Wie viele Händler ein Währungspaar gekauft oder verkauft haben) und wird am besten als konträrer Indikator verwendet, wenn die Märkte stark wachsen. On-Demand Video Kurse Lernen Sie Forex zu erlernen oder entdecken Sie neue Strategien und Trading-Tipps aus diesen Video-Kursen. Wählen Sie aus 60 Unterrichtsstunden, die eine Reihe von grundlegenden und erweiterten Themen umfassen: fundamentale Analyse, technische Analyse, Geld-Management, und vieles mehr. Live Classroom Erlernen Sie, Forex von den DailyFX Kurslehrern zu handeln. Join Live-Trading-Sitzungen, Montag bis Freitag, um einfache und erweiterte Forex-Konzepte und Strategien zu lernen. Real, aktuelle Handelsbeispiele werden verwendet, um ihre Wirksamkeit zu maximieren. Forex Artikel Donnerstag, 24. November 2016 13:17 UTC Diese eToro-Überprüfung durch das Team von professionellen Experten bei ForexSQ für diejenigen, die über das eToro wissen wollen durchgeführt. Im Jahr 1997, da die Deregulierung der Forex-Handelsbranche, gab es eine riesige Verbreitung von Internet-basierten Spot Forex. Sonntag, 06. November 2016 01:42 UTC Diese AvaTrade Überprüfung wurde von ForexSQ Experten für diejenigen, die über den AvaTrade Forex Broker wissen wollen, durchgeführt. Das AvaTrade Unternehmen, das zuvor als AvaForex oder AvaFX Broker, Estd. Im Jahr 2006 gehört zu den obersten Fx Brokern der Welt mit. Mittwoch, den 02. November 2016 04:29 UTC Die Finanzmärkte bieten den Händlern eine moderne Plattform für den Zugang zu einer breiten Palette von Vermögenswerten und Wertpapieren wie Aktien, Devisen, Rohstoffen und Derivaten. Jedoch ist es praktisch unmöglich für jedermann, im globalen Finanzsystem zu handeln. Dienstag, den 01. November 2016 um 07:03 Uhr UTC Diese Plus500-Überprüfung von ForexSQ Experten-Händler-Team durchgeführt für die Händler wollen wissen, über die Plus500 Unternehmen, Alles über Plus 500 ltd erklären, wie Plus500 Aktienkurs, Plus500 WebTrader, Lesen Sie diese Plus 500 Bewertungen vor öffnen . Donnerstag, den 27. Oktober 2016 um 14:47 Uhr UTC Diese HYCM-Überprüfung durch das Team von ForexSQ Experten für diejenigen, die wissen wollen, wie zu öffnen Handelskonto mit HYCM Broker. Der HYCM Forex Broker ist der Handelsname der Henyep Capital Markets Ltd., ein Teil der Henyep Gruppe, a.


Friday 28 April 2017

Forex Handelsunternehmen In Hong Kong

Asien: Hong Kong Hong Kong (SFC) Regulierung News 28 Dez 2016, Hongkong - Blackwell Global Pressemitteilung - Hongkong-China Stock Verbinden Sie einen Boost auf die Multi-Asset-Brokerage. International Forex und CFDs Brokerage Blackwell Global kündigt heute die Übernahme von 2 neuen. 26 Dez 2016, Hongkong - Finanzkommission Pressemitteilung - Führende externe Streitbeilegungsorganisation (EDR), Finanzkommission, die für die Finanzdienstleistungsbranche tätig ist und heute von FinaCom PLC betrieben wird. 30 Nov 2016, Hongkong - FinanceFeeds Pressemitteilung - Die britische Handelsgesellschaft One Financial Markets hat heute in Hongkong den neuen Regulierungsstandard für Wertpapiere und Futures (SFC) bekannt gegeben. 19.10.2016, Hongkong - Hongkong Wertpapier - und Futures-Kommission - Die Securities and Futures Commission (SFC) hat die FXCM Asia Limited (HK FXCM) (jetzt bekannt als Rakuten Securities Hong Kong Limited) HK4 gerügt und verurteilt. In Verbindung stehende Forex-Vermittler-Nachrichten 20 September 2016, Hong Kong - LeapRate - Rakuten Wertpapiere Hong Kong begrenzt (Rakuten Wertpapiere HK) verkündeten heute Rakuten FX, ein nagelneuer forex Kontoservice für Klienten, um durch eine firmeneigene Handelsplattform zu handeln. Mit. 11 Jul 2016, London, Großbritannien - LeapRate - Die IKON MultiBank Group, ein Online-Anbieter, der von der Financial Conduct Authority UK und der Australian Securities Investments Commission reguliert wurde, gab heute bekannt. 14 Sep 2015, Hongkong - ADS Securities Pressemitteilung - Retail-Angebot von preisgekrönten Abu Dhabi-basierte Finanzdienstleistungsunternehmen jetzt zur Verfügung Hong Kong Kunden. Vertreter aus der Finanzdienstleistungsbranche. 29. Mai 2015, Hongkong - Finanzen Magnaten - Die Unternehmen kündigten den Abschluss des Deal, mit CITIC vereinbaren, 100 Millionen für fast 60 der KVB Kunlun zahlen. KVL Kunlun und das chinesische Unternehmen CITIC Securities angekündigt. 27 Apr 2015, Hongkong - Business Wire - Die 5. jährliche IAIR Awardsreg fand am 10. März 2015 in Hongkong statt, dem eine Konferenz mit dem Titel Asia CEO Summit vorangegangen war. Mehr als 50 Unternehmen wurden für ihre anerkannt. 19 März 2015, Hongkong - AtoZ Forex - Der führende Anbieter von FX - und CFD-Produkten, IKON, hat die Öffentlichkeit über ihre jüngste Produktfreigabe informiert. Nämlich eine neue Version ihrer Wundplattform, wie viele Firmen jetzt verlegen. 15 Dez 2014, Saudi-Arabien - Reuters - Die IKON Group, der weltweit führende Forex Currencies Trading Broker, wurde auf der 7. Saudi Money Expo 2014 mit der Best Institutional FX-Plattform 2014 ausgezeichnet. Trading Devisen auf Margin trägt ein hohes Maß an Risiko und möglicherweise nicht für alle Anleger geeignet. Die Möglichkeit besteht, dass Sie einen Verlust von einigen oder allen Ihrer anfänglichen Investition zu erhalten und daher sollten Sie nicht investieren Geld, das Sie nicht leisten können, zu verlieren. Sie sollten sich bewusst sein, alle Risiken im Zusammenhang mit Devisenhandel und suchen Beratung von einem unabhängigen Finanzberater, wenn Sie irgendwelche Zweifel haben. 169 2007-2016 - VDO Enterprises, Inc. Forex Broker Hongkong OptiLab Partner AB Fatburs Brunnsgata 31 118 28 Stockholm Schweden Der Handel mit Devisen an der Marge hat ein hohes Risiko und ist möglicherweise nicht für alle Anleger geeignet. Der hohe Grad der Hebelwirkung kann sowohl gegen Sie als auch für Sie arbeiten. Vor der Entscheidung, in Devisen zu investieren, sollten Sie sorgfältig überlegen Sie Ihre Anlageziele, Erfahrung und Risikobereitschaft. Keine Informationen oder Meinung auf dieser Website sollte als eine Aufforderung oder ein Angebot zum Kauf oder Verkauf von Währung, Eigenkapital oder andere Finanzinstrumente oder Dienstleistungen genommen werden. Die Wertentwicklung in der Vergangenheit ist kein Hinweis auf die zukünftige Wertentwicklung. Bitte lesen Sie unsere rechtlichen Hinweise. Kopie 2017 OptiLab Partners AB. Alle Rechte vorbehalten. Fixed Spreads werden in Rakuten FX Account während mindestens 95 der monatlichen Kern-Zeit (8 Uhr bis 2 Uhr HKT von jedem Handelstag) angeboten. Raw Spreads, die sich auf die direkten Anführungszeichen von Liquiditätsanbietern beziehen, werden im Trading Station-Konto angeboten. Spreads, die oben und in unserer Website gezeigt werden, dienen nur als Referenz und sind nicht garantiert und können über die durchschnittlichen Spreads, die von der Volatilität des Marktes abhängen, erweitert werden, insbesondere bei extrem geringer Liquidität, Nachrichten oder öffentlichen Feiertagen. Bitte beziehen Sie sich immer auf die Handelsplattformen für die aktuellsten Spreads. 606 Die Orderausführungsquote berechnet sich aus 9.043 der AS Streaming - und Streaming-Handelsaufträge in 10k-Auftragsgröße mit 1 Pip-Schlupf-Einstellung im Zeitraum zwischen dem 1. und 25. August 2016 167 Rakuten Securities HK bietet Trading Station-Plattform über ihren Partner FXCM an. Während Tradency ist der Anbieter von Mirror Trader Plattform Rakuten Securities HK. 8251 Die Kommission wird pro Handelsseite sowohl auf offenen Handel (en) als auch auf engen Handel (en) aufgeladen. Alle Provisionen können von Zeit zu Zeit ohne vorherige Ankündigung geändert werden. Bitte beziehen Sie sich immer auf den aktuellsten Plan der Standardgebühren und Gebühren. Die hier angegebenen Rohstreuungen dienen nur als Referenz. Sie bezieht sich auf die von den Liquiditätsanbietern erhaltenen direkten Quotes, sie kann je nach Marktlage variieren. Bitte beziehen Sie sich immer auf die Handelsplattform für die aktuellsten Rohaufschläge. Hinweis: USDOLLAR wird nicht mit der neuen Provisionsstruktur angeboten und wird weiterhin mit Aufschlag angeboten. Um Ihr Rakuten Securities HKs-Handelskonto zu schützen, sollten Sie Ihr Passwort regelmäßig ändern und ein sicheres Kennwort festlegen. Rakuten Securities, Inc. ist eine hundertprozentige Tochtergesellschaft von Rakuten Securities, Inc. (Rakuten Securities, Inc.). Einer der wichtigsten Online-Broker in Japan, gegründet 1999, ist eine Tochtergesellschaft von Rakuten Securities Rakuten, Inc. (TOKYO: 4755). Das Verlustrisiko im Fremdwährungshandel kann erheblich sein. Sie können nicht geeignet sein, da Sie Verluste über Ihre ursprünglichen Margin-Fonds. Leverage kann gegen Sie arbeiten. Die Platzierung bedingter Aufträge, wie Stop-Loss - oder Stop-Limit-Aufträge, begrenzt nicht unbedingt Verluste auf die beabsichtigten Beträge. Marktbedingungen können es unmöglich machen, solche Aufträge auszuführen. Sie können kurzfristig angerufen werden, um zusätzliche Margin-Fonds einzahlen. Wenn die erforderlichen Mittel nicht innerhalb der vorgeschriebenen Zeit zur Verfügung gestellt werden, kann Ihre Position liquidiert werden. Sie haften für ein daraus resultierendes Defizit in Ihrem Konto. Sie sollten daher sorgfältig prüfen, ob ein solches Trading im Hinblick auf Ihre eigenen Finanz - und Anlageziele geeignet ist. Spekulieren Sie nicht mit Kapital, das Sie sich nicht leisten können, zu verlieren. Wenn Sie sich entscheiden, Produkte von Rakuten Securities HK zu vertreiben, müssen Sie die Informationen und die Offenlegung von Rakuten Securities HK lesen und verstehen. Rakuten Securities HK kann allgemeine Anmerkungen enthalten, die nicht als Anlageberatung gedacht sind und nicht als solche ausgelegt werden dürfen. Suchen Sie Beratung von einem separaten Finanzberater. Die Rakuten Securities HK und die Rakuten Group haften nicht für Fehler, Ungenauigkeiten oder Auslassungen, die die Richtigkeit, Vollständigkeit der Informationen, Texte, Grafiken, Links oder sonstigen in diesen Materialien enthaltenen Informationen nicht garantieren. Lesen und verstehen Sie die Allgemeinen Geschäftsbedingungen auf der Website von Rakuten Securities HKs, bevor Sie weitere Maßnahmen ergreifen. Informationssicherheit im Internet: Um Ihre Privatsphäre zu schützen, greifen Sie nicht auf Ihr Handelskonto über öffentlichen oder gemeinsam genutzten Computer zu oder speichern Ihr Passwort lokal auf einem beliebigen Computer oder Mobilgerät nach dem Anmelden. Rakuten Securities HK wird Sie niemals bitten, Ihre persönlichen Daten zu senden Wie Kontonummer und Passwort an uns direkt per E-Mail. () Unternehmensregistrierungs-ID (in Japan): Kanto Local Finance Bureau (Finanzinstrumente-Unternehmen) No.195 Copyright-Kopie 2017 Rakuten Securities Hong Kong Limited. Alle Rechte vorbehalten.


Wednesday 26 April 2017

Instaforex Trading Plattform Für Android

Gruppen: Repräsentative Beiträge: 1.204 Registriert: 9-9. Juni ab: Russland Mitglied No. 5 Insta Forex internationalen Broker ist glücklich ihren Kunden und Partnern eine mobile Version von InstaTrader Plattform für eine solche Software wie Blackberry, Android Web zu präsentieren. Nun, da Insta Forex Unternehmen diese Neuheit eingeführt hat, kann seinen Kunden genießen anpassungsHandel auf dem Forex ihre mobilen devices33 Technologie Innovationen verwenden, sind eine der Prioritäten von Insta Forex Unternehmensentwicklung: es immer die höchsten Anforderungen seiner Kunden gerecht zu werden sucht. InstaTrader mobile Handelsplattform entwickelt, um die Bedingungen für die Arbeit auf Forex noch bequemer machen ist eine weitere Neuheit von Insta Forex Spezialisten erstellt. Das mobile Handelsendgerät hat fast die gleichen Funktionen wie seine computerbasierte Version. Es eröffnet neue Möglichkeiten für Devisenhändler. Insbesondere ermöglicht sie die Abwicklung von Angeboten, die auf den wichtigsten Währungspaaren, Querzinssätzen, globalen Aktienindizes und der Durchführung technischer Analysen erfolgen. Mit der Hilfe der extrem klaren InstaTrader-Schnittstelle kann man ausstehende Aufträge festlegen Instant Execution Instant-Technologie sorgt für hohe Geschwindigkeit der Geschäfte Ausführung. Sie können nur InstaTrader Plattform für Blackberry-Smartphones, Android-Betriebssystem und Web-Plattform von der offiziellen Website von Insta Forex internationalen Broker InstaForex herunterladen. InstaForex: Schritt halten mit time33 Grüße, offizielle representativePlatform Handels Dengan Multiterminal undeinem dapat bekerja dengan beberapa akun Handel di InstaForex di saat Yang Sama, dengan mengelolanya dalam satu Terminal. Multiterminal merupakan instrumen Handel Yang ideal untuk para Händler Yang melakukan investasi dan Handel di akun Klien Mereka. (Account Management) Plattform Handel dijalankan di MS Windows OS. Klien InstaForex bisa mendownload plattform InstaForex MobileTrader kostenlos runterladen. Setelah aplikasi terinstal, und ein memperoleh akses langsung ke pengelolaan akun. Unda bisa Handel mata ueinn, CFD peinl logeinm, komoditeinls, seeinm, dan menganeinlleis dan mereinrzun grafik. Aplikasi ini Mitgliedschaft fasilitas Handel yang dikembangkan. Alat serba guna secara khusus didesäne bagi klien InstaForex untuk Membran Handel mereka sangat nyaman. Gunakan kemampuan Teknik - Instal InstaForex Mobile für Android Jika undeinem memiliki ponsel Apfel, undeinem bisa mendownload InstaForex Mobile Pada iPhone atau iPad undeinem. Setelah menginstalnya, unda bisa menutup transaksi, menganalisa kutipan, dan menguji strategi Handel. Dalam kisaran Yang mudah dijangkau Dari instrumen standar Yang Lengkap untuk kenyamanan kerja ada dalam genggaman undeinem. Handel tidak pernah semudah als sefleksibel ini. Herunterladen versi terbaru dari InstaForex MobileTrader dengan gratis. Nikmati handelnden yang nyaman dengan antarmuka yang rama pengguna dan software dari versi seluler. Platform InstaForex Mobile kesempatan besar untuk mencapai tujuan Multiterminal (tidak mendukung dengan Mac OS) Dengan Multiterminal undeinem dapat bekerja dengan beberapa akun Handel di InstaForex di saat Yang Sama, dengan mengelolanya dalam satu Terminal. Multiterminal merupakan instrumen Handel Yang ideal untuk para Händler Yang melakukan investasi dan Handel di akun Klien Mereka. (Account Management) Plattform Handel dijalankan di MS Windows OS. Versi mobile


Schreiben Forex Expert Berater

MetaTrader 5 - Trading Systems Schritt für Schritt Anleitung zum Schreiben eines Expert Advisors in MQL5 für Anfänger Einführung Dieser Artikel richtet sich an Anfänger, die lernen möchten, wie man einfache Expertenberater in der neuen MQL5-Sprache schreiben kann. Wir beginnen zunächst mit der Definition, was wir wollen, dass unsere EA (Expert Advisor) zu tun, und dann auf, wie wir wollen, dass die EA zu tun. 1. Handelsstrategie Was unsere EA tun wird: Sie überwacht einen bestimmten Indikator, und wenn eine bestimmte Bedingung erfüllt ist (oder bestimmte Bedingungen erfüllt sind), wird sie je nach dem gegenwärtigen Zustand einen Handel (entweder ShortSell oder LongBuy) platzieren Erfüllt ist. Dies wird als Handelsstrategie bezeichnet. Bevor Sie eine EA schreiben können, müssen Sie zuerst die Strategie entwickeln, die Sie in die EA automatisieren möchten. In diesem Fall ändern wir die obige Aussage so, dass sie die Strategie widerspiegelt, die wir zu einer EA entwickeln wollen. Wir verwenden einen Indikator namens Moving Average mit einem Zeitraum von 8 (Sie können jede Periode wählen, aber für die Zwecke unserer Strategie werden wir 8) Wir wollen, dass unsere EA einen Long (Buy) Handel platziert, wenn die Moving Average - 8 (um der Diskussion willen, werde ich es als MA-8 bezeichnen) steigt nach oben und der Preis ist dicht darüber und es wird ein Short (Sell) platzieren, wenn MA-8 nach unten abnimmt und der Preis nahe ist darunter. Wir werden auch einen anderen Indikator namens Average Directional Movement (ADX) mit der Periode 8 verwenden, um auch zu bestimmen, ob sich der Markt tendiert oder nicht. Wir tun dies, weil wir wollen nur den Handel geben, wenn der Markt ist Trends und entspannen, wenn der Markt reicht (das heißt, nicht Trending). Um dies zu erreichen, werden wir nur unser Geschäft (Kauf oder Verkauf) platzieren, wenn die oben genannten Bedingungen erfüllt sind und der ADX-Wert größer ist als 22. Wenn ADX größer als 22 ist, aber abnimmt oder ADX kleiner als 22 ist, Obwohl die Bedingung B erfüllt ist. Wir wollen uns auch schützen, indem wir einen Stop-Verlust von 30 Pips setzen und für unser Profit-Ziel einen Gewinn von 100 Pips anstreben. Wir wollen auch, dass unsere EA BuySell-Chancen nur dann durchsuchen wird, wenn eine neue Bar gebildet wurde, und wir werden auch sicherstellen, dass wir eine Buy-Position eröffnen, wenn die Buy-Bedingungen erfüllt sind und wir noch nicht geöffnet haben und eine Sell-Position eröffnen Die Verkaufsbedingungen sind erfüllt und wir haben nicht bereits eine eröffnet. Wir haben nun unsere Strategie entwickelt, jetzt ist es an der Zeit, unseren Code zu schreiben. 2. Schreiben eines Expertenberaters Beginnen Sie mit dem Starten des MetaQuotes Language Editor 5. Drücken Sie dann Strg oder klicken Sie auf die Schaltfläche Neu in der Menüleiste. Abbildung 1. Starten eines neuen MQL5-Dokuments Wählen Sie im MQL5-Assistenten den Expertenratgeber aus und klicken Sie auf Weiter Gezeigt in Fig. 2: Abbildung 2. Programmtyp wählen Im nächsten Fenster geben Sie den Namen ein, den Sie Ihrer EA im Feld Name geben möchten. In diesem Fall habe ich MyFirstEA eingegeben. Sie können dann Ihren Namen in das Autor-Feld und auch Ihre Website-Adresse oder E-Mail-Adresse in das Feld Link (falls vorhanden) eingeben. Abbildung 3. Allgemeine Eigenschaften des Expertenberaters Da wir einige Parameter für unsere EA ändern können, um zu sehen, welche der Werte das beste Ergebnis liefern können, werden wir sie durch Klicken auf die Schaltfläche Hinzufügen hinzufügen. Abbildung 4. Einstellen der EA-Eingangsparameter In unserem EA wollen wir mit unseren Einstellungen für Stop Loss, Take Profit, ADX Period und Moving Average Period experimentieren, so dass wir sie an dieser Stelle definieren werden. Doppelklicken Sie unterhalb des Namensbereichs und geben Sie den Namen des Parameters ein, und klicken Sie dann unter dem Typ, um den Datentyp für den Parameter auszuwählen, und doppelklicken Sie unter dem Abschnitt Anfangswert und geben Sie den Anfangswert für den Parameter ein. Sobald Sie fertig sind, sollte es so aussehen: Abbildung 5. Datentypen der EA-Eingabeparameter Wie Sie oben sehen können, habe ich für alle Parameter den Integer-Datentyp (int) ausgewählt. Lassen Sie uns sprechen ein wenig über Datentypen. Char: Der char-Typ benötigt 1 Byte Speicher (8 Bits) und erlaubt das Ausdrücken in den binären Notation-28256-Werten. Der char-Typ kann sowohl positive als auch negative Werte enthalten. Der Wertebereich reicht von -128 bis 127. uchar: Der uchar-Integer-Typ belegt ebenfalls 1 Byte Speicher, sowie den char-Typ, aber im Gegensatz zu uchar ist nur für positive Werte gedacht. Der minimale Wert ist null, der maximale Wert 255. Der erste Buchstabe u im Namen des uchar-Typs ist die Abkürzung für unsigned. Kurz: Die Größe des kurzen Typs beträgt 2 Bytes (16 Bits) und dementsprechend erlaubt es den Wertebereich gleich 2 zu der Leistung 16: 216 65 536. Da der kurze Typ ein Vorzeichen eins ist und beide enthält Positiven und negativen Werten liegt der Wertebereich zwischen -32 768 und 32 767. ushort: Der Typ unsigned short ist der Typ ushort. Die ebenfalls eine Größe von 2 Bytes aufweist. Der minimale Wert ist 0, der maximale Wert ist 65 535. int: Die Größe des int-Typs beträgt 4 Bytes (32 Bits). Der minimale Wert ist -2 147 483 648, der maximale Wert ist 2 147 483 647. uint: Der unsignierte Integer-Typ ist uint. Es dauert 4 Byte Speicher und erlaubt das Ausdrücken von ganzen Zahlen von 0 bis 4 294 967 295. long: Die Größe des langen Typs beträgt 8 Byte (64 Bit). Der minimale Wert ist -9 223 372 036 854 775 808, der maximale Wert ist 9 223 372 036 854 775 807. ulong: Der ulong-Typ belegt auch 8 Bytes und kann Werte von 0 bis 18 446 744 073 709 551 615 speichern In der obigen Beschreibung der verschiedenen Datentypen sind die nicht-signierten Ganzzahlentypen nicht zum Speichern negativer Werte ausgelegt, jeder Versuch, einen negativen Wert einzustellen, kann zu unerwarteten Konsequenzen führen. Wenn Sie zum Beispiel negative Werte speichern möchten, können Sie sie nicht innerhalb der nicht signierten Typen (z. B. uchar, uint, ushort, ulong) speichern. Zurück zu unserem EA. Wenn Sie sich die Datentypen anschauen, werden Sie mir zustimmen, dass wir die Datentypen char oder uchar verwenden müssen, da die Daten, die wir in diesen Parametern speichern wollen, weniger als 127 oder 255 betragen. Für eine gute Speicherverwaltung ist dies das beste, was zu tun ist. Jedoch für die Diskussion, wir bleiben immer noch auf den int-Typ. Wenn Sie alle notwendigen Parameter gesetzt haben, klicken Sie auf die Schaltfläche Fertig, und der MetaQuotes Editor erstellt das Skelett des Codes für Sie, wie in der nächsten Abbildung dargestellt. Lässt brechen den Code in die verschiedenen Abschnitte für ein besseres Verständnis. Der obere Teil (Header) des Codes ist, wo die Eigenschaft der EA definiert ist. Sie können sehen, dass hier die Werte sind, die Sie im MQL5-Assistenten in Abbildung 3 ausgefüllt haben. In diesem Abschnitt des Codes können Sie zusätzliche Parameter wie Beschreibung (kurze Textbeschreibung des EA) definieren, Konstanten deklarieren, zusätzliche Dateien oder Importfunktionen einfügen . Wenn eine Anweisung mit einem Symbol beginnt, heißt sie eine Präprozessor-Direktive und endet nicht mit einem Semikolon. Ein anderes Beispiel für Präprozessor-Direktiven beinhaltet: Die Definitionsrichtlinie wird für eine Deklaration von Konstanten verwendet. Es wird in der Form define identifier tokenstring geschrieben. Dies bedeutet, dass jedes Vorkommen von Bezeichner in Ihrem Code durch den Wert tokenstring ersetzt wird. Definieren ABC 100 definieren COMPANYNAME MetaQuotes Software Corp. Es wird jedes Vorkommen von COMPANYNAME durch den String MetaQuotes Software Corp. ersetzen oder es wird jedes Vorkommen von ABC durch die char (oder integer) 100 in Ihrem Code ersetzen. Weitere Informationen zu den Präprozessor-Direktiven finden Sie im MQL5-Handbuch. Lassen Sie uns jetzt mit unserer Diskussion weiter. Der zweite Teil des Headers unseres Codes ist der Eingabeparameterabschnitt: Wir geben alle Parameter an, die in unserem EA in diesem Abschnitt verwendet werden. Dazu gehören alle Variablen, die von allen Funktionen, die wir in unserem EA schreiben werden, verwendet werden. Variablen, die auf dieser Ebene deklariert werden, heißen Globale Variablen, da sie auf jede Funktion in unserem EA zugreifen können, die sie benötigen. Die Eingabeparameter sind Parameter, die nur außerhalb unserer EA geändert werden können. Wir können auch andere Variablen deklarieren, die wir im Rahmen unserer EA manipulieren werden, aber außerhalb unseres EA in diesem Abschnitt nicht verfügbar sein werden. Als nächstes ist die EA-Initialisierungsfunktion. Dies ist die erste Funktion, die aufgerufen wird, wenn das EA gestartet oder an ein Diagramm angehängt wird, und es wird nur einmal aufgerufen. Dieser Abschnitt ist der beste Ort, um einige wichtige Kontrollen zu machen, um sicherzustellen, dass unsere EA funktioniert sehr gut. Wir können entscheiden, ob die Karte genügend Stäbe für unsere EA hat, etc. usw. Es ist auch der beste Platz, um die Griffe zu erhalten, die wir für unsere Indikatoren (ADX und Moving Average Indikatoren) verwenden werden. Für unsere EA, werden wir die Griffe für unsere Indicators während der Initialisierung in diesem Abschnitt erstellt. Diese Funktion verarbeitet das NewTick-Ereignis. Die erzeugt wird, wenn ein neues Angebot für ein Symbol empfangen wird. Beachten Sie, dass Expert Advisor keine Handelsoperationen durchführen kann, wenn die Verwendung von Expertenberatern im Client-Terminal nicht zulässig ist (Button Auto Trading). Abbildung 6. Autotrading ist aktiviert Die meisten unserer Codes, die unsere bisherige Strategie implementieren, werden in diesem Abschnitt beschrieben. Nun, da wir die verschiedenen Abschnitte des Codes für unsere EA betrachtet haben, beginnen wir mit dem Hinzufügen von Fleisch zum Skelett. 2.2 EINGANGSPARAMETER ABSCHNITT Wie Sie sehen können, haben wir weitere Parameter hinzugefügt. Bevor wir fortfahren, die neuen Parameter zu diskutieren, lassen Sie uns etwas besprechen, das Sie jetzt sehen können. Die beiden Schrägstriche erlauben es uns, Kommentare in unsere Codes zu schreiben. Mit Kommentaren, können wir wissen, was unsere Variablen stehen, oder was wir tun, zu diesem Zeitpunkt in unserem Code. Es gibt auch ein besseres Verständnis unseres Codes. Es gibt zwei grundlegende Möglichkeiten, Kommentare zu schreiben: Dies ist ein einzeiliger Kommentar Dies ist ein mehrzeiliger Kommentar Dies ist ein mehrzeiliger Kommentar. Mehrzeilige Kommentare beginnen mit dem Paar von Symbolen und enden mit dem einen. Der Compiler ignoriert alle Kommentare beim Kompilieren des Codes. Die Verwendung von Einzelzeilenkommentaren für die Eingabeparameter ist eine gute Möglichkeit, unsere EA-Benutzer zu verstehen, was diese Parameter darstellen. Bei den EA-Input-Eigenschaften sehen unsere Benutzer den Parameter selbst nicht, stattdessen sehen sie die Kommentare wie unten gezeigt: Abbildung 7. Eingabeparameter von Expert Advisor Jetzt haben wir beschlossen, weitere Parameter für unsere EA hinzuzufügen. Die EAMagic ist die Magic-Nummer für alle Bestellungen unserer EA. Der minimale ADX-Wert (AdxMin) wird als doppelter Datentyp deklariert. Ein Doppel wird verwendet, um Gleitkommakonstanten zu speichern, die einen ganzzahligen Teil, einen Dezimalpunkt und einen Bruchteil enthalten. Double mysum 123.5678 double b7 0.09876 Das Lot zu handeln (Lot) steht für das Volumen des Finanzinstruments, das wir handeln möchten. Dann haben wir andere Parameter, die wir verwenden werden, deklariert: Der AdxHandle dient zur Speicherung des ADX-Indikatorhandles, während der MaHandle den Handle für das Moving Average-Kennzeichen speichert. Die plsDI, minDI, adxVal sind dynamische Arrays, die die Werte von DI, - DI und Haupt-ADX (der ADX-Anzeige) für jede Tabelle im Diagramm enthalten. Das maVal ist ein dynamisches Array, das die Werte des Moving Average-Indikators für jeden Balken im Diagramm enthält. By the way, was sind dynamische Arrays Ein dynamisches Array ist ein Array ohne Dimension deklariert. Mit anderen Worten, in dem Paar eckiger Klammern wird kein Wert angegeben. Ein statisches Array, auf der anderen Seite hat seine Dimensionen am Deklarationspunkt definiert. Double allbars 20 dies wird 20 Elemente nehmen pclose ist eine Variable, die wir verwenden, um die Close-Preis für die Bar, die wir für die Überprüfung unserer BuySell-Trades zu überwachen. STP und TKP werden verwendet, um die Stop Loss und die Take Profit Werte in unserem EA zu speichern. 2.3. EA INTIALISIERUNGSABSCHLUSS Hier erhalten wir die Griffe unserer Anzeige mit den jeweiligen Anzeigefunktionen. Der ADX-Indikatorhandgriff wird mit der iADX-Funktion erhalten. Das Chart-Symbol (NULL bedeutet auch das aktuelle Symbol im aktuellen Chart), das Chart-Periodimeframe (0 bedeutet auch den aktuellen Zeitrahmen im aktuellen Chart), die ADX-Mittelungsperiode für die Berechnung des Index (die wir zuvor unter Eingabeparametern definiert haben) Abschnitt) als Parameter oder Argumente. Int iADX (String-Symbol, Symbolname ENUMTIMEFRAMES-Periode, Periode int Adxperiod-Mittelungsperiode) Das Indikatorhandle für Moving Average wird mit der iMA-Funktion erhalten. Es hat die folgenden Argumente: das Diagramm-Symbol (das mit Symbol Symbol () oder NULL für das aktuelle Symbol auf dem aktuellen Diagramm erhalten werden kann), das Diagramm Periodenzeitrahmen (die mit Periodenperiode () oder 0 für erhalten werden können Der aktuelle Zeitrahmen des aktuellen Diagramms), die Durchschnittsdurchschnittszeit des Moving Average (die wir zuvor unter dem Abschnitt Inputparameter definiert haben), die Verschiebung des Indikators relativ zum Preisdiagramm (Verschiebung hier 0), der Moving Average Glättungstyp (könnte Einer der folgenden Mittelungsmethoden: Simple Averaging-MODESMA, Exponential-Mittelwertbildung-MODEEMA, Smoothed Averaging-MODESMMA oder Linear-Weighted Averaging-MODELWMA) und der Preis für die Mittelung (hier verwenden wir den engen Preis). Int iMA (Zeichenkettensymbol Symbolname ENUMTIMEFRAMES Periodendauer int maperiod Durchschnittsperiode int mashift Horizontale Verschiebung ENUMMAMETHOD mamethod Glättungstyp ENUMAPPLIEDPRICE angewandter Preis Art des Preises oder Griffs) Lesen Sie bitte das MQL5-Handbuch, um weitere Details zu diesen Indikatorfunktionen zu erhalten. Es wird Ihnen ein besseres Verständnis der Verwendung jeder Indikator. Wir versuchen erneut, für alle Fehler zu überprüfen, falls die Funktion den Griff nicht erfolgreich zurückgegeben hat, erhalten wir einen INVALIDHANDLE-Fehler. Wir verwenden die Alert-Funktion, um den Fehler mit der GetlastError-Funktion anzuzeigen. Wir entscheiden, den Stop Loss und die Take Profit Werte in den Variablen STP und TKP zu speichern, die wir früher deklariert haben. Warum tun wir dies, weil die in den INPUT-Parametern gespeicherten Werte schreibgeschützt sind, können sie nicht geändert werden. Also hier wollen wir sicherstellen, dass unsere EA funktioniert sehr gut mit allen Brokern. Ziffern oder Ziffern () r stellt die Anzahl der Dezimalstellen fest, die die Genauigkeit des Preises des aktuellen Kartensymbols bestimmen. Für eine 5-stellige oder dreistellige Preistabelle multiplizieren wir sowohl den Stop Loss als auch den Take Profit mit 10. 2.4. EA DEINTIALIZATION SECTION Da diese Funktion aufgerufen wird, wenn die EA deaktiviert oder aus einem Diagramm entfernt wird, geben wir alle Indikatoren frei, die während des Initialisierungsprozesses erzeugt wurden. Wir haben zwei Griffe, einen für ADX-Indikator und einen anderen Griff für den Moving Average-Indikator, erstellt. Wir verwenden die Funktion IndicatorRelease (), um dies zu erreichen. Es dauert nur ein Argument (das Indikator-Handle) bool IndicatorRelease (int Indikatorhandle. Indikatorhandle) Die Funktion entfernt einen Indikatorgriff und gibt den Berechnungsblock des Indikators frei, falls dieser nicht verwendet wurde. 2.5 Der EA-ONTICK-Abschnitt Das erste, was wir hier tun müssen, ist zu prüfen, ob wir genügend Balken auf dem vorliegenden Diagramm haben. Wir können die gesamten Balken im Verlauf eines Diagramms mit der Balkenfunktion erhalten. Es gibt zwei Parameter, das Symbol (erhalten Sie mit Symbol oder Symbol (). Diese beiden geben das aktuelle Symbol für das aktuelle Diagramm, auf dem unsere EA angefügt ist) und den Zeitraum oder Zeitrahmen des vorliegenden Charts Oder Periode () Diese beiden geben den Zeitrahmen des aktuellen Diagramms zurück, auf dem die EA angefügt ist). Wenn die insgesamt verfügbaren Stäbe kleiner als 60 sind, möchten wir, dass unsere EA sich entspannt, bis wir genügend Stäbe im Diagramm haben. Die Alert-Funktion zeigt eine Meldung in einem separaten Fenster an. Es werden alle Werte durch Kommas als Parameterargumente getrennt. In diesem Fall haben wir nur einen String-Wert. Die Rückkehr beendet die Initialisierung unserer EA. Der Expert Advisor führt den Handel zu Beginn einer neuen Bar durch, so dass es notwendig ist, um das Problem mit der neuen Balkenidentifikation zu lösen. Mit den Worten, wir wollen sicher sein, dass unsere EA nicht auf LongShort-Setups bei jedem Tick prüfen, wir wollen nur, dass unser EA nach LongShort-Positionen sucht, wenn es eine neue Leiste gibt. Wir beginnen mit der Deklaration einer statischen datetime Variable OldTime. Die die Bar-Zeit speichern wird. Wir haben es als statisch deklariert, weil wir wollen, dass der Wert im Speicher bis zum nächsten Aufruf der OnTick-Funktion beibehalten wird. Dann können wir den Wert mit der NewTime-Variablen (auch vom Datetime-Datentyp) vergleichen, bei der es sich um ein Array eines Elements handelt, das die neue (aktuelle) Balkenzeit enthält. Wir haben auch eine Bool-Datentyp-Variable IsNewBar deklariert und ihren Wert auf false gesetzt. Dies ist, weil wir wollen, dass ihr Wert nur dann wahr ist, wenn wir eine neue Leiste haben. Wir verwenden die CopyTime-Funktion, um die Zeit des aktuellen Balkens zu erhalten. Es kopiert die Balkenzeit zum Array NewTime mit einem Element, wenn es erfolgreich ist, vergleichen wir die Zeit einer neuen Balken mit der vorherigen Balkenzeit. Wenn die Zeit arent gleich ist, bedeutet dies, dass wir eine neue Leiste haben, und wir setzen die Variable IsNewBar auf TRUE und speichern den Wert der aktuellen Barzeit auf die Variable OldTime. Die Variable IsNewBar zeigt an, dass wir eine neue Leiste haben. Wenn es FALSE ist, beenden wir die Ausführung der OnTick-Funktion. Werfen Sie einen Blick auf den Code, den es prüft für die Debug-Modus-Ausführung, wird es die Meldung über die Bar mal, wenn Debug-Modus, werden wir prüfen, es weiter zu drucken. Das nächste, was wir hier tun wollen, ist zu überprüfen, ob wir genug Bars haben, um mit zu arbeiten. Warum wiederholen Sie es Wir wollen nur sicher sein, dass unsere EA richtig funktioniert. Es sollte beachtet werden, dass die OnTick-Funktion bei jedem neuen Tick (Preisangebot) aufgerufen wird, während die OnInit-Funktion nur einmal aufgerufen wird, wenn die EA an ein Diagramm angehängt wird. Sie bemerken, daß wir es hier wieder anders gemacht haben. Wir beschließen, die gesamten Balken in der Geschichte zu speichern, die wir aus dem Ausdruck in einer neuen Variablen, Mybars, erhalten haben. Innerhalb der OnTick-Funktion deklariert. Diese Variablentyp ist eine lokale Variable, im Gegensatz zu der Variablen, die wir im Abschnitt INPUT PARAMETERS deklariert haben. Während die Variablen, die im Abschnitt "Eingangsparameter" unseres Codes deklariert sind, für alle Funktionen verfügbar sind, sind in unserem Code, der sie benötigt, Variablen, die innerhalb einer einzigen Funktion deklariert sind, begrenzt und nur für diese Funktion verfügbar. Es kann nicht außerhalb dieser Funktion verwendet werden. Als Nächstes deklarierten wir einige Variablen von MQL5-Strukturtypen, die in diesem Abschnitt unserer EA verwendet werden. MQL5 hat eine ganze Reihe von Strukturen, die Dinge ziemlich einfach für EA-Entwickler macht. Nehmen wir die Strukturen nacheinander. Dies ist eine Struktur für die Speicherung der neuesten Preise von Symbolen verwendet. Struct MqlTick datetime time Zeit der letzten Preisaktualisierung double bid Aktueller Gebotspreis double ask Aktueller Preis doppelter letzter Preis letzter Kauf (letzter) ulong Volumen Volumen für den aktuellen Letzter Preis Jede Variable, die vom MqlTick-Typ deklariert wird, kann leicht sein Um die aktuellen Werte von Ask, Bid, Last und Volume zu erhalten, sobald Sie die Funktion SymbolInfoTick () aufrufen. Also haben wir den letzten Preis als MqlTick-Typ deklariert, damit wir ihn nutzen können, um die Ask - und Bid-Preise zu erhalten. Diese Struktur wird verwendet, um alle Handelsaufträge für eine Handelsoperation durchzuführen. Es enthält in seiner Struktur alle Felder, die für die Durchführung eines Handelsabkommens notwendig sind. Struct MqlTradeRequest ENUMTRADEREQUESTACTIONS Aktion Handelsbetriebsart ulong Magie Expert Advisor ID (Magic Number) ulong Order Bestellen Sie Ticket String Symbol Trade Symbol Doppelvolumen Angefordertes Volumen für einen Deal in vielen doppelten Preis Preis double stoplimit StopLimit Ebene der Bestellung double sl Stop Loss Ebene der Order double tp Take Profit Level des Auftrags ulong Abweichung Maximal mögliche Abweichung vom angeforderten Preis ENUMORDERTYPE Typ Auftragsart ENUMORDERTYPEFILLING Typfilling Auftragsausführungstyp ENUMORDERTYPETIME typetime Auftragsdurchlaufzeit datetime Verfall Auftragsablaufzeit (für die Aufträge des ORDERTIMESPECIFIED-Typs) string comment Bestellkommentar Any Variable, die für den MqlTradeRequest-Typ deklariert ist, kann verwendet werden, um Aufträge für unsere Handelsoperationen zu senden. Hier haben wir MQ als MqlTradeRequest-Typ deklariert. Das Ergebnis einer Handelsoperation wird als eine spezielle vordefinierte Struktur von MqlTradeResult zurückgegeben. Jede Variable, die als MqlTradeResult-Typ deklariert ist, kann auf die Ergebnisse der Handelsanforderungen zugreifen. Struct MqlTradeResult uint retcode Operation Rückgabecode ulong deal Deal Ticket, wenn es ulong Auftrag ausgeführt wird Bestellen Sie das Ticket, wenn es doppeltes Volumen aufgelegt wird Deal Volumen, bestätigt durch Broker Doppelpreis Deal Preis, bestätigt durch Broker doppeltes Gebot Aktuelle Gebotspreis double ask Aktuelle Fragen Der Preis (Öffnen, Schließen, Hoch, Niedrig), die Zeit, die Volumina der einzelnen Balken und die Spreizung für ein Symbol werden in dieser Struktur gespeichert. Jedes Array, das deklariert wurde, um vom Typ MqlRates zu sein, kann verwendet werden, um den Preis, die Volumes und den Verlauf für ein Symbol zu speichern. Struct MqlRates datetime time Period start time double open Open Preis double high Der höchste Kurs der Periode double low Der niedrigste Kurs der Periode double schließen Close price long tickvolume Tick volume int spread Spread long realvolume Handelsvolumen Hier haben wir ein Array mrate deklariert Wird verwendet, um diese Informationen zu speichern. Als nächstes entscheiden wir, alle Arrays, die wir verwenden, um Bars Details als Serie zu speichern. Damit wird sichergestellt, dass die Werte, die in die Arrays kopiert werden, wie die Zeitreihen indexiert werden, dh, 0, 1, 2, 3 (entsprechend dem Balkenindex), so dass wir die ArraySetAsSeries () - Funktion verwenden ArraySetAsSeries (void-Array-Array nach Referenz-Bool-Set true bedeutet umgekehrte Reihenfolge der Indizierung) Es sei darauf hingewiesen, dass dies auch einmal in der Initialisierung Abschnitt unseres Codes getan werden kann. Allerdings habe ich beschlossen, es an dieser Stelle um der Sache willen Diese Funktion benötigt zwei Argumente Chart-Symbol und die MqlTick-Struktur-Variable (lastprice ).Wenn es einen Fehler gibt, berichteten wir es. Weiter haben wir die Informationen über kopiert Die neuesten drei Balken in unserem Mqlrates-Array mit der Copy-Funktion. Die Copyounts-Funktion wird verwendet, um die History-Daten der MqlRates-Struktur einer bestimmten Symbol-Periode in einer bestimmten Menge in ein Array des MqlRates-Typs zu erhalten. Symbolname ENUMTIMEFRAMES Zeitrahmen. Zeitraum int startpos. Startposition int zählen. Daten zählen zu kopieren MqlRates Ratesarray Ziel-Array zu kopieren) Der Symbolname wird durch das Symbol erhalten. Wird der aktuelle Periodenzeitraum unter Verwendung einer Periode erhalten. Für die Startposition starten wir von der aktuellen Bar, Bar 0, und wir zählen nur drei Bars, Bars 0, 1 und 2. Das Ergebnis wird gespeichert werden in unserem Array, mrate. Das mrate-Array enthält nun alle Preis-, Zeit-, Volumen - und Spread-Informationen für die Balken 0. 1 und 2. Damit wir die Details der Balken erhalten, verwenden wir folgendes: Wir können beispielsweise die folgenden Informationen über die einzelnen Balken haben : Mrate1.time Bar 1 Startzeit mrate1.open Bar 1 Offener Preis mrate0.high Bar 0 (aktueller Bar) hoher Preis usw Als nächstes haben wir alle Indikatorwerte in die dynamischen Arrays kopiert, die wir mit der CopyBuffer-Funktion deklariert haben. Int CopyBuffer (int Indikatorhandle, Indikatorgrenze int buffernum, Indikatorpufferzahl int startpos, Startposition int count, Betrag zum Kopieren des Doppelpufferzielfeldes zum Kopieren) Das Indikatorhandle ist das Handle, das wir im OnInit-Bereich erstellt haben. Bei Puffernummern hat der ADX-Indikator drei (3) Puffer: Der Moving Average-Indikator hat nur einen (1) Puffer: Wir kopieren aus dem aktuellen Balken (0) in die letzten zwei Balken. Die Anzahl der zu kopierenden Datensätze beträgt 3 (Balken 0, 1 und 2). Der Puffer sind die dynamischen Zielsysteme, die wir früher als adxVal, plsDI, minDI und maVal bezeichnet hatten. Wie Sie hier noch einmal sehen können, versuchen wir, alle Fehler zu erfassen, die beim Kopieren auftreten können. Wenn es Fehler, keine Notwendigkeit, weiter zu gehen. Es ist wichtig anzumerken, dass die CopyBuffer () - und die CopyRates () - Funktion die Gesamtzahl der beim Erfolg kopierten Datensätze zurückgibt, während sie -1 Incase eines Fehlers zurückgibt. Deshalb suchen wir in den Fehlerüberprüfungsfunktionen nach einem Wert kleiner 0 (Null). An dieser Stelle möchten wir überprüfen, ob wir bereits eine Kauf - oder Verkaufsposition eröffnet haben, in der Reihenfolge der Wörter, wir wollen sicherstellen, dass wir nur ONE Sell oder Buy Handel zu einem Zeitpunkt geöffnet haben. Wir wollen keinen neuen Kauf eröffnen, wenn wir bereits einen haben, und wir wollen keinen neuen Verkauf eröffnen, wenn wir bereits einen geöffnet haben. Um zu erreichen, werden wir zunächst deklarieren zwei Bool-Datentyp-Variablen (Buyopened und Sellopened), die einen WAHREN Wert halten wird, wenn wir bereits eine Position für Kauf oder Verkauf geöffnet haben. Wir verwenden die Handelsfunktion PositionSelect, um zu wissen, ob wir eine offene Position haben. Diese Funktion gibt TRUE zurück, wenn wir bereits eine Position haben und FALSE wenn wir keine haben. Es wird als das Hauptargumentparameter, das Symbol (Währungspaar), das wir überprüfen wollen. Hier verwenden wir das Symbol, weil wir das aktuelle Symbol (Währungspaar) überprüfen. Wenn dieser Ausdruck TRUE zurückgibt, wollen wir überprüfen, ob die geöffnete Position ein Buy oder ein Sell ist. Dazu verwenden wir die Funktion "PositionGetInteger". Es gibt uns die Art der Position geöffnet, wenn wir sie mit dem POSITIONTYPE-Modifikator verwenden. Sie gibt die Positionstypkennung zurück, die entweder POSITIONTYPEBUY oder POSITIONTYPESELL sein kann. In unserem Fall haben wir sie verwendet, um festzustellen, welche Position wir bereits geöffnet haben. Wenn es ein Verkauf ist, speichern wir einen WAHREN Wert in Sellopened und wenn es ein Kauf ist, speichern wir einen WAHREN Wert in Buyopened. Wir werden diese beiden Variablen später verwenden können, wenn wir nach Selling oder Buy Bedingungen später in unserem Code suchen. Es ist jetzt Zeit, den engen Preis für die Bar zu speichern, die wir für unser BuySell-Setup verwenden werden. Denken Sie daran, dass wir für diese Variable eine Variable deklariert haben. Wir werden nun mit dem nächsten Schritt fortfahren. Es ist nun Zeit, nach einer Kaufgelegenheit zu suchen. Lassen Sie uns analysieren den Ausdruck oben, wie es die Strategie, die wir früher entworfen. Wir erklären eine Bool-Typ-Variable für jede unserer Bedingungen, die erfüllt sein müssen, bevor ein Auftrag platziert werden kann. Eine Variable vom Typ bool kann nur TRUE oder FALSE enthalten. So wurde unsere Kaufstrategie in vier Konditionen aufgeteilt. Wenn eine der Bedingungen erfüllt oder erfüllt ist, wird ein Wert von TRUE in unserer Variablen vom Typ bool gespeichert, andernfalls wird ein Wert von FALSE gespeichert. Betrachten wir sie nacheinander. Hier sehen wir die MA-8 Werte auf Balken 0, 1 und 2. Wenn der Wert von MA-8 auf dem aktuellen Balken größer ist als sein Wert auf dem vorherigen Balken 1 und auch der MA-8-Wert auf Balken 1 größer als sein Wert auf Balken 2 ist. Es bedeutet, dass MA-8 nach oben zunimmt. Dies erfüllt eine unserer Bedingungen für eine Buy-Einrichtung. Dieser Ausdruck überprüft, ob Bar 1 Close-Preis höher ist als der Wert von MA-8 im gleichen Zeitraum (Bar 1-Periode). Wenn der Preis höher ist, dann ist unsere zweite Bedingung auch erfüllt worden, dann können wir für andere Bedingungen überprüfen. Wenn jedoch die beiden oben erwähnten Bedingungen nicht erfüllt sind, besteht keine Notwendigkeit, andere Bedingungen zu überprüfen. Deshalb beschließen wir, die nächsten Ausdrücke in diese beiden Anfangsbedingungen (Ausdrücke) aufzunehmen. Jetzt wollen wir überprüfen, ob der aktuelle Wert von ADX (ADX-Wert auf Bar 0) größer ist als der in den Eingabeparametern deklarierte minimale ADX-Wert. Wenn dieser Ausdruck wahr ist, dh der aktuelle Wert von ADX größer als der minimale erforderliche Wert ist, möchten wir auch sicher sein, dass der plusDI-Wert größer als der minusDI-Wert ist. Dies ist, was wir im nächsten Ausdruck erreicht haben Wenn alle diese Bedingungen erfüllt sind, das heißt, wenn sie true zurückgeben, dann wollen wir sicher sein, dass wir keine neue Buy-Position öffnen, wenn wir bereits eine haben. Es ist nun an der Zeit, den Wert der Buyopened-Variablen zu überprüfen, die wir früher in unserem Code angegeben haben. Wenn Buyopened ist, wollen wir nicht eine andere Position zu kaufen, also, wir zeigen eine Warnung, um uns zu informieren und dann zurück, so dass unsere EA wird nun für den nächsten Tick warten. Allerdings, wenn Buyopened FALSE ist, dann bereiten wir unsere Datensätze mit der MqlTradeRequest-Typ-Variable (mrequest), die wir früher für unsere Bestellung zu senden. Die Aktion hier, die Handelsart ist, ist TRADEACTIONDEAL, weil wir eine Trade Order für eine sofortige Ausführung platzieren. Wenn wir einen Auftrag ändern, dann verwenden wir TRADEACTIONMODIFY. Um eine Bestellung zu löschen, verwenden wir TRADEACTIONREMOVE. Wir haben unsere MqlTick Art spätesten Preis zu bekommen die neuesten Ask-Preis. Der Auftrag Stop-Loss-Preis wird durch Subtraktion unserer StopLoss in Punkte aus dem Ask-Preis, während die Bestellung erhalten Profit Preis wird durch das Hinzufügen unseres TakeProfit in Punkte auf den Ask-Preis erhalten. Sie werden auch beobachten, dass wir die NormalizeDouble-Funktion für den Ask-Preis, die StopLoss - und TakeProfit-Werte verwendet haben, ist es eine gute Praxis, diese Preise immer auf die Anzahl der Ziffern des Währungspaares zu normalisieren, bevor Sie sie an den Handelsserver senden. Das Symbol ist das aktuelle Symbol (Symbol oder Symbol ()). Die Auftragsart ist die Art der Bestellung, die wir platzieren, hier legen wir eine Kauforder ORDERTYPEBUY. Für einen Verkaufsauftrag ist es ORDERTYPESELL. Die Orderartfüllung ist die Orderausführung ORDERFILLINGFOK bedeutet, dass der Deal ausschließlich mit einem festgelegten Volumen zum gleichen oder besseren Preis ausgeführt werden kann, als der angegebene Orderpreis. Wenn auf dem Auftragssymbol keine ausreichenden Angebotsmengen vorhanden sind, wird die Bestellung nicht ausgeführt. Die Funktion OrderSend () verwendet zwei Argumente, die Variable MqlTradeRequest und die Variable MqlTradeResult. Wie Sie sehen können, haben wir unsere Variable MqlTradeRequest und die Variable MqlTradeResult verwendet, um unseren Auftrag mit OrderSend zu platzieren. Nachdem wir unsere Bestellung gesendet haben, verwenden wir jetzt die Variable MqlTradeResult, um das Ergebnis unserer Bestellung zu überprüfen. Wenn unsere Bestellung erfolgreich durchgeführt wird, wollen wir informiert werden, und wenn nicht, wollen wir es auch wissen. Mit der Variablen mresult von MqlTradeResult können wir auf den Return-Code der Operation und auch auf die Order-Ticket-Nummer zugreifen, wenn der Auftrag platziert wird. Der Rückkehrcode 10009 zeigt, dass die OrderSend-Anfrage erfolgreich abgeschlossen wurde, während 10008 zeigt, dass unsere Bestellung platziert wurde. Deshalb haben wir für einen dieser beiden Rückgabecodes überprüft. Wenn wir irgendwelche von ihnen haben, sind wir sicher, dass unsere Bestellung abgeschlossen wurde oder es wurde platziert. Um nach einer Verkaufschance zu suchen, prüfen wir das Gegenteil dessen, was wir für Buy Opportunity getan haben, außer für unseren ADX, der größer sein muss als der angegebene Mindestwert. So wie wir es im Buy-Bereich getan haben, deklarieren wir für jede unserer Bedingungen eine Bool-Variable, die erfüllt sein muss, bevor eine Order geleistet werden kann. Eine Variable vom Typ bool kann nur TRUE oder FALSE enthalten. So wurde unsere Verkaufstrategie in vier Bedingungen unterteilt. Wenn eine der Bedingungen erfüllt oder erfüllt ist, wird ein Wert von TRUE in unserer Variablen vom Typ bool gespeichert, andernfalls wird ein Wert von FALSE gespeichert. Sehen wir uns die einzelnen MA-8-Werte an den Bars 0, 1 und 2 an. Wenn der Wert von MA-8 auf dem aktuellen Balken kleiner ist als sein Wert auf dem vorherigen Balken 1 und auch der MA-8 Wert auf Balken 1 kleiner als sein Wert auf Balken 2 ist. Bedeutet dies, dass MA-8 nach unten abnimmt. Dies erfüllt eine unserer Bedingungen für eine Verkaufseinrichtung. This expression is checking to see if Bar 1 Close price is lower than the value of MA-8 at the same period (Bar 1 period). If the price is lower, then our second condition has also been satisfied, then we can check for other conditions. However, if the two conditions we have just considered were not met, then there will be no need to check other conditions. That is why we decide to include the next expressions within these two initial conditions (expressions). Now we want to check if the current value of ADX (ADX value on Bar 0) is greater than the Minimum ADX value declared in the input parameters. If this expression is true, that is, the current value of ADX is greater than the Minimum required value we also want to be sure that the MinusDI value is greater than the plusDI value. This is what we achieved in the next expression If these conditions are met, that is, if they return true, then we want to be sure that we do not open a new Buy position if we already have one. It is now time to check the value of the Buyopened variable we declared earlier in our code. If Sellopened is true, we do not want to open another Sell position, so, we display an alert to inform us and then return so that our EA will now wait for the next Tick. However, if Sellopened is FALSE, then we setup our Sell trade request as we did for Buying order. The major difference here is the way we calculated our stop loss price and take profit price. Also since we are selling, we sell at the Bid price that is why we used our MqlTick type variable latestprice to get the latest bid price. The other type here, as explained earlier, is ORDERTYPESELL. Also here, we used the NormalizeDouble function for the Bid price, the StopLoss and TakeProfit values, it is good practice to always normalize these prices to the number of digits of currency pair before sending it to the trade server. Just as we did for our Buy order, we must also check if our Sell order is successful or not. So we used the same expression as in our Buy order. 3. Debugging and Testing our Expert Advisor At this point, we need to test our EA to know it our strategy works or not. Also, it is possible that there are one or two errors in our EA code. This will be discovered in the next step. Debugging our code helps us to see how our code performs line by line (if we set breakpoints) and there and then we can notice any error or bug in our code and quickly make the necessary corrections before using our code in real trade. Here, we are going to go through the step by step process of debugging our Expert Advisor, first of all, by setting breakpoints and secondly, without breakpoints. To do this, Make sure you have not closed the Editor. First of all, let us select the chart we want to use to test our EA. On the Editor Menu bar, click on Tools and click on Options as shown below: Figure 8. Setting Debugging options Once the Options window appears, select the currency pair, and the periodtimeframe to use and click the OK button: Before we start the debugger, let us set breakpoints. Breakpoints allow us to monitor the behaviorperformance of our code at certain selected locations or lines. Rather than running through all the code at once, the debugger will stop whenever it see a breakpoint, waiting for your net action. By this we will be able to analyze our code and monitor its behavior as it reaches every set break-points. We will also be able to evaluate the values of some of our variables to see if things are actually the way we envisaged. To insert a breakpoint, go to the line in your code where you want to set the breakpoint. By the left hand side, on the gray field near the border of the code line, double-click and you will see a small round blue button with a white square inside it. Or on the alternative, place the cursor of your mouse anywhere on the code line where you want the breakpoint to appear and press F9 . To remove the breakpoint, press F9 again or double-click on it. Figure 10. Setting a breakpoint For our code, we are going to set breakpoint on five different lines. I will also label them form 1 to 5 for the sake of explanation. To continue, set breakpoint at the seven code lines as shown in the figure below. Breakpoint 1 is the one we have created above. Figure 11. Setting additional breakpoints Once we have finished setting our breakpoints, we are now set to start debugging our code. To start the debugger, press F5 or click the green button on the Toolbar of the MetaEditor: Figure 12. Starting the Debugger The first thing the editor does is to compile the code, if there is any error at the point, it will display it and if no error, it will let you know that the code compiled successfully. Figure 13. Compilation Report Please note that the fact that the code compiled successfully does not mean there may not be errors in your code. Depending on how your code is written, there may be runtime errors. For example, if any of our expressions does not evaluate correctly due to any little oversight, the code will compile correctly but may not run correctly. Too much of the talk, lets see it in action Once the debugger has finished compiling the code, it takes you to the trading terminal, and attach the EA to the chart you have specified on the MetaEditor Options settings. At the same time, it shows you the Input parameters section of the EA. Since we are not adjusting anything yet, just click the OK button. Figure 14. Expert Advisor Input Parameters for Debugging You will now see the EA clearly on the top-right hand corner of the chart. Once it starts the OnTick() . it will stop as soon as it gets to our breakpoint 1. Figure 15. Debugger stops at the first breakpoint You will notice a green arrow at that code line. That tells you that previous code line had been executed we are now ready to execute the present line. Let me make some explanations before we proceed. If you look at the Editors Tool Bar, you will observe that the three buttons with curved arrows which were earlier grayed out are now activated. This is because we are now running the debugger. These buttonscommands are used to step through our code (Step into, Step over or Step out) Figure 16. Step into command The Step Into is used to go from one step of the program execution into the next step, entering into any called functions within that code line. Click on the button or press F11 to invoke the command. (We will use this command in our Step-by-Step debugging of our code.) Figure 17. Step over command The Step over . on the other hand does not enter into any called function within that code line. Click on the button or press F10 to invoke the command Figure 18. Step out command To execute a program step that is one level higher, you click this button or press ShiftF11 . Also, at the lower part of the Editor, you will see the Toolbox window . The Debug tab in this window has the following headings: File : This displays the name of the file been called Function : This displays the present function from the file been called Line : This displays the number of the code line in the file from which the function is called. Expression : This is where you can type the name of any expressionvariable you are interested in monitoring from our code. Value : This will display the value of the expressionvariable we typed at the Expression area. Type : This will display the data type of the expressionvariable been monitored. Back to our debugging process The next thing we want to do is now to type in the variablesexpressions from our code that we are interested in monitoring. Make sure you only monitor the variablesexpressions that really matters in your code. For our example, we will monitor the following: OldTime (old bar time) NewTime0 (current bar time) IsNewBar (flag that indicates the new bar) Mybars (Total bars in History) Our EA depends on it You can add other ones like the ADX values, the MA-8 values, etc. To add the expressionvariable, double-click under the Expressions area or right-click under the Expressions area and select Add as shown in the figure above. Type the expressionvariable to monitor or watch. Figure 19. The expressions watching window Type all the necessary variablesexpressions Figure 20. Adding expressions or variables to watch If the variable hasnt been declared yet, its type is Unknown identifier (except the static variables). Now, lets move on Figure 21. Step into command in action Click the Step into button or press F11 and observe what happens. Keep on pressing this button or F11 until you get to breakpoint no 2 . continue until you get to breakpoint no 4 as shown below and observe the expressions watching window. Figure 22. Watching the expressions or variables Figure 23. Watching the expressions or variables Figure 24. Watching the expressions or variables Once there is a new tick, it will return to the fist code line of the OnTick() function. And all the values of our variablesexpression will now be reset because this is a new tick except if any of them is declared as a static variable. In our case we have one static variable OldTime. Figure 25. Values of variables on NewTick event To go over the process again, continue pressing the F11 key and keep monitoring the variables at the expressions watching window. You can stop the debugger and then remove all the breakpoints. As we see, in Debug mode it prints the message We have new bar here. . Figure 26. Expert Advisor prints the message in Debug mode Start the debugging process again but this time without breakpoints. Keep watching at every tick and if any of our BuySell condition is met, it will place a trade and since we have written our code to tell us if an order is placed successful or otherwise, we will see an alert. Figure 27. Expert Advisor places trade during debugging I think you can leave the EA to work for a few more minutes while you take a coffee. Once you are back and you have made some money ( just kidding ), then click the STOP (Red) button on the MetaEditor to stop debugging. Figure 28. Stopping the debugger What we have actually done here is to see that our EA only checks for a trade at the opening of a new Bar and that our EA actually works. There is still a lot of room for adjustments to our EA code. Let me make it clear, at this point that, the Trading terminal must be connected to the internet, otherwise, debugging will not work because the terminal will not be able to trade. 3.2 TESTING OUR EA STRATEGY At this point we now want to test our EA using the Strategy Tester built into the Trading Terminal. To start the Strategy Tester, press CONTROLR or click the View menu on the Terminal Menu Bar and click on Strategy Tester as shown below Figure 26. Starting the Strategy Testing The Tester (Strategy Tester) is shown at the lower part of the terminal. For you to see all the Testers settings, you need to expandresize it. To do this, move your mouse pointer to the point shown by the red arrow (as shown below) Figure 27. The Strategy Tester window The mouse pointer changes to a double-end arrow, hold down the mouse and drag the line upwards. Stop when you discover that you can see everything on the settings tab. Figure 28. The Strategy Tester Settings Tab Select the EA you want to test Select the Currency pair to use for the test Select the PeriodTimeframe to use for the test Select Custom Period and set the dates in 5 Set the dates for the custom period to be used for the test Execution is Normal Select the deposit amount in USD to be used for the test Set Optimization to Disable (We are not optimizing now, we just want to test) Click this button when you are ready to start test. Before we click the Start button, lets look at the other tabs on the Tester The processor used by the Tester for the Test. Depending on your Computers processor type. Mine is only one (1) core processor. Figure 29. The Strategy Tester Agents tab Once the agent, you will see something similar to the figure below Figure 30. The Strategy Tester Agents tab during a test This is where all the events going on during the test period is displayed Figure 31. The Strategy Tester Journal tab showing trade activities This is where you can specify the input parameters for the EA. Figure 32. The Strategy Tester Inputs tab If we are optimizing our EA, then we will need to set the values in the circled area. The Start is the values you want the Tester to begin with. The Step is the increment rate for the value you selected, and The Stop is the value at which the Tester will stop incrementing the value for that parameter. However, in our case we are not optimizing our EA, so we will not need to touch that for now. Once everything is set, we now go back to the Settings tab and click the Start button. Then the tester begins its work. All you need to do now is to go and take another cup of coffee if you like, or, if you are like me, you may want to monitor every event, then turn to the Journal tab. Once you begin to see messages about orders been sent on the Journal Tab, you may then wish to turn to a NEW tab named Graph which has just been created. Once you switch to the Graph tab, you will see the graph keep on increasing or decreasing as the case may be depending on the outcome of your trades. Figure 33. The graph result for the Expert Advisor Test Once the test is completed, you will see another tab called Results . Switch to the Results tab and you will see the summary of the test we have just carried out. Figure 34. The Strategy Tester Results tab showing test results summary You can see the total Gross Profit, Net Profit, total trades total loss trades and many more. Its really interesting to see that we have about USD 1,450.0 within the period we selected for our test. At least we have some profit. Let me make something very clear to you here. You will discover that the settings for the EA parameters that you see in the Strategy tester is different from the initial settings in the Input parameters of the EA. I have just demonstrated to you that you can change any of those input parameters to get the best out of your EA. Instead of using a period of 8 each for the Moving Average and ADX, I changed it to 10 for Moving Average and 14 for ADX. I also change the Stop Loss from 30 to 35. Last but not the least, I decided to use 2 Hour timeframe. Remember, this is the Strategy Tester. If you want to view a complete report of the test, then right-click on anywhere in the Results tab, you will see a menu. From this menu, Select Save as Report . Figure 35. Saving the result of the test The save dialog window will appear, type a name for your report (if you want, otherwise leave the default name) and click the save button. The whole report will be saved in HTML format for you. To view the chart for the test that was carried out, click Open Chart and you will see the chart displayed Figure 36. The chart showing the test Thats it, we have successfully written and tested our EA and we now have a result to work with. You can now go back to the strategy tester Settings tab and make the test for other TimeframesPeriod. I want you to carry out the test using different currency pairs, different timeframes, different Stop Loss, different Take profit and see how the EA performs. You can even try new Moving Average and ADX values. As I said earlier, that is the essence of the Strategy tester. I will also like you to share your results with me. Conclusion In this step by step guide, we have been able to look at the basic steps required in writing a simple Expert Advisor based on a developed trading strategy. We have also looked at how we check our EA for errors using the debugger. We also discussed how to test the performance of our EA using the Strategy Tester. With this, we have been able to see the power and robustness of the new MQL5 language. Our EA is not yet perfect or complete as many more adjustments must still be made in order to used it for real trading. There is still more to learn and I want you to read the article over again together with the MQL5 manual, and try everything you have learn in this article, I can assure you that you will be a great EA developer in no distant future. Advanced Guide To MetaTrader 4 - Expert Advisors Expert Advisor Creation Expert Advisors are programs that allow automation of the analytical and trading processes in the MT4 platform. To create an Expert Advisor (or Expert), the expert editing program - MetaEditor - has to be opened from within the MT4 platform. To open the editor (see Figure 1):13 In the Navigator window, right-click on Expert Advisors and select Create or In the Main Menu gt Tools gt MetaQuotes Language Editor or Click on the MetaEditor icon in the Standard Toolbar: or Press F4 on the computer keyboard. 13 13 Figure 1 - There are several ways to open the MetaEditor. 13Any of these actions will open the Expert Creation Wizard. The Wizard can be used to create Expert Advisors, Custom Indicators, Scripts and DLLs. To create an Expert Advisor, select Expert Advisor and click Next to continue, as shown in Figure 2. 13 Figure 2 - MT4s Expert Advisor Wizard is used to create Expert Advisors, Custom Indicators, Scripts and Libraries (DLLs). 13The General Properties of the Expert Advisor window appears. Here, traders must specify the: Name - A user-created name for the Expert. Developer - The developers name. Link - To the developers website, if applicable. Inputs - the list of Expert inputs 13 13To add a new parameter to the Inputs field, press the Add button. For each Parameter, the trader must specify the Name, Type and Initial Value, as shown in Figure 3. To delete a parameter, highlight the parameter and press Delete. These become the Input Variables within the Expert. Once all the inputs have been listed, click Finish to continue.13 Figure 3 - Create the input variables by identifying Name, Type and Initial Value. 13A new window appears in the programming environment. The Experts name appears at the top of the window, and the previously entered input parameters are listed near the top of the code, as shown in Figure 4. 13 Figure 4 - The Expert name and inputs appear in the code window. 13From here, the Expert code can be entered into the window using the MQL4 programming language and syntax (see Figure 5). Hinweis . Specifics regarding programming are outside the scope of this tutorial understanding programming logic and learning a specific language require significant effort. Traders can learn more about programming in the MQL4 environment by reading the MT4 Help Guides and participating in the active MQL4 community forums. MQL4, like other proprietary languages, has a list of Reserved Words and Standard Constants that are used during programming. Examples of constants for trade operations, along with their descriptions, include:13 OPBUY - Buying position OPSELL - Selling position OPBUYLIMIT - Buy limit pending position OPSELLLIMIT - Sell limit pending position OPBUYSTOP - Buy stop pending position OPSELLSTOP - Sell stop pending position 13 13 Figure 5 - part of the code for an Expert Advisor. Certain words have predefined uses here, OPSELL instructs the computer to sell if other criteria are met ( if statements). Traders can find a MQL4 Reference in the Help tab of the Toolbox in the MetaEditor window. This Reference includes information that is helpful to beginner and experienced programmers including: Expert Advisor Compiling After the Expert development has been completed, it must be compiled in order to ensure that the code has been written in the proper format needed to run the Expert. To compile the Expert: Select File gt Compile (see Figure 6) or Click the Compile button on the toolbar or Press F5 on the computer keyboard. 13 13Once compiling has been initiated, an update appears in the Toolbox beneath the code in the MetaEditor window, as shown in Figure 6. An errors or warnings will be listed.13 Figure 6 - Successful compiling with zero errors and zero warnings. 13After successful compilation, the new Expert will appear in the Navigator - Expert Advisors window, as shown in Figure 7. If the Expert did not compile successfully, it will still appear but its icon will be gray and the Expert cannot be used. 13 Figure 7 - The new Expert now appears in the Navigator-Expert Advisors window. Expert Advisor Setup Before the Expert can be used, its parameters must be defined in the Terminal Settings window. To open the window:13 In the Main Menu gt Tools gt Options or Pressing CTRL O on the computer keyboard. Either action will open the Options window. Select the Expert Advisors tab, as shown in Figure 8. 13 Figure 8 - Select the Expert Advisors tab in the Options window to define an Experts parameters. 13 13The following settings are available in the Expert Advisors tab: Enable Expert Advisors - this option allows the user to enable (check) or disable (uncheck) the use of all Experts. Disable experts when the account has been changed - this option disables the Expert if the account has been changes, such as from a demo to a live account. Disable experts when the profile has been changed - this option prevents Experts from launching if the profile has changed. Allow live trading - to enable Experts in real-time mode (rather than testing an Expert on historical data). Ask manual confirmation - to send trade confirmation prior to submitting the order. Allow DLL imports - to use DLLs to enhance Expert functionality. Confirm DLL function calls - to allow control over the execution of each called function. Allow external experts imports - to allow the Expert to access functions from other Experts or MQL4 libraries. 13 13Once the selections have been made, click OK to close the window. Expert Advisor Launch 13 After the Expert has been created and setup, it is ready to be launched. To launch an Expert: 13 Right-click on the Expert in the Navigator - Expert Advisors window and select Attach to a chart or13 Double-click on the Expert in the Navigator - Expert Advisors window or13 Drag-and-drop the Expert to the desired chart.13 13A window appears with Common and Inputs tabs, as shown in Figure 9. Review the settings in each tab and make any necessary changes, and then click OK to attach the Expert to the active price chart.13 Figure 9 - Make any changes to the Common and Inputs tabs before attaching the Expert to the active price chart. 13The Expert will now be attached to the price chart. Its name will appear in the upper right-hand corner of the chart. The Experts name will be followed by a smiley face, as shown in Figure 10, if live trading is enabled. Otherwise, the Experts name will appear with a frowny face, a dagger after the name indicates that all experts are disabled. 13 Figure 10 - An Expert with a smiley face indicates that live trading has been enabled. 13The Expert is now ready to begin analytical and trading functions. Expert Advisor Shutdown To shut down an Expert, it has to be removed from the chart. To remove an Expert, right-click on the active price chart, select Expert Advisors and then Remove, as shown in Figure 11. 13 Figure 11 - To remove an Expert, right-click the active price chart, select Expert Advisors from the drop-down menu, and then select Remove. Notes About Expert Advisors All Experts are shutdown if the Terminal is closed. If a chart is closed, the Expert attached to the chart will shut down as well. Adding another Expert to a chart will remove the previous one (a confirmation appears). Deleting the Expert from the Navigator window does not shut down an Expert of the same name on an active price chart. 13 13SEE: Trading Systems Coding Advanced Guide To MetaTrader 4 - Custom IndicatorsMetaTrader 5 - Examples Writing an Expert Advisor Using the MQL5 Object-Oriented Programming Approach Introduction In the first article. we took a journey through the basic steps of creating, debugging and testing an Expert Advisor in MQL5. Everything we did was very simple and interesting however, the new MQL5 language has much more to offer. In this article, we will consider the Object Oriented approach to doing what we did in the first article. Most people think this is difficult, but I want to assure you that by the time you finish reading through this article, you will be able to write your own Expert Advisor which is object oriented based. We will not repeat some of the things we have learned in the first article. so I suggest that you first of all read through the article if you have not already done so. 1. The Object-Oriented Paradigm One of the things that make the new MQL5 much more powerful and robust than MQL4 is its OOP (Object Oriented Programming) approach. It is recommended in OOP that an object should not expose any of its implementation details. This way, its implementation can be changed without changing the code that uses the object. This means that a class allows a programmer to hide (and also prevents changes to) how the class he has written is implemented. To get things clearer, let us dwell a bit on the terms class and object just mentioned. CLASS. A class is more like an expanded concept of a data structure but instead of holding data only, it holds both data and functions. A class can contain several variables and functions, which are called the members of the class. It is an encapsulation of data members and functions that manipulate the data. A class is much more powerful, in that you can wrap up all your Expert Advisors functions in a class. You will only be making reference to the functions anytime you need them in your EA code. By the way, this is what this article is all about. OBJECT. An object is an instance of a class. Once a class has been created, to use the class, we must declare an instance of the class. This is called an object. In other words, to create an object you need a class. 1.1. DECLARING A CLASS A class, basically . contains the description of the members (properties and functionsmethods) of an object you want to create from the class. Let us look at an example If we want to create an object that will have doors, sits, tyres, weight . etc. and that can also start, changegear, stop and horn then we need to write a class for it. The doors, sits, tyres, weight, start, changegear, stop and horn will be the members of the class. Of course, you will observe that, these members are categorized some are just what our object will have (properties) while the others are what our object will do (actions functionsmethods). To declare our class, we need to think of a very good and descriptive name for it. In this case, we will call our class CAR . Our CAR class will have the properties and functions stated above as its members. To declare a class, we start by typing the keyword class followed by the name of the class followed by a pair of braces that contains the members of the class. So, the basic format of a class is as shown below: Here, classname is a valid identifier for the class we want to write, members1 and members2 are the data members of the class. The accesskeyword specifies the access right to the members of our class. An accesskeyword can be private . protected or public . Remember that we are trying to write a class that can be used by ourselves and others without actually exposing the implementation details. That is why access rights are necessary. There may be some members of our class we dont want access to from outside of our class. These are declared within the private access section using the private or protected keyword. Other members that we want access to from outside of our class will then be declared within the public access section using the public keyword. Now, our new CAR class will now look like below: Our CAR class is declared using the keyword class. This class contains eighth members with four members having private access and four members having public access. The four members in the private section are data members. Three are of integer (int) data type and one a double data type. These members cannot be accessed by any other function that is declared outside of this class. The four members in the public section are function members. Two return bool data type and two return void type. These are the members that are accessible to any object of this class whenever it is created by anyone using our class. Once an object of our class is created, these members will be readily available for use. As you will rightly observed, the access keywords ( private, public, protected ) are always followed by a colon. The class declaration also ended with a semi-colon. The members are declared using their correct data type. It should be noted that once you declare a class, all members of the class are given private access rights unless it is explicitly specified as we did above. For example, in the class declaration below: All the four members declared above the public access keyword automatically have private access. For our class to be used, an object of the class must first of all be created. Now, let us create an object which is a type of our class. To do this we will use our class name followed by the name we want to give the object. Or we can create another object Honda or Toyota is now a type of a CAR and can now have access to all the member functions of our CAR class provided the member functions are declared within the public access section. We will come back to this later. You can see that we can create as many objects of this class as we want. This is one of the benefits of Object Oriented programming. At this point, let us consider in details, the format of a class in MQL5. This is a declaration of a class where classname is the name of the class. This class has nine members, but out of this nine, two are special members . The Constructor: The constructor (represented as classname() ) is a special function that is called automatically when a new object of the type of the class is created. So in this case, when you create an object of the type of this class the constructor, classname() . is called automatically. The name of the constructor must match the name of the class, that is why we named the constructor as classname() . In MQL5, a constructor does not take any input parameters and has no return type. Memory allocations and initialization of the class members are normally done when the constructor is called. Constructors cannot be called explicitly as if they were regular member functions. They are only executed when a new object of that class is created. A class in MQL5 can only have one constructor. The Destructor: The second special member is represented as classname() . This is the class destructor written with a tide ( ) before the class name. It is called automatically when a class object is destroyed. All members of the class that needs to be de-initialized are de-initialized at this stage and it does not really matter whether you explicitly declared the destructor or not. Data Members: Members of a class can be any legal data type, the class type or the struct type. In other words, when declaring member variables of a class, you can use any legal data type (int, double, string, etc), an object of another class or a type of a structure (for example, the MQL5 MqlTradeRequest, etc) Function Members: These are members of the class which are used for modifying the data members and executing the major functions methods of the class. The return type for the function members can be of any legal return type (bool, void, double, string, etc). Private: Members declared within this section are only accessible by the function members of the class. They cannot be accessed by any other function outside of the class. Protected: Members declared within this section are accessible to the function members of the class and also can be accessed by the member functions of other classes that are derived from this class. This means that we can also create a new class from this class. In this case, the new class derived from this class (which will now become the base class) will be able to access the protected members of the base class. This is the concept of inheritance in OOP. We will soon discuss it, just relax Public: Members declared within this section are available for usage outside of the class by an object of the class. This is where to declare some of the functions that will be needed to use the class in other programs. Now that we have looked at the basic format of a class, I hope you are not bored yet because we still have some other interesting aspect of classes we need to look at before we finally jump into creating a class wrapper for our Expert Advisor. Lets say we want to make another class from this initial class baseclass . The format for deriving a new class from an initial class is as follows: The Derived Class: A few explanations here before we proceed to explain the details. The class newclass is derived from the class baseclass using the colon and an accesskeyword as shown above. Now, the newclass derivedmade from baseclass can access (or inherit) both the public and protected members of baseclass but cannot access (or not inherit) the private members of the baseclass . The newclass can also implement new member methodsfunctions different from the baseclass . In other words, the newclass can also have its own data and function members apart from the ones it inherits from the baseclass . If the public keyword is used in creating the derived class, it means that the public and protected members of the base class will be inherited as public and protected members of the derived class. If the Protected keyword is used, public and protected members of base class will be inherited as protected members of the derived class. If the private keyword is used, the public and protected members of base class will be inherited as private members of the derived class. It is important to note that when a new object of the newclas s (the derived class) is created, the constructor of the baseclass is called first before the constructor of the newclass while when the object is destroyed, the destructor of the newclass (the derived class) is called first before the destructor of the baseclass . To better understand this concept of inheritance, let us go back to our initial class CAR. We can derive another class SALOON from this class. Notice that I have declared three of the data members of the class CAR as protected. This is to enable our new class SALOON inherit these members. Also, I want you to understand that the order in which you place the access keywords does not matter. What matters is that all members declared under an access keyword belong to that keyword. Our derived class SALOON has two members and at the same time inherits seven members (protected and public members) from the base class CAR. This means that once an object of SALOON is created, it will be able to access the public member functions of CAR which are start() . changegear() . stop() and horn() together with its own public member function runathighspeed() . This is the concept of inheritance. Just as some charactersbehaviours (methods) of our fatherparents (base class) show up in us, their children (derived class), because we inherit those behaviours (methodsfunctions) from them either genetically or otherwise. Sorry, I am not a medical personnel, but I believe you quite grasp the picture I am trying to paint. By the way, MQL5 does not support multiple inheritance, so no need to talk about it. Hmm. I hope the black cloth covering the mystical thing called OOP or CLASS is being removed little by liitle dont get tired, if you feel at this point you are still not very clear with what we are discussing, you may need to relax, take a cup of coffee and then come back and start from the beginning. It is not as mysterious as you think If you are now back at this point, I assume you are following my explanation. I want you to tell me how many more classes you can derive from our base class CAR Please I need you answer. I am serious. Name them and write their declarations and mail them to me. If you can name them all, I will take you out for launch (am I kidding) Now that you are set for more, lets continue It is true that when I write, I write like my Dad. His hand writings are very neat and highly stylish just like mine. I guess it is something I inherit from him, but guess what he uses his left hand to write while I use my right hand and when you see the writings you can hardly differentiate because they look similar. What is the problem here I inherit good hand-writing from my father but I do not write with my left hand like my father. This means that even though its what I inherit and it looks similar but the way I do mine is different from my father. Does this make sense to you This is an idea of what is called Polymorphism in OOP. A derived class (myself, as in the example above) inherits a member function (writefine() for my handwritng) from a base class (my Dad) but it (I) implements the function (writefine() ) in a different way from the base class (My Dad). Back to our CAR class, and the derived class SALOON Let us look at a few changes we have made here. First, we have declared a new derived class from CAR named WAGON with two members. We have also modified the member function changegear() to become a virtual function in the base class. Why did we make changegear() a virtual function. It is simply because we want any class that inherits the function from the base class to be able to implement it in its own way. In other words, virtual member functions of a class are member functions that can be overridden or implemented differently in any class derived from the class where they are declared. The member function body can then be replaced with a new set of implementation in the derived class. Even though, we may not use the word virtual again in the derived classes, it is good programming practice to always use it in the derived classes. From the examples above, classes SALOON and WAGON implements the function changegear() in their own ways. 1.3. DEFINING CLASS METHODS (MEMBER FUNCTIONS) Since we have known, to some extent, how to declare classes lets move further by discussing how to define the member functions of a class. After we have declared the class, the next thing is to define the member functions of our class. Let us look at our CAR class again In defining the member functions, we have used a double colon ( :: ) operator called the scope operator . This is written just like normal functions, the only difference is the class name and the scope operator that is added. You will also observe that one of the functions was already defined within the class (member function horn() ). A member function can be defined in the class declaration or outside the class declaration as you have seen it here. I think it will be of importance if we can review the concept of functions a little before we proceed. By the way, what is a function Sometimes in a house where you have three kids, rather than just one of them doing all the works in the house one was asked to be washing the plates every day after supper, one was asked to be doing the sweeping while the third was given the task of arranging the beds every morning. There are some works to be done in the house, instead of giving all the works to one child, we divided it among the three of them. This will make the task very easy and light for each one of them rather than been a burden to just one of them. Also, if one of the kids did not do hisher task, we quickly know which one of them to flog. This is the idea behind functions. Most times we want to write a code that will do many tasks. This is where functions come in. We can decide to break the task into smaller tasks and then write a function to perform each of the smaller tasks. A function is a code-block that performs or implements a set of operations. It is a group of statements that is executed whenever it is called from some point in a program. A function can be defined as follows: Returntype . the data type returned by the function (must be a valid data type or void if it returns nothing) Functionname . the name of the function (must be a valid name) which will be used for calling the function Parameters . parameters are valid data type variables which will act within the function as a local variable. If a function has more than one parameter, they are separated by commas. Expressions . the body of the function that contains block of statements Example of a function: The function return type is integer (int), doaddition is the function name and int x and int y are the parameters. What the function does is to add any two input parameters supplied it and return the result. So if we supply the function with two integer variables 2 and 3, the function will do the addition and return 5 as the result. For more information about functions, please consult the MQL5 Reference manual. Now enough of the theories let us get down to work. The essence of this article is to teach you how you can write a class for your Expert Advisor using the Object Oriented approach presented in MQL5. It is now time for action 2. Writing an Expert Advisor At this point, we will be making reference to the Expert Advisor we created in the first article. If you have not read the article, please go and do so now so that most of the things we shall be discussing from this point on will not be strange to you. However, I may still revise a few things that may be necessary. Before you can write your class, you need to sit down and develop your trading strategy first. We have already done this in the first article. The next thing is to select those functionalities we want to delegate to our class. These functionalities will determine the member variables of our class. Just a recap of our trading strategy from the first article. What our EA will do: It will monitor a particular indicator, and when a certain condition is met (or certain conditions are met), it will place a trade (either a ShortSell or LongBuy), depending on the present condition that has been met. The above is called a trading strategy. Before you can write an EA, you must first develop the strategy that you want to automate into the EA. So in this case, let us modify the above statement so that it reflects the strategy we want to develop into an EA. We will use an indicator called Moving Average with a period of 8 ( You can choose any period, but for the purpose of our strategy, we will use 8) We want our EA to place a Long (Buy) trade when the Moving Average-8 (for the sake of our discussion, I will refer to it as MA-8) is increasing upwards and the price is close above it and it will place a Short (Sell) when MA-8 is decreasing downwards and the price is close below it. We are also going to use another indicator called Average Directional Movement (ADX) with period 8 also to help us determine whether the market is trending or not. We are doing this because we only want to enter the trade when the market is trending and relax when the market is ranging (that is, not trending). To achieve this, we will only place our trade (Buy or Sell) when above conditions are met and the ADX value is greater than 22. If ADX is greater than 22 but decreasing, or ADX is less than 22, we will not trade, even though the condition B has been met. We want to also protect ourselves by setting a Stop loss of 30 pips, and for our Profit target we will target a profit of 100 pips. We also want our EA to look for BuySell opportunities only when a new bar has been formed and we will also make sure we open a Buy position if the Buy conditions are met and we do not already have one opened, and open a Sell position when the Sell conditions are met and we do not already have one opened. In addition, we want to make sure that we are able to control the percent of our Free Margin that can be used in placing a trade and also to ensure that we check available free margin before placing any trade. Our EA will only place a trade if available margin is enough for the trade. Now you understand what we want to do. The functions we want to delegate to our class are: Check for Buy and Sell conditions Place BuySell depending on the result of the conditions checked Basically, this is all we want our EA to do. These two functionalities are the major functions but there are still more. For example, in checking for BuySell positions, the indicators must be used. This means obtaining the values of the indicators must also be in our class. So, we include: Get all the indicator handles (at the EA OnInit section) Get all indicator buffers (at the EA OnTick section) Release all indicator handles (at the EA OnDeinit section) In getting the indicator values, our class will need to know the MA and ADX periods, the chart period and symbol (currency pair we are working with), so we must also include: Get ADX and MA periods, and other important parameters like the chart period and symbol. Also for the checking of free margin before placing a trade, we will include Check Free Marginpercentage of account to use for trade With this we already have an idea of what variables and functions should be in our class. Okay, I have done the thinking for you it is time to write some code. 2.1. Writing a class Let us begin by launching the MetaEditor (I believe you already know this). Once the MetaEditor is opened, let us start a new MQL document by clicking the New toolbar or CtrlN. In the wizard window, select Include and click the NEXT button. Figure 1. Starting a new MQL5 document Type the name of the file as shown below and click finish: Figure 2. Naming a new document We selected include because our class is going to be an include file which will be included in our EA code once we are ready to use it. That is why you do not have room to enter input parameters. As usual, the editor provides you with a skeleton of what it thinks you want to do. To begin, please delete everything below the property link code line. You should now have something like this. Now let us write the declaration of our class, we shall call our class, MyExpert . Lets analyze the class declaration. The declaration starts with the name of the class. Next we declared the private members of the class. The Private Members: As explained earlier, these private member variables are not accessible by any function outside of the class. Most of the variables are very clear in their declarations so I wont waste time talking about them. However, you will remember in our discussion, that we stated that member variables can be any legal data type, structure or class. I believe you can see this in action here with the declaration of the MqlTradeRequest and MqlTradeResults types. The constructor does not take any input parameters please bear this in mind when writing your own class. The member functions We have defined these member functions to allow us set the important variables that will be needed by our class to perform its function. Without using these functions, these variables will not be available for our class to use. As you will also notice, we had already declare a corresponding variable in our class that will hold these values once they are set by these functions. Another thing to note is that we have defined these member functions within the class declaration. As I explained earlier, it is allowed. It means we wont need to define them again when defining other member functions as you will see very soon. Just like normal functions, they have parameters of the correct data type depending on the return values of each function. I believe this should not be strange to you. We only declare these member functions but we did not define them. This is because we will be doing that later. These are functions that will manipulate most of the values store in the member variables of our class and at the same time they form the functions for the major role of our class. We will discuss them later. The Protected members These members will be inherited by any class that is derived from our class. It is not really necessary if you dont intend to derive any other class from this class. You can as well place them as private members. I am only doing this to let you understand the various issues we have discussed earlier about classes. These three functions are also very important though internal to our class. The showError will display our errors and the getBuffers will be used to get indicator buffers. MarginOK check if there is enough free margin to open a position. Once you have finished with the declaration of the class, dont forget the semi-colon. It is very important. The next thing to do immediately after declaring the class is to define the member functions that have not been defined in the declaration section. This is our class constructor. Here we used the double colon ( :: ) (the scope operator ) between the class name and the member function name. What we are trying to say is this: Though we are defining this member function outside of the class declaration, but it is still in the scope of the class. It is a member of the class whose name comes before the two colons (scope operator ). It does not have any input parameters. It is at this point we initialize most of the necessary member variables and we use the ZeroMemory function to accomplish this. void ZeroMemory ( void amp variable reset variable ) This function resets the values of variables passed to it. In this case we use it to reset the values of our structure types (MqlTradeRequest and MqlTradeResult ) and our arrays. The showError function: This is a protected member function which is used to display all errors encountered during the operations of any object of our class. It takes two argumentsparameters Error description and error code. The getBuffers function: This function is used to copy all our indicators buffers to the arrays we have specified in the member variables using the respective indicator handle. The CopyBuffer function was explained in the first article. The getBuffers function does not have any input parameters because we are using the values from the member variables of the class. We used our internal error function here to display any error that may occur in the process of copying the buffers. The MarginOK function: This function is actually doing two jobs. It checks to make sure that we have enough free margin to place the trade and also checks to make sure we dont use more than a specified percentage of the free margin available to place the trade. In this way we can control how much money we use for each trade. We use the AccountInfoDouble() function together with the ENUMACCOUNTINFODOUBLE identifier to get the Free Margin for the account. We also use the AccountInfoInteger() function together with the ENUMACCOUNTINFOINTEGER identifier to get the Leverage for the account. The AccountInfoInteger() and AccountInfoDouble() are account functions used to get the details of the current account using the EA. We also used the symbol properties functions SymbolInfoDouble() and SymbolInfoString() to get the contract size and base currency for the current symbol (currency pair) respectively. The SymbolInfoDouble() function takes the symbol name and an ENUMSYMBOLINFODOUBLE identifier as parameters while the SymbolInfoString() function takes the symbol name and an ENUMSYMBOLINFOSTRING identifier as parameters. The results of these functions are stored in the declared variables for each data type. The calculation we have done here is very simple. To get the required margin for placing a trade, we consider two situations: The base currency is USD (USDCAD, USDCHF, USDJPY, etc.) Margin required Contract size per lot Leverage 2. The base currency is not USD (EURUSD, etc) Margin required current price of symbol contract size per lotLeverage. We now decide to check if the margin required to trade the specified lot size or volume is greater than the percentage of free margin you want to use for a trade. If margin required is less the function returns TRUE and the trade is placed, otherwise, it return FALSE and the trade will not be placed. The doInit function: This is a public function we intend to use in the OnInit() function of our EA which we will write soon and it is going to do two things. First, it will set the handles for our indicators and also perform the array-set-as-series action on the array variables. It has two input parameters which will be supplied from within our EA code. The doUninit function: This function is also a public member function which will be used in the UnDeInit function of our EA to release all handles for the indicators we have used. It does not have any input parameters. The checkBuy function: This function will be used to check if a buy condition has been set or not. That is why its return type is bool. It means that it will return a TRUE or a FALSE. This is where we defined our Buy trade strategy. If a buy condition is met based on the strategy we have defined, it will return TRUE however, if the Buy condition is not met it will return FALSE. When using this function in our code, we will then place a buy if it returns TRUE. The first thing we have done here is to call the internal member function getBuffers() . which will copy all the array values needed by the checkBuy function to the corresponding array variables. The conditions coded here had been explained in the first article. The checkSell function: Just like the checkBuy . this function will be used to check if a Sell condition has been set or not. That is why its return type is also bool. It means that it will return a TRUE or a FALSE. This is where we defined our Sell trade strategy. If a sell condition is met based on the strategy we have defined, it will return TRUE however, if the sell condition is not met it will return FALSE. When using this function in our code, we will then place a sell if it returns TRUE. Just like in checkBuy . we called the internal function getBuffers() first. The conditions coded here had also been explained in the first article. The openBuy function: This is the function that opens a buy position whenever it is called in our EA. It has, as input parameters, most of the variables that will be needed to place the trade and some of the variables will be provided by our EA code. You will notice, as explained in the first article. that we have used the MqlTraderequest type variables here. We will not need to use them in our EA code. Before a trade is placed, we want to confirm if the user wants to check margin, if the value of ChkMargin (which will be obtained from the EA) is 1, then we call the MarginOK() function to do that for us. The result of this function determines the next step to take. However, if the user does not want to check margin, then we just continue and place the trade. The openSell function: Just like the openBuy function, this function opens a sell position whenever it is called in our EA. It has, as input parameters, most of the variables that will be needed to place the trade and some of the variables will be provided by our EA code. Just as we did when opening a Buy position, before a trade is placed, we want to confirm if the user wants to check margin, if the value of ChkMargin (which will be obtained from the EA) is 1, then we call the MarginOK() function to do that for us. The result of this function determines the next step to take. However, if the user does not want to check margin, then we just continue and place the trade. Now we have finished the declaration and definition of our class and the member functions, however, we have left out some other tasks which we intend to handle in our EA code. These include checking of available bars, checking of new bars and checking for available opened positions. They will be handled in our EA code. To see a list of the all the functions and methods of our class, click on the functions commandmenu on the MetaEditor as shown below. The function displays all the member functions including the Destructor which we did not explicitly declared in our code. The protected members are pointed by green arrows while the Constructor and destructor are pointed by blue arrows. Figure 3. Our class member functions showing the class destructor Did I hear you say, debug Maybe you are right. It is always good to test and see if your code has errors otherwise you will be disappointed when you release it to the public. The problem here is that this is just an include file, it is not an expert adviser code or script or indicator code which can be attached to the chart. At this point you have two options (from my experience). you either risk pressing the debug button on your editor so that the debugger will report any error in your code with the exception of a no executable file produced error, which will be displayed because an. mqh file cannot be compiled into an. ex5 file. OR Go ahead and write the code for the EA that will use your class. Once you start debugging the EA, the included file will be checked along with it. In fact, this is the best and most acceptable way to do it. Figure 4. mqh files cannot be compiled 2.2. WRITING THE EXPERT ADVISOR I guess your editor is still opened. Start a new document again but this time select Expert Advisor. (Please see the first article for details). But this time, name your EA myoopea . This is where you should be now: Now we are ready to write our OOP based EA. The first thing we are going to do here is to include the class we have just written using the include preprocessor command. Include the class just immediately after the last preprocessor property command There are two ways of including a file, When we use the angle bracket (lt. gt), it means that the file to be included will be taken from the standard include directory (that is, include folder inside the MQL5 directory). The current directory (which is the Experts folder inside the MQL5 directory will not be considered as a possible place to look for the file). However, if the file is enclosed in quotation marks (. ), the file will be considered to be in the current directory (which is the Experts folder) and the standard directory (Include folder) will not be checked. If your class is saved in the Include folder (standard directory) and you use the quotation marks instead of angle brackets or vice versa, you will get an error when compiling the code. Figure 5. An error message displayed when include file cannot be found EA INPUT PARAMETERS Most of the input parameters here are not new. Lets discuss the new ones. We have introduced an integer variable to hold a value of 1 if we want to use margin check or 0 if we dont. We have also declared another variable to hold the maximum percentage of Free margin to be used in opening a position. These values will later be used in our class object when created. Immediately after the input parameters, we define other two parameters (STP and TKP) which we want to be able to manipulate (to cater for 5 and 3 digit prices) since we cannot change the values of the input variables. Then we create an object of our class for use within our EA code. As explained earlier, to create an object of a class, you use the class name followed by the name of the object you wish to create. Here we have created an object Cexpert which is a type of MyExpert class. Cexpert can now be used to access all the public member functions of the class MyExpert . EA INITIALIZATION SECTION At this point, we called the doInit function of our class and pass the ADX and MA period variables to it. Next we set all the other variables that will be needed by the object we have just created so that it will be stored in the objects member variables using the functions we already described when writing our class. The next line of codes shouldnt be strange, we just decide to adjust our Stop Loss and Take Profit values for three and five-digit prices. EA DEINITIALIZATION SECTION We called the doUninit function of the class so as to release all the indicator handles that must have been created in the EA initialization function. EA ONTICK SECTION The first thing we do here is to check for total available bars. If it is enough for our EA to trade, it will otherwise it will not trade until we have enough bars (that is, 60 bars). Then we declared two variables of the MQL5 structure (MqlTick and MqlRates ). And lastly, we use the ArraySetAsSeries function on the rates array. Here, we used the SymbolInfoTick function to get the latest price quote and used CopyRates to get the last rates for the past three bars (present bar inclusive). The next lines of code check if we have a new bar. We declared two datetime variables, one is a static variable ( PrevTime ) and the other is BarTime . If we have a new bar, the bar time is stored in the static variable PrevTime so that we will be able to compare its value with the value of BarTime in the next tick. In the next tick, if the PrevTime equals BarTime . then it is still the same bar whose time was stored. So our EA will relax. If however BarTime is not equal to PrevTime . then we have a new bar. We decide to store the new bar start time in the static datetime variable, PrevTime and our EA can now proceed to check for new BUY or SELL opportunities. We decide to check if we already have an opened position. We just want to be sure we opened a buy trade when there is no Buy opened and a sell trade when there is no sell opened. Now we are back to the object we created, why Because we have been able to make all the necessary checks that is necessary for our object to do its work. The first thing we do is to get the closed price for the previous bar using our objects member function setCloseprice . Then we call the checkBuy function to find out if a condition for buy is set, if it returns TRUE, then we want to be sure we dont have an already opened buy position. If we dont have an already opened buy position, then we prepare the required variables to be used for our order ( the order type, the current ASK price, stop loss, take profit and maximum deviation ) and call the openBuy function. See how easy it is to use the class we have written. This is the same as what we have done above. Since we are checking for a sell, we called the checkSell function and if it returns TRUE and we dont already have a sell position opened, we prepare the required variables to place our order ( the order type, the current ASK price, stop loss, take profit and maximum deviation ) and then call the openSell function. Pretty easy, isnt it We have finished writing the codes. Now it is time to debug our code. If you dont know how to use the debugger, please read the first article for a better understanding. When you press F5 or press the debug button, the included file (our class) will be included and checked, and if there is any error, it will report it. Once you see the error, you need to go back to the code and correct the error. Figure 6. Our include file is included when debugging the main EA code If everything is okay you have done well. It is now time to test our EA using the strategy tester. We need to compile our EA before testing it with the Strategy Tester. To do this, click on the Compile button or press F7 on your computer keyboard. Figure 7. Click the Compile menu button to compile our code From the trading terminal menu bar, go to View --gt Strategy Tester or press CONTROLR to start the strategy tester. (For details of how to use the tester, please read the first article ). For you to be able to test the EA with the strategy tester, you must first of all compile it. If you dont compile it, you will get an error when you select the Expert Advisor on the settings bar of the strategy tester. (I just discover this in the new version of the terminal.) Figure 8. The code of EA should be compiled before its use in the Strategy Tester Find below the results of the Strategy tester for our OOP based Expert Advisor. Figure 9. The trade results for our Object Oriented Expert Advisor Figure 10. The graph results for our Object Oriented Expert Advisor The trade activity reportjournal: Figure 11. The trade activity results for our Object Oriented Expert Advisor The chart for the test: Figure 12. The trade chart results for our Object Oriented Expert Advisor Conclusion In this article we have discussed, to some level, the basics of a class and how to use it in writing a simple Expert Advisor. We have not delved too much into the advanced areas of classes but what we have discussed in this article is enough to help you develop yourself to a level you will be able to write your own object oriented Expert Advisor code. We have also discussed about how we can check for free margin such that our EA does not trade when the free margin available is not enough for the position we want to open. You will now agree with me that the new MQL5 language has much more to offer and you dont have to be a programming guru to take advantage of this new language. That is the main reason behind writing the step-by-step guides.