forex generator

65
ن ی وژژ ست ی ا رام ب گ ا روع دب ش ل اژ ب قMT دژ رب ت ا ب م ن دو وژژ اژ اژ ر ف رم ا ت ن ی رد. ا ک اب خ ت ن ژا ا4 و5 وسط ت ی که ک لا ب د. ب ک ی م ی ن ا ب; ی ب ی دژ رب ت ا ب مرای ت اژ ر ف رم ا ت ن ی ا4 ن رای وژژ ت را ج ل ا ب ا ود ق ش ی م ی ح را ط5 . ت س ی ب اژ: ر ف رم ا ت ی صل حه ا ف ص د ب ک ی م م ه را ف رQ ظ ن وژد م وداژ م نرای ت ژاX لاک ب اد خ ی ا کان ی ام] نلا ا ب ت م س ق رام گ ا دب اب وبa ت ح م ی ر ک ر م ت م س ق د. وب ش ی م ف ی ر ع ت هاX لاک ب واص خ ی ها و گ ر ت و= ت= چ ت م س قرای ت ج ی ا بp ن ی ت ی] ب ا= ب ت م س قEA ن ه. دژ وژژ د اد ش خ ی اPro ود. ش ی م داده ش ی ما ن ط ی ن وژس کد ش ود اژ y ش ی م هاد ن y س; ب د. وب y شلy ص ی م ا~ن ا y ه ب y ی ق تد و و y ش روع y ش ده yرد شy گX لاک ب ا y ی ب تy س ی ا وداژی بy م نرy هOn Every Tick اده ف تy س ” ا اژ ر ت ا اژ هاX وک ل ب صال نرای ا ت د. ب کیLine ود. ش می اده ف ت س ا اژ ردن کX اک= رای ب تDel اد خ یرای ا ت وEA اژF7 اژ ت= پ; ن ر شگد ا ا خ یرای ا ت وF5 د. ب کی اده ف ت س ا

Upload: javi-crepo-sierra

Post on 10-Nov-2015

215 views

Category:

Documents


11 download

DESCRIPTION

Forex

TRANSCRIPT

MT . 4 5 . 4 5 .

: . EA . Pro .

. On Every Tick . Line . Del EA F7 F5 . Technical Analysis . First Function Second Function .

. . . mq4 mq5 . ex .

..\terminal\experts\indicators . mod . . :

: .

. .

.

.

Trailing Stop EA . EA .

Order ID Sell Buy . order id . order id . Close order order . . Order id magic number .

EA Generate EA . EA expert . :

EA Compilation successful . :

: MA (0 1 2 ) Technical Analysis 2 .

Technical Analysis 2 3 . :

:

1: MA MA . . (4) On Every Tick ( EA ) . 5 5-digit Broker True .

Print Info to Chart .

Generate EA Compiled successful .

Technical Analysis . .

... . iMA .

MA MA .

Buy . if Order Does Not Exist Buy .

: 5 if order does not exist if position does not exist . buy . :

. MA MA .

EA generate . : EA

2014.05.12 11 36.000 2014.04.04 05:01:06 Function: BuyOrder3 Error: 10013 Invalid request2014.05.12 11 36.000 2014.04.04 05:01:07 failed exchange buy 0.20 EURUSD at 1.37150 sl: 1.36950 tp: 1.37450 [Invalid request] . EA EA mq5 //--- prepare a requestMqlTradeRequest request;

//--- prepare a requestMqlTradeRequest request={0};

. : Trailing stop :

Trailing Stop Order id . .

.

: Pending order .

: High ADX 20 . .

:

High (0) (MODE_UPPER) :

ADX 20 :

:

: Parabolic SAR : . . . . .

:

:

SAR :

SAR .

iSAR .

Return Codes of the Trade ServerAll requests to execute trade operations are sent as a structure of a trade request MqlTradeRequest using function OrderSend(). The function execution result is placed to structure MqlTradeResult, whose retcode field contains the trade server return code. CodeConstantDescription

10004TRADE_RETCODE_REQUOTERequote

10006TRADE_RETCODE_REJECTRequest rejected

10007TRADE_RETCODE_CANCELRequest canceled by trader

10008TRADE_RETCODE_PLACEDOrder placed

10009TRADE_RETCODE_DONERequest completed

10010TRADE_RETCODE_DONE_PARTIALOnly part of the request was completed

10011TRADE_RETCODE_ERRORRequest processing error

10012TRADE_RETCODE_TIMEOUTRequest canceled by timeout

10013TRADE_RETCODE_INVALIDInvalid request

10014TRADE_RETCODE_INVALID_VOLUMEInvalid volume in the request

10015TRADE_RETCODE_INVALID_PRICEInvalid price in the request

10016TRADE_RETCODE_INVALID_STOPSInvalid stops in the request

10017TRADE_RETCODE_TRADE_DISABLEDTrade is disabled

10018TRADE_RETCODE_MARKET_CLOSEDMarket is closed

10019TRADE_RETCODE_NO_MONEYThere is not enough money to complete the request

10020TRADE_RETCODE_PRICE_CHANGEDPrices changed

10021TRADE_RETCODE_PRICE_OFFThere are no quotes to process the request

10022TRADE_RETCODE_INVALID_EXPIRATIONInvalid order expiration date in the request

10023TRADE_RETCODE_ORDER_CHANGEDOrder state changed

10024TRADE_RETCODE_TOO_MANY_REQUESTSToo frequent requests

10025TRADE_RETCODE_NO_CHANGESNo changes in request

10026TRADE_RETCODE_SERVER_DISABLES_ATAutotrading disabled by server

10027TRADE_RETCODE_CLIENT_DISABLES_ATAutotrading disabled by client terminal

10028TRADE_RETCODE_LOCKEDRequest locked for processing

10029TRADE_RETCODE_FROZENOrder or position frozen

10030TRADE_RETCODE_INVALID_FILLInvalid order filling type

10031TRADE_RETCODE_CONNECTIONNo connection with the trade server

10032TRADE_RETCODE_ONLY_REALOperation is allowed only for live accounts

10033TRADE_RETCODE_LIMIT_ORDERSThe number of pending orders has reached the limit

10034TRADE_RETCODE_LIMIT_VOLUMEThe volume of orders and positions for the symbol has reached the limit

10035TRADE_RETCODE_INVALID_ORDERIncorrect or prohibited order type

10036TRADE_RETCODE_POSITION_CLOSEDPosition with the specified POSITION_IDENTIFIER has already been closed

Runtime ErrorsGetLastError() is the function that returns the last error code that is stored in the predefined variable _LastError. This value can be reset to zero by the ResetLastError() function.ConstantCodeDescription

ERR_SUCCESS0The operation completed successfully

ERR_INTERNAL_ERROR4001Unexpected internal error

ERR_WRONG_INTERNAL_PARAMETER4002Wrong parameter in the inner call of the client terminal function

ERR_INVALID_PARAMETER4003Wrong parameter when calling the system function

ERR_NOT_ENOUGH_MEMORY4004Not enough memory to perform the system function

ERR_STRUCT_WITHOBJECTS_ORCLASS4005The structure contains objects of strings and/or dynamic arrays and/or structure of such objects and/or classes

ERR_INVALID_ARRAY4006Array of a wrong type, wrong size, or a damaged object of a dynamic array

ERR_ARRAY_RESIZE_ERROR4007Not enough memory for the relocation of an array, or an attempt to change the size of a static array

ERR_STRING_RESIZE_ERROR4008Not enough memory for the relocation of string

ERR_NOTINITIALIZED_STRING4009Not initialized string

ERR_INVALID_DATETIME4010Invalid date and/or time

ERR_ARRAY_BAD_SIZE4011Requested array size exceeds 2 GB

ERR_INVALID_POINTER4012Wrong pointer

ERR_INVALID_POINTER_TYPE4013Wrong type of pointer

ERR_FUNCTION_NOT_ALLOWED4014System function is not allowed to call

ERR_RESOURCE_NAME_DUPLICATED4015The names of the dynamic and the static resource match

ERR_RESOURCE_NOT_FOUND4016Resource with this name has not been found in EX5

ERR_RESOURCE_UNSUPPOTED_TYPE4017Unsupported resource type or its size exceeds 16 Mb

ERR_RESOURCE_NAME_IS_TOO_LONG4018The resource name exceeds 63 characters

Charts

ERR_CHART_WRONG_ID4101Wrong chart ID

ERR_CHART_NO_REPLY4102Chart does not respond

ERR_CHART_NOT_FOUND4103Chart not found

ERR_CHART_NO_EXPERT4104No Expert Advisor in the chart that could handle the event

ERR_CHART_CANNOT_OPEN4105Chart opening error

ERR_CHART_CANNOT_CHANGE4106Failed to change chart symbol and period

ERR_CHART_WRONG_PARAMETER4107Error value of the parameter for the function of working with charts

ERR_CHART_CANNOT_CREATE_TIMER4108Failed to create timer

ERR_CHART_WRONG_PROPERTY4109Wrong chart property ID

ERR_CHART_SCREENSHOT_FAILED4110Error creating screenshots

ERR_CHART_NAVIGATE_FAILED4111Error navigating through chart

ERR_CHART_TEMPLATE_FAILED4112Error applying template

ERR_CHART_WINDOW_NOT_FOUND4113Subwindow containing the indicator was not found

ERR_CHART_INDICATOR_CANNOT_ADD4114Error adding an indicator to chart

ERR_CHART_INDICATOR_CANNOT_DEL4115Error deleting an indicator from the chart

ERR_CHART_INDICATOR_NOT_FOUND4116Indicator not found on the specified chart

Graphical Objects

ERR_OBJECT_ERROR4201Error working with a graphical object

ERR_OBJECT_NOT_FOUND4202Graphical object was not found

ERR_OBJECT_WRONG_PROPERTY4203Wrong ID of a graphical object property

ERR_OBJECT_GETDATE_FAILED4204Unable to get date corresponding to the value

ERR_OBJECT_GETVALUE_FAILED4205Unable to get value corresponding to the date

MarketInfo

ERR_MARKET_UNKNOWN_SYMBOL4301Unknown symbol

ERR_MARKET_NOT_SELECTED4302Symbol is not selected in MarketWatch

ERR_MARKET_WRONG_PROPERTY4303Wrong identifier of a symbol property

ERR_MARKET_LASTTIME_UNKNOWN4304Time of the last tick is not known (no ticks)

ERR_MARKET_SELECT_ERROR4305Error adding or deleting a symbol in MarketWatch

History Access

ERR_HISTORY_NOT_FOUND4401Requested history not found

ERR_HISTORY_WRONG_PROPERTY4402Wrong ID of the history property

Global_Variables

ERR_GLOBALVARIABLE_NOT_FOUND4501Global variable of the client terminal is not found

ERR_GLOBALVARIABLE_EXISTS4502Global variable of the client terminal with the same name already exists

ERR_MAIL_SEND_FAILED4510Email sending failed

ERR_PLAY_SOUND_FAILED 4511Sound playing failed

ERR_MQL5_WRONG_PROPERTY 4512Wrong identifier of the program property

ERR_TERMINAL_WRONG_PROPERTY4513Wrong identifier of the terminal property

ERR_FTP_SEND_FAILED4514File sending via ftp failed

ERR_NOTIFICATION_SEND_FAILED4515Failed to send a notification

ERR_NOTIFICATION_WRONG_PARAMETER4516Invalid parameter for sending a notification an empty string or NULL has been passed to the SendNotification() function

ERR_NOTIFICATION_WRONG_SETTINGS4517Wrong settings of notifications in the terminal (ID is not specified or permission is not set)

ERR_NOTIFICATION_TOO_FREQUENT4518Too frequent sending of notifications

Custom Indicator Buffers

ERR_BUFFERS_NO_MEMORY4601Not enough memory for the distribution of indicator buffers

ERR_BUFFERS_WRONG_INDEX4602Wrong indicator buffer index

Custom Indicator Properties

ERR_CUSTOM_WRONG_PROPERTY4603Wrong ID of the custom indicator property

Account

ERR_ACCOUNT_WRONG_PROPERTY4701Wrong account property ID

ERR_TRADE_WRONG_PROPERTY4751Wrong trade property ID

ERR_TRADE_DISABLED4752Trading by Expert Advisors prohibited

ERR_TRADE_POSITION_NOT_FOUND4753Position not found

ERR_TRADE_ORDER_NOT_FOUND4754Order not found

ERR_TRADE_DEAL_NOT_FOUND4755Deal not found

ERR_TRADE_SEND_FAILED4756Trade request sending failed

Indicators

ERR_INDICATOR_UNKNOWN_SYMBOL4801Unknown symbol

ERR_INDICATOR_CANNOT_CREATE4802Indicator cannot be created

ERR_INDICATOR_NO_MEMORY4803Not enough memory to add the indicator

ERR_INDICATOR_CANNOT_APPLY4804The indicator cannot be applied to another indicator

ERR_INDICATOR_CANNOT_ADD4805Error applying an indicator to chart

ERR_INDICATOR_DATA_NOT_FOUND4806Requested data not found

ERR_INDICATOR_WRONG_HANDLE4807Wrong indicator handle

ERR_INDICATOR_WRONG_PARAMETERS4808Wrong number of parameters when creating an indicator

ERR_INDICATOR_PARAMETERS_MISSING4809No parameters when creating an indicator

ERR_INDICATOR_CUSTOM_NAME4810The first parameter in the array must be the name of the custom indicator

ERR_INDICATOR_PARAMETER_TYPE4811Invalid parameter type in the array when creating an indicator

ERR_INDICATOR_WRONG_INDEX4812Wrong index of the requested indicator buffer

Depth of Market

ERR_BOOKS_CANNOT_ADD4901Depth Of Market can not be added

ERR_BOOKS_CANNOT_DELETE4902Depth Of Market can not be removed

ERR_BOOKS_CANNOT_GET4903The data from Depth Of Market can not be obtained

ERR_BOOKS_CANNOT_SUBSCRIBE4904Error in subscribing to receive new data from Depth Of Market

File Operations

ERR_TOO_MANY_FILES5001More than 64 files cannot be opened at the same time

ERR_WRONG_FILENAME5002Invalid file name

ERR_TOO_LONG_FILENAME5003Too long file name

ERR_CANNOT_OPEN_FILE5004File opening error

ERR_FILE_CACHEBUFFER_ERROR5005Not enough memory for cache to read

ERR_CANNOT_DELETE_FILE5006File deleting error

ERR_INVALID_FILEHANDLE5007A file with this handle was closed, or was not opening at all

ERR_WRONG_FILEHANDLE5008Wrong file handle

ERR_FILE_NOTTOWRITE5009The file must be opened for writing

ERR_FILE_NOTTOREAD5010The file must be opened for reading

ERR_FILE_NOTBIN5011The file must be opened as a binary one

ERR_FILE_NOTTXT5012The file must be opened as a text

ERR_FILE_NOTTXTORCSV5013The file must be opened as a text or CSV

ERR_FILE_NOTCSV5014The file must be opened as CSV

ERR_FILE_READERROR5015File reading error

ERR_FILE_BINSTRINGSIZE5016String size must be specified, because the file is opened as binary

ERR_INCOMPATIBLE_FILE5017A text file must be for string arrays, for other arrays - binary

ERR_FILE_IS_DIRECTORY5018This is not a file, this is a directory

ERR_FILE_NOT_EXIST5019File does not exist

ERR_FILE_CANNOT_REWRITE5020File can not be rewritten

ERR_WRONG_DIRECTORYNAME5021Wrong directory name

ERR_DIRECTORY_NOT_EXIST5022Directory does not exist

ERR_FILE_ISNOT_DIRECTORY5023This is a file, not a directory

ERR_CANNOT_DELETE_DIRECTORY5024The directory cannot be removed

ERR_CANNOT_CLEAN_DIRECTORY5025Failed to clear the directory (probably one or more files are blocked and removal operation failed)

ERR_FILE_WRITEERROR5026Failed to write a resource to a file

String Casting

ERR_NO_STRING_DATE5030No date in the string

ERR_WRONG_STRING_DATE5031Wrong date in the string

ERR_WRONG_STRING_TIME5032Wrong time in the string

ERR_STRING_TIME_ERROR5033Error converting string to date

ERR_STRING_OUT_OF_MEMORY5034Not enough memory for the string

ERR_STRING_SMALL_LEN5035The string length is less than expected

ERR_STRING_TOO_BIGNUMBER5036Too large number, more than ULONG_MAX

ERR_WRONG_FORMATSTRING5037Invalid format string

ERR_TOO_MANY_FORMATTERS5038Amount of format specifiers more than the parameters

ERR_TOO_MANY_PARAMETERS5039Amount of parameters more than the format specifiers

ERR_WRONG_STRING_PARAMETER5040Damaged parameter of string type

ERR_STRINGPOS_OUTOFRANGE5041Position outside the string

ERR_STRING_ZEROADDED50420 added to the string end, a useless operation

ERR_STRING_UNKNOWNTYPE5043Unknown data type when converting to a string

ERR_WRONG_STRING_OBJECT5044Damaged string object

Operations with Arrays

ERR_INCOMPATIBLE_ARRAYS5050Copying incompatible arrays. String array can be copied only to a string array, and a numeric array - in numeric array only

ERR_SMALL_ASSERIES_ARRAY5051The receiving array is declared as AS_SERIES, and it is of insufficient size

ERR_SMALL_ARRAY5052Too small array, the starting position is outside the array

ERR_ZEROSIZE_ARRAY5053An array of zero length

ERR_NUMBER_ARRAYS_ONLY5054Must be a numeric array

ERR_ONEDIM_ARRAYS_ONLY5055Must be a one-dimensional array

ERR_SERIES_ARRAY5056Timeseries cannot be used

ERR_DOUBLE_ARRAY_ONLY5057Must be an array of type double

ERR_FLOAT_ARRAY_ONLY5058Must be an array of type float

ERR_LONG_ARRAY_ONLY5059Must be an array of type long

ERR_INT_ARRAY_ONLY5060Must be an array of type int

ERR_SHORT_ARRAY_ONLY5061Must be an array of type short

ERR_CHAR_ARRAY_ONLY5062Must be an array of type char

Operations with OpenCL

ERR_OPENCL_NOT_SUPPORTED5100OpenCL functions are not supported on this computer

ERR_OPENCL_INTERNAL5101Internal error occurred when running OpenCL

ERR_OPENCL_INVALID_HANDLE5102Invalid OpenCL handle

ERR_OPENCL_CONTEXT_CREATE5103Error creating the OpenCL context

ERR_OPENCL_QUEUE_CREATE5104Failed to create a run queue in OpenCL

ERR_OPENCL_PROGRAM_CREATE 5105Error occurred when compiling an OpenCL program

ERR_OPENCL_TOO_LONG_KERNEL_NAME5106Too long kernel name (OpenCL kernel)

ERR_OPENCL_KERNEL_CREATE 5107Error creating an OpenCL kernel

ERR_OPENCL_SET_KERNEL_PARAMETER5108Error occurred when setting parameters for the OpenCL kernel

ERR_OPENCL_EXECUTE5109OpenCL program runtime error

ERR_OPENCL_WRONG_BUFFER_SIZE5110Invalid size of the OpenCL buffer

ERR_OPENCL_WRONG_BUFFER_OFFSET5111Invalid offset in the OpenCL buffer

ERR_OPENCL_BUFFER_CREATE5112Failed to create and OpenCL buffer

User-Defined Errors

ERR_USER_ERROR_FIRST65536User defined errors start with this code

Trade FunctionsThis is the group of functions intended for managing trading activities.Trading functions can be used in Expert Advisors and scripts. Trading functions can be called only if in the properties of the Expert Advisor or script the "Allow live trading" checkbox is enabled.FunctionAction

OrderCloseCloses opened order

OrderCloseByCloses an opened order by another opposite opened order

OrderClosePriceReturns close price of the currently selected order

OrderCloseTimeReturns close time of the currently selected order

OrderCommentReturns comment of the currently selected order

OrderCommissionReturns calculated commission of the currently selected order

OrderDeleteDeletes previously opened pending order

OrderExpirationReturns expiration date of the selected pending order

OrderLotsReturns amount of lots of the selected order

OrderMagicNumberReturns an identifying (magic) number of the currently selected order

OrderModifyModification of characteristics of the previously opened or pending orders

OrderOpenPriceReturns open price of the currently selected order

OrderOpenTimeReturns open time of the currently selected order

OrderPrintPrints information about the selected order in the log

OrderProfitReturns profit of the currently selected order

OrderSelectThe function selects an order for further processing

OrderSendThe main function used to open an order or place a pending order

OrdersHistoryTotalReturns the number of closed orders in the account history loaded into the terminal

OrderStopLossReturns stop loss value of the currently selected order

OrdersTotalReturns the number of market and pending orders

OrderSwapReturns swap value of the currently selected order

OrderSymbolReturns symbol name of the currently selected order

OrderTakeProfitReturns take profit value of the currently selected order

OrderTicketReturns ticket number of the currently selected order

OrderTypeReturns order operation type of the currently selected order

1. Variable names with auxiliary symbols for example. (Dot) All variables that have a point, or underscore - must now be changed to another name. Was: extern int Test.dot = 10; Became: extern int Testdot = 10;

Was: extern int Test_dot = 10; Became: extern int Testdot = 10;

The error that occurs when the wrong code: '.' - Semicolon expected

2. Declare variables are now more and variables that have been named for the new features - requires a change in name. Was: extern double char = 554.5; Became: extern double charnewexample = 554.5;

Was: double new = 10; Became: double neweample = 10;

The error that occurs when the wrong code: 'char' - unexpected token or 'new' - name expected

3. Each function should now have a return statement RETURN Was: int Testreturnint () { int a; int b; if (a == b) return (1); } Became: int Testreturnint () { int a; int b; if (a == b) return (1); return (0); }

Was: bool Testreturnbool () { int a; int b; if (a == b) return (true); }

Became: bool Testreturnbool () { int a; int b; if (a == b) return (true); return (false); }

Was: void Testreturnvoid () { int a; int b; if (a == b) return; }

Became: void Testreturnvoid () { int a; int b; if (a == b) return; return; }

Was: string Testreturnstring () { int a; int b; if (a == b) return ("43"); } Became: string Testreturnstring () { int a; int b; if (a == b) return ("43"); return (""); }

Warning that occurs when the wrong code: not all control paths return a value

4. Switsh function as an expression can only accept integers If earlier through switsh could sort out any value now, this operator can only take integers as a comparison to your function to work on, you must replace it with the comparison operators if else Was: int Testswitchdouble () { double k1 = 1.432; int y; switch (k1) { case 1.432: y = 1; break; case 1.433: y = 2; break; case 1.434: y = 3; break; } } Became: int Testswitchdouble () { double k1 = 1.432; int y; if (k1 == 1.432) y = 1; if (k1 == 1.433) y = 2; if (k1 == 1.434) y = 3; return (y); }

The error that occurs when the wrong code: 'k1' - illegal switch expression type and '1 .432 '- constant expression is not integral

5. All variables declared within a function must differ from the names of global variables (Optional) Warning that occurs when the wrong code: declaration of 'testvariable' hides global declaration

6. All variables must conform to the type used in functions If you display the Print or look like a string or object StringFind ObjectCreate You should accordingly write the correct type of the variable, or transfer the right type of variable Was: int test = 1; Print (AccountNumber ()); StringFind ("Example string", test); ObjectCreate (0, test, OBJ_LABEL, 0,0,0); Became: int test = 1; Print ((string) AccountNumber ()); StringFind ("Example string", (string) test); ObjectCreate (0, (string) test, OBJ_LABEL, 0,0,0);

In parentheses, you can specify the type of the variable that will be converted automatically

Was: int dg = MarketInfo (Symbol (), MODE_DIGITS); Became: double dg = MarketInfo (Symbol (), MODE_DIGITS);

Error or warning, which occurs when the wrong code: the second parameter for StringFind function must be a string - occurs after the compilation of the expert implicit conversion from 'number' to 'string' possible loss of data due to type conversion

7. Party libraries and functions, which include the transmission lines in the DLL If your expert has functions that have string variables in the new build should be translated into Unicode, is not difficult.

eg Was: # Import "wininet.dll" int InternetOpen A (string sAgent, int lAccessType, string sProxyName = "", string sProxyBypass = "", int lFlags = 0); int InternetOpenUrl A (int hInternetSession, string sUrl, string sHeaders = "", int lHeadersLength = 0, int lFlags = 0, int lContext = 0); # Import Became: # Import "wininet.dll" int InternetOpen W (string sAgent, int lAccessType, string sProxyName = "", string sProxyBypass = "", int lFlags = 0); int InternetOpenUrl W (int hInternetSession, string sUrl, string sHeaders = "", int lHeadersLength = 0, int lFlags = 0, int lContext = 0); # Import

Error that occurs when the wrong code: Error in call InternetOpenUrlA ()

8. Hard troubleshooting # property strict set this code at the beginning of your advisor and your advisor will give a lot of mistakes. These errors have passed a rigorous selection, and correcting them you will get maximum speed from your expert. And pure EA code

STEP1 Your HelloMQL5Tutorial Expert Advisor in 5 minutesWhat is an Expert Advisor?When I started I had no idea what an EA does. It is simply an automated piece of program code that can calculate. It does its calculations on a chart and it can tell you about market conditions, create buy or sell signals, send emails, make accoustic allert sounds to inform you that YOU can take a trade but more powerful is the ability to let it trade on YOUR rules.Here is a simple example!void OnTick() { int Spread; Spread=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD); Comment("Spread is "+Spread);}This if a full working EA. It will tell you how high the current spread is. If you drag it on an EURUSD chart and the price changes, you will see something like this:

show the spread on your chartin STEP2 you will see how to create it within 5 minutes or less.STEP2 Build the HELLOMQL5TUTORIAL expert advisor with MetaEditorHow to make it a working Expert Advisor for MetaTrader 5To use the code from STEP1 you must compile it. To do this please follow these steps1. Start Metatrader 52. Press the F4 key to bring up the MetaEditor3. Click on File -> New -> Expert Advisor4. Click on Continue and give it the Name Experts\HELLOMQL5TUTORIAL5. Click on Continue and ignore all the radio boxes for further functions6. Delete all the code in the text editor7. Replace it with this codevoid OnTick() { int Spread; Spread=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD); Comment("Spread is "+Spread); }Now press the F5 key to compile the Expert AdvisorIf everything went right, your MetaEditor window now should look like this

Compiled HELLOMQL5TUTORIALIn Step3 we are going to tell MetaTrader 5 that Expert Advisors should be allowed.STEP3 How to use your selfmade Expert Advisor in Metatrader 5How to get your Expert Advisor HELLOMQL5TUTORIAL to work for youExpert Advisors can take real trades that can produce real losses. For that reason they are disallowed by default. To make them work properly, you need to change thisHow to allow Expert Advisors in MetaTrader 51. Open MetaTrader 52. Press CTRL + O or click on Tools -> Options3. Check the option Allow automated trading on the Expert Advisors tab

Expert Advisor Trading must be allowed by the userIn STEP4 we are going to use your HELLOMQL5TUTORIAL Expert Advisor on a real chartSTEP4 how to use an Expert Advisor in Metatrader5To use an Expert Advisor you must attach it to a chart1. Please follow these steps:2. Open MetaTrader 53. Open the EURUSD chart4. Press CTRL+N or click on View -> Navigator to bring up the Navigator window5. Drag and drop the HELLOMQL5Tutorial Expert Advisor on the chartNow your chart should look like this

Drag and drop your Expert Advisor on the chartNow you should see the name of the EA in the upper right corner of the currency chart. Please notice that the price will have to change before you see the Spread in the upper left corner.In STEP5 we will use it in the strategy tester for backtestingWhat is a strategy tester and how can we use it?If you want to test your Expert Advisor when the markets are closed, there is no price change. And maybe you want to know, how well your trading strategy would have performed last night or in the last month. You use the builtin strategy tester in Metatrader 5 for all these scenariosHow to activate the Strategy Tester in Metatrader 5Please follow these steps:1. Open Metatrader 52. Press CTRL+R or click on View -> Strategy Tester to bring up the Strategy Tester3. Adjust the settings as in the screenshot below

Press CTRL+R to bring up the Strategy Tester windowWhen everything is set and done press the start button. It might take a few moments while Metatrader 5 is loading history data. In STEP6 we will see how to do a strategy test.STEP6 How to do a strategy testOur first real strategy test in MQL5In STEP5 we have adjusted the necessary settings and hit the start button.1. Have a little patience while MetaTrader loads the history data2. Watch out for a magnifying glass icon in your task bar3. Click that icon to open the Strategy Tester VisualisationNow you should see this window

You can start, stop or adjust the speed of your strategy test with the toolbarAfter you have started the strategy test, you can adjust the speed, pause or restart the test and you will see the spread lable change. But how do we actually buy or sell something? In STEP7 we are going to do that STEP6 How to do a strategy testSTEP 8 Define your order to buy or sell STEP7 How to buy something with your EAHow can we make an MQL5 EA buy something?Knowing the spread is nice, but how can we make a trade in MQL5?To start trading in MQL5 you need to understand what a MQLTradeRequest is. We are going to cover that in the advanced course in more detail. Basically it is all the data that you need to have when you place a trade by hand like the direction (Buy or Sell), the current price, the settings for StopLoss and TakeProfit and so on.Here is how to use the MQL5 Help to understand the MQLTradeRequest1. Open MetaTrader 52. Press F4 to open the MetaEditor3. Type in MqlTradeRequest4. Put your mouse cursor over that word and press F1Now you should see the context sensitive Help window come up

MQLTRADEREQUEST the data struct you need to know to open real trades in MQL5Congratulations! You have made it through the very basic part of this course. If you would like to continue you can sign up FOR FREE for the advanced part REAL MQL5 TRADESSTEP 8 Define your order to buy or sellHow do we open a Buy or Sell order?To open an order, you must understand how MQL5 does it.Basically MQL5 has a builtin OrderSend() function.Inside the Metatrader Help you will find this entryOrderSend()boolOrderSend(MqlTradeRequest&requestMqlTradeResult&result);

Okay, now we know that we have to handle a request and a result. But how can we put that knowledge into action?First we need to declare an MqlTradeRequest like this:MqlTradeRequest myrequest;Let's assume we want to buy what is on the current chart. It should be a market order of 0.1 Lot (not less) without a Stop Loss or a Take Profit. If price moves more than 20 points, we don't want to buy anymore.How do we translate that wish into programming code?There is a request type for that calledORDER_TYPE_BUYmyrequest.type = ORDER_TYPE_BUY;it should be a market ordermyrequest.action = TRADE_ACTION_DEAL;We want no StopLoss and no Take Profit nowmyrequest.sl =0 ;myrequest.tp =0 ;that order should only take place within a slippage of 20 pointsmyrequest.deviation =20;We want to buy what is on the current chartmyrequest.symbol = _Symbol;and we want only 0.1 Lotmyrequest.volume = 0.1;and if we get filled, we want only to get filled with the requestet LotSize all at once (Could come in handy once you start to trade a few thousand lots a day)myrequest.type_filling = ORDER_FILLING_FOK;That was not to hard to understand, was it?Another hint: you might need to add this code if you get the failed exchange buy invalid request errorZeroMemory(myrequest);ZeroMemory (myresult);In STEP9 we will create a complete function that does exactly what we wantSTEP9 How to build a real buy orderNow that we know how a buy order works, let's create oneI do also store the AccountEquity after I open a trade in a variable called LastEquity. That way I can compare the current equity with the equity after a trade and decide if I want to take another trade.Here is the codevoid OpenBuyOrder(){MqlTradeRequest myrequest;MqlTradeResult myresult;ZeroMemory(myrequest);myrequest.action = TRADE_ACTION_DEAL;myrequest.type = ORDER_TYPE_BUY;myrequest.symbol = _Symbol;myrequest.volume = LotSize; // fill in a double valuemyrequest.type_filling = ORDER_FILLING_FOK;myrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);myrequest.sl = 0 ;myrequest.tp = 0 ;myrequest.deviation =60;OrderSend (myrequest,myresult);LastEquity=AccountInfoDouble(ACCOUNT_EQUITY);}STEP10 How to build a real sell orderOur sell order is almost identical to the buy order in Step9The difference is, that we use the BID price this timevoid OpenSellOrder(){MqlTradeRequest myrequest;MqlTradeResult myresult;ZeroMemory(myrequest);myrequest.action = TRADE_ACTION_DEAL;myrequest.type = ORDER_TYPE_SELL;myrequest.symbol = _Symbol;myrequest.volume = LotSize; // use a double valuemyrequest.type_filling = ORDER_FILLING_FOK;myrequest.price = SymbolInfoDouble(_Symbol,SYMBOL_BID);myrequest.sl = 0 ;myrequest.tp = 0 ;myrequest.deviation =60;OrderSend (myrequest,myresult);LastEquity=AccountInfoDouble(ACCOUNT_EQUITY);}STEP11 How to get the highest candleThe highest candle can be useful for technical Expert AdvisorsIf you have ever read a book about technical chart analysis, you might know that it is all about new highs and new lows. To calculate the highest candle within the last x candles, you can use this simple code (simply paste into new and empty EA template)double HighestCandleM1;void OnTick() {HighestCandleM1= CheckForHighestCandle();Comment ("Number of the highest candle within the last 10 candles before the current candle: "+ HighestCandleM1); }double CheckForHighestCandle(){double High[];ArraySetAsSeries(High,true);CopyHigh(_Symbol,PERIOD_M1,0,11,High);double Calc1= ArrayMaximum(High,0,11);return Calc1;}Here is how it looks like

If you want to use it within you own EA, simply copy and paste the CheckForHighestCandle() function and add the two lines in the OnTick function into the appropriate place in your own code.Would you like to know the highest candle within the last 100 candles instead? Simply change the number 11 in the two lines above the linereturn Calc1;to 101.STEP12 How to get the lowest candleThe lowest candle can be useful for technical Expert AdvisorsIf you have ever read a book about technical chart analysis, you might know that it is all about new highs and new lows. To calculate the lowest candle within the last x candles, you can use this simple code (simply paste into new and empty EA template)double LowestCandleM1;void OnTick() {LowestCandleM1= CheckForLowestCandle();Comment ("Number of the lowest candle within the last 10 candles before the current candle: "+ LowestCandleM1); }double CheckForLowestCandle(){double Low[];ArraySetAsSeries(Low,true);CopyLow(_Symbol,PERIOD_M1,0,11,Low);double Calc1= ArrayMinimum(Low,0,11);return Calc1;}Here is how it looks like

If you want to use it within you own EA, simply copy and paste the CheckForLowestCandle() function and add the two lines in the OnTick function into the appropriate place in your own code.Would you like to know the lowest candle within the last 100 candles instead? Simply change the number 11 in the two lines above the linereturn Calc1;to 101.