EA intelligent trading system using the introduction (detailed)
read:2023/2/24 18:42:54

File placement instructions ¤Indicators mq4, ex4 files copied to the indicators directory of the subdirectory of the experts directory ¤cashback forex automatic forex trading accounts mq4, ex4 files copied to the experts directory ¤tpl files are template files, copy to templates directory ¤DLL files are library files, copy to libraries subdirectory of experts directory ¤SET files are setup files, copy to presets subdirectory of experts directory ¤pdf, txt, doc file for the description of the document, you can directly open to read EA use method as an extension of the foreign exchange trading, the use of intelligent trading system (EA) instead of manual trading seems to become a new trend, so how to use the EA intelligent trading system in MT4? First, of course, you have to have an EA, and must be ex4 as the extension, if it forextradingaccountstype only mq4 file, please use MetaTrader comes with the editor MetaEditor to open, mq4 through the compile (compile), and to not error, in order to get a folder under the original storage mq4 with the same name Copy the file with the ex4 suffix to the folder where MetaTrader4 is located under the experts folder, for example: D:/MetaTrader/experts, close and reopen MetaTrader4. point profit system for example, point attached to the chart, such as: four, will appear the following pop-up window: pay special attention to the selection here, if not tick to allow real-time automatic trading, then your intelligent system will not automatically trade five, in terms of automatic transactions, MT there is a general switch, is the Tools menu under the options: six, there is another place must be selected Start: The last of the above chart becomes this is has started the intelligent trading system seven, after completing all the above settings, look at the upper right corner of your chart must appear your intelligent trading system file name and a smiley face appear so even if the current chart has enabled the intelligent trading system at this point, you can go spend the day waiting for If you want to stop your smart trading system, the best way is to click on the smart trading icon above this chart, but then all your charts above the smart trading will stop all the smilies in the upper right corner of the charts have turned into forks If you just stop the EA on the current chart, you should press F7 If you want to stop the EA on top of the current chart, you should press F7 and the following window will pop up: Click to remove the hook in front of Allow Real Time Auto Trading and then OK, so that the EA on top of the current chart will stop The crying face will appear on top of the chart: And if you want to completely eliminate the EA on top of the current chart, first right click on the chart area, there will be a Click on Intelligent Trading System, then after Click to eliminate, this EA will be removed from the top of the current chart, the upper right corner of the chart will be nothing Attachment: Introduction to EA EA that is ExpertAdvisors abbreviation Chinese meaning expert advisors, commonly known as intelligent trading system, is a computer simulation of the traders order operation for the process of automatic machine trading nbsp; A manual trading process Here we take the MT4 foreign exchange client as an example, first of all to analyze a foreign exchange trader manual foreign exchange trading operation process: the steps are as follows: 1. open the foreign exchange trading client, select a currency pair chart; 2. monitor the K-line trend chart of the currency pair, commonly known as staring, looking for the time to open or close a position, that is 3. If the conditions are met, place an order to open a position (long or short) or close a position 4. Repeat step 2, continue to stare at the market, assuming that the second step is to open a position, that is, to find the conditions for closing a position 5. If the conditions for closing a position are met, close the operation, calculate profit and loss accounting to complete a cycle of transactions 6; 5 steps 7. If not trading, exit the foreign exchange client Second, the machine manipulation process Based on the above analysis, we already know that a complete intelligent trading system (commonly known as EA) in operation after the basic functions that must be achieved, is the above manual operation of 1-5 steps which is the basic working process of intelligent trading system, so the working principle of intelligent trading system is by the programmer with the help of a computer programming language, by writing program trading instructions to simulate the behavior of human traders to place orders to achieve the process of automatic machine trading the main execution process can be divided into: stare - > open positions - > stare again - > close positions, so the cycle of execution process on the platform that supports automatic machine trading, the current foreign exchange market Popular on the MetaQuotes companys MT4 platform, because this platform is embedded in a MQL4 language, which provides access to server-side data and can carry out trading operations interface, program traders can write their own automatic trading system according to their own trading strategies, so as to achieve the automatic trading of machines, both to reduce the workload of humans and to overcome human But the current EA development, still in the early start-up phase, some still have defects, but I believe that with the development of technology, automatic machine trading will eventually gradually replace the human manual operation will then give traders a new choice Third, the relevant MQL language knowledge In order to achieve machine operation, and then look at the required MQL4 language related to the Knowledge: 1. master the basic syntax of the MQL4 language and the composition of the program, and the running process For the syntax part, please refer the reader to the relevant information, which is omitted here Regarding the composition of the program, for an intelligent trading system EA program: the main three functions are: init(): the initialization function, responsible for program variables and data initial input; only once when the program is called in, generally do not need to rewrite the content deinit (): counter-initialization function, responsible for the program exit, the data from memory clear; only once when the program exit, execute, generally do not need to rewrite the content start (): start function, that is, the main function of the program, responsible for the EA program all transaction execution process, in fact, he is an EA transaction management and execution function every certain time, generally within a few seconds, executed once, that is, cyclic execution, until the program is terminated when it exits running process: after starting EA, the programs INTI () start executing once, --> then START () cyclic execution ---> finally exit EA when deinit() is executed once 2. mql4 with trading-related trading functions: open function: intOrderSend(stringsymbol,intcmd,doublevolume,doubleprice,intslippage, doublestoploss,doubletakeprofit,voidcomment,voidmagic,voidexpiration,voidarrow_color) This function is mainly applied to open positions and pending transactions parameters: symbol -currency pair cmd-purchase method volume-purchase lots price-close price slippage-maximum allowable slippage stoploss-stop loss level takeprofit-win level comment-notes text magic-order specified code can be used as user specified identification code expiration-order valid time (pending orders only) arrow_color-arrow color on the chart if the parameter is missing or exists CLR_NONE price value will not be drawn in the chart Close function: boolOrderClose(intticket,doublelots,doubleprice, intslippage,voidColor) the order to close the operation if the function succeeds, the value returned is true if the function fails, the value returned is false to get detailed error information, see GetLastError() function parameters: ticket - order number lots - lots price-closing price slippage-maximum number of points Color-chart marker color If the parameter is missing, CLR_NONE value will not be drawn in the chart OrderModify function: boolOrderModify(intticket,doubleprice, doublestoploss,doubletakeprofit,datetimeexpiration,voidarrow_color) for the previous open or pending order to modify the characteristics if the function succeeds, the value returned is TRUE if the function fails, the value returned is FALSE to get the detailed error information, see GetLastError() function parameters: ticket-order number price-closing price stoploss-new stop level takeprofit-new win level expiration-pending order valid time arrow_color-allowed in the chart for stop/win If the parameter is missing or there is a CLR_NONE value, it will not be displayed on the chart Fourth, the source code of the trading process analysis The following source code is a moving average based intelligent trading system code, the entire program is very simple but the EA function is very complete, to achieve a completely automated by the computer to place orders and close positions, the entire program only uses a START() function to achieve program code analysis see the relevant comments in the code //+------------------------------------------------------------------+ //---- inputparameters externdoubleTakeProfit=20; externdoubleStopLoss=30; externdoubleLots=2; externdoubleTrailingStop=50; externintShortEma= 5; externintLongEma=60; //+------------------------------------------------------------------+ //|expertinitializationfunction| //+-- ---------------------------------------------------------------+ intinit() forextradingaccountsregister //---- //---- return(0); } //+------------------------------ ------------------------------------+ //|expertdeinitializationfunction| //+-------------------------------------------------------- ----------+ intdeinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expertstartfunction| //+------------------------------------------------------------------+ intstart() { intcnt,ticket,total; doubleSEma,LEma; //---- if(Bars<100) { Print(barslessthan100); return(0); } //---- if(TakeProfit<10) { Print(TakeProfitlessthan10); return(0);//checkTakeProfit } //---- SEma=iMA(NULL,0,ShortEma,0,MODE_EMA,PRICE_CLOSE,0); LEma=iMA(NULL,0,LongEma,0,MODE_EMA,PRICE_ CLOSE,0); //---- staticintisCrossed=0; isCrossed=Crossed(LEma,SEma); //---- total=OrdersTotal(); if(total<1) { if(isCrossed==1)//meet short position condition , open short position { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point, Bid-TakeProfit*Point,EMA_CROSS,12345,0,Green); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print(SELLorderopened:,OrderOpenPrice()); }else Print(ErroropeningSELLorder:, GetLastError()); return(0); } if(isCrossed==2)//meet the multiple position condition, open multiple positions { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point, Ask+ TakeProfit*Point,EMA_CROSS,12345,0,Red); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print(BUYorderopened:, OrderOpenPrice()); }else Print(ErroropeningBUYorder:,GetLastError()); return(0); } return(0); } return(0); } //---- order modification to achieve dynamic stop-loss tracking for(cnt=0;cnt< total;cnt++) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()) { if(OrderType( )==OP_SELL)//longpositionisopened { //checkfortrailingstop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if( OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid-Point*TrailingStop, OrderTakeProfit(), 0, Green); return(0); } } }else//gotoshortposition { //checkfortrailingstop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point* TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop))) { OrderModify(OrderTicket(),OrderOpenPrice(), Ask+Point*TrailingStop , OrderTakeProfit(),0,Red); return(0); } } } } } } //---- return(0); } //+------------------------------------------------------------------+ / / / Moving average long/short condition judgment, intCrossed(doubleline1,doubleline2) { staticintlast_direction=0; staticintcurrent_direction=0; / / Dont workinthefirstload, waitforthefirstcross! staticboolfirst_time=true; if(first_time==true) { first_time=false; return(0); } //---- if(line1>line2) current_ direction=2;//up long market up through do long if(line1<line2) current_direction=1;//down short market down through do short //---- if(current_direction!=last_direction)//changed long/short change{ last_direction=current_direction; return(last_direction); elsereturn(0);//notchanged } V. The conclusion of this paper From the above analysis, we can know that the so-called EA, is a computer simulation The specific steps are as follows: 1. When the user opens the foreign exchange client program, by the client program to call the user in the system has been preset EA trading system program 2. Repeat step 2, continue to monitor the market, assuming that the second step is to open a position, that is, to find the conditions for closing a position 5. If the conditions for closing a position are met, close the position operation, calculate profit and loss accounting to complete a trading cycle 6. If you continue to trade, EA repeat 2-> 3-> 4-> 5 steps 7. Set to disable the EA, or exit the Forex client