forex.pm forex forum binary options trade - Forex - Algo Trading: How to Automate Trading Process and Avoid Human Mistakes
  • Welcome to forex.pm forex forum binary options trade. Please login or sign up.
 

Algo Trading: How to Automate Trading Process and Avoid Human Mistakes

Started by forex4you, Dec 08, 2022, 02:58 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

forex4you

Algo Trading: How to Automate Trading Process and Avoid Human Mistakes

<p class="MsoNormal text-align-start">Constant news monitoring, data analysis, patterns and price change tracking are part of a trader's routine that takes a long time, concentration, and much effort. This is challenging even for experienced traders.</p><p class="MsoNormal">To maximize profits, traders should react quickly, be mentally agile, and control emotions. Even simple fatigue can lead to trading losses. So automation of market analysis and data collection is a good way to save time and nerves and avoid human mistake factors. Traders who use automated systems and algorithms are called algo traders.</p><p class="MsoNormal text-align-start">What and why to automate?</p><p class="MsoNormal">Any process can be automated, from data collection and analysis to the latest events notifications (for example, via Telegram). Process automation allows traders to avoid human errors, spend more time for themselves or family, relax, and recover.</p><p class="MsoNormal text-align-start">How to start?</p><p class="MsoNormal">The MetaTrader platform provides the MQL programming language to automate most trading processes. Thanks to this specially adapted language, even beginners in programming can use the whole range of MetaTrader tools, from getting indicator signals to fully automated trading based on their algorithm.</p><p class="MsoNormal">The MQL4 and MQL5 languages corresponding to MetaTrader 4 and MetaTrader 5 differ from each other. For newbies in programming, it's better to start with MQL4 because you can even write a simple trading robot (EA - expert advisor) using this language. By the way, we recommend visiting the website page [<a href="https://www.mql5.com/" rel="follow">https://www.mql5.com/</a>] to find more articles, scripts, and other materials about algo trading and ask like-minded people any questions on the forum.</p><p class="MsoNormal text-align-start">MQL4 is simple</p><p class="MsoNormal">We'll demonstrate the simplicity of working with MQL4 by describing a simple robot (EA) in MQL4.</p><p class="MsoNormal">First, open an account with any of the brokers. We advise the FBS broker and their site <a href="https://ad.doubleclick.net/ddm/clk/545347123;354342054;z">FBS.com</a> due to its international licenses, good reputation, and favorable conditions for algo traders. When your account is opened, log in to it via MT4.</p><p class="MsoNormal">Open MT4 Trading Platform and follow these steps: In the Navigator window, find the Expert Advisor section, right-click, and select Create in MetaEditor. Next, select Expert Advisor (template) - Next - Specify a name (Expert\FirstEA, etc.) - Next - Next - Done. The MetaEditor code editor window will open.</p><p class="MsoNormal">Below is a full listing of the program, which you can copy into MetaEditor and click Compile. You will see that your EA named FirstEA (etc.) has appeared in the Expert Advisors section.</p><p class="MsoNormal">#property copyright "Copyright 2017, MetaQuotes Software Corp."</p><p class="MsoNormal">#property link      "https://www.mql5.com"</p><p class="MsoNormal">#property version   "1.00"</p><p class="MsoNormal">#property strict</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//| Expert initialization function                                   |</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">int OnInit()</p><p class="MsoNormal">  {</p><p class="MsoNormal">//---</p><p class="MsoNormal">//---</p><p class="MsoNormal">   return(INIT_SUCCEEDED);</p><p class="MsoNormal">  }</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//| Expert deinitialization function                                 |</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">void OnDeinit(const int reason)</p><p class="MsoNormal">  {</p><p class="MsoNormal">//---</p><p class="MsoNormal">  }</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//| Expert tick function                                             |</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">void OnTick()</p><p class="MsoNormal">   {</p><p class="MsoNormal">   if(iRSI(NULL,0,14,PRICE_CLOSE,0)>=70 && AmountSell()==0)</p><p class="MsoNormal">      {</p><p class="MsoNormal">      if (AmountBuy()>0) CloseBuy();</p><p class="MsoNormal">      OrderSend(Symbol(),1,0.01,Bid,0,0,0,"",0,0,0);</p><p class="MsoNormal">      }</p><p class="MsoNormal">   if(iRSI(NULL,0,14,PRICE_CLOSE,0)<=30 &&="" AmountBuy()="=0)</p><p class=" MsoNormal">      {</p><p class="MsoNormal">      if (AmountSell()>0) CloseSell();</p><p class="MsoNormal">      OrderSend(Symbol(),0,0.01,Ask,0,0,0,"",0,0,0);</p><p class="MsoNormal">      }     </p><p class="MsoNormal">   }</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//Close Sell orders function</p><p class="MsoNormal">void CloseSell()</p><p class="MsoNormal">   {</p><p class="MsoNormal">   for(int i=OrdersTotal()-1; i>=0; i--)</p><p class="MsoNormal">      {</p><p class="MsoNormal">      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;</p><p class="MsoNormal">      if(OrderType()==OP_SELL) OrderClose(OrderTicket(), OrderLots(),Ask,0,0);</p><p class="MsoNormal">      }</p><p class="MsoNormal">   }</p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//Close Buy orders function   </p><p class="MsoNormal">void CloseBuy()</p><p class="MsoNormal">   {</p><p class="MsoNormal">   for(int i=OrdersTotal()-1; i>=0; i--)</p><p class="MsoNormal">      {</p><p class="MsoNormal">      if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;</p><p class="MsoNormal">      if(OrderType()==OP_BUY) OrderClose(OrderTicket(), OrderLots(),Bid,0,0);</p><p class="MsoNormal">      }</p><p class="MsoNormal">   }   </p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//Counting the number of open Buy orders </p><p class="MsoNormal">int AmountBuy()</p><p class="MsoNormal">   {</p><p class="MsoNormal">   int amount = 0;</p><p class="MsoNormal">   for(int i = OrdersTotal() -1; i>=0; i--)</p><p class="MsoNormal">     {</p><p class="MsoNormal">      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))</p><p class="MsoNormal">        {</p><p class="MsoNormal">         if (OrderType()==OP_BUY)</p><p class="MsoNormal">            amount++;</p><p class="MsoNormal">        }</p><p class="MsoNormal">     }</p><p class="MsoNormal">   return(amount);</p><p class="MsoNormal">   } </p><p class="MsoNormal">//+------------------------------------------------------------------+</p><p class="MsoNormal">//Counting the number of open Sell orders  </p><p class="MsoNormal">int AmountSell()</p><p class="MsoNormal">   {</p><p class="MsoNormal">   int amount = 0;</p><p class="MsoNormal">   for(int i = OrdersTotal() -1; i>=0; i--)</p><p class="MsoNormal">     {</p><p class="MsoNormal">      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))</p><p class="MsoNormal">        {</p><p class="MsoNormal">         if (OrderType()==OP_SELL)</p><p class="MsoNormal">            amount++;</p><p class="MsoNormal">        }</p><p class="MsoNormal">     }</p><p class="MsoNormal">   return(amount);</p><p class="MsoNormal">   }</p><p class="MsoNormal">Try to start your EA on your account by moving it to the chart. You also need to activate the AutoTrading button (at the top of MT4) and allow automated trading in the Tools - Options - Expert Advisors -  Allow automated trading settings.</p><p class="MsoNormal">Now, if the value of the RSI (Relative Strength Index) indicator is below 30, a Buy order with a volume of 0.01 is opened, while an opened Sell order is closed. If the indicator value is above 70, a Sell order with a volume of 0.01 is opened, while an opened Buy order is closed. That's it! We launched a trading robot based on the values of the RSI indicator.</p><p class="MsoNormal text-align-start">What does a code mean?</p><p class="MsoNormal">Let's understand the code's structure. The code consists of one main function and several auxiliary functions. </p><p class="MsoNormal">The main function is OnTick() which executes its code (inside curly braces) every tick. A tick is an event when the instrument price direction changes. OnTick() is the main function where other functions are called to help perform special actions, such as closing and counting opened Sell and Buy orders.</p><p class="MsoNormal">Auxiliary functions are:CloseSell() - closes all Sell ordersCloseBuy() - closes all Buy ordersAmountSell()- counts all Sell ordersAmountBuy()- counts all Buy orders</p><p class="MsoNormal">Imagine your TV is broken, and you call a specialist to fix it because you don't know the TV mechanisms, but a specialist knows everything about fixing the device. It means this specialist serves a particular function for you - a TV repair. Similarly, the main function calls OnTick() auxiliary functions to perform certain actions.</p><p class="MsoNormal">if(iRSI(NULL,0,14,PRICE_CLOSE,0)>=70 && AmountSell()==0)</p><p class="MsoNormal">The above code literally means the following: if the value of the RSI indicator is greater than or equal to 70 and the number of opened Sell orders is 0. To avoid opening more than one Sell order, we call for the "AmountSell" function, which only counts the number of opened Sell orders. </p><p class="MsoNormal">Then we check if there are open Buy orders, and if there are (greater than 0), then we close them:</p><p class="MsoNormal">if (AmountBuy()>0) CloseBuy() </p><p class="MsoNormal">Here, we call the CloseBuy() function that helps us to close Buy orders. This function only performs the closing Buy orders, nothing else.</p><p class="MsoNormal">Then, we open a Sell order:</p><p class="MsoNormal">OrderSend(Symbol(),1,0.01,Bid,0,0,0,"",0,0,0);</p><p class="MsoNormal">Similarly, we write a condition for opening a Buy order:</p><p class="MsoNormal">if(iRSI(NULL,0,14,PRICE_CLOSE,0)<=30 &&="" AmountBuy()="=0)</p><p class=" MsoNormal">The above condition similarly checks the value of the RSI indicator, and if it is less than 30, then Sell orders are closed and Buy orders are opened, i.e., actions described in curly brackets below.</p><p class="MsoNormal">It's not that hard, is it?</p><p class="MsoNormal">To get more information on the functions provided by the MQL4 language, choose the function you are interested in and press F1. There you will find relevant documentation and descriptions of all features.</p><p class="MsoNormal text-align-start">About FBS </p><p class="MsoNormal"><a href="https://ad.doubleclick.net/ddm/clk/545347123;354342054;z">FBS </a>is an international licensed broker (IFSC license) providing global markets with transparent and reliable services and products for professional and semi-professional CFD and Margin FX traders. With its solid experience of 13 years, high-quality services, and dozens of awards, FBS conquered the trust of 27M+ clients and became the Official Principal Partner of Leicester City Football Club.</p>

This article was written by Finance Magnates Staff at www.financemagnates.com.

Source: Algo Trading: How to Automate Trading Process and Avoid Human Mistakes
Forex4you offers wide range of trading accounts with DDE, NDDE and STP executions including more than 100 instruments. Forex4you is based on MetaTrader 4 trading platform. Clients have the advantage of daily technical and fundamental analysis, one-click trading, economic calendar, mobile trading applications, news and forecasts from Dow Jones (UK) and signals from Trading Central (US). In addition, Forex4you offers Forex dictionary, educational materials and lot of "How to" guides about Forex.

forex4you.com   share4you.com   betiforex.com Forex  beginners-guide-to-iq-option-complete-review forex4you review forex4you Forex4you Review - One of the Best Forex Brokers Forex4you Review - One of the Best Forex Brokers forex4you - PAMM forex broker review and feedback from traders forexbinaryoption.ae aroundworld24.com  Affiliate programs  Forex4you Affiliate programs   



forex4you.com