17.10.2021

How to limit the trading time of Forex advisors? Buy limit and set limit at the right time Installation and configuration


You have probably noticed that transactions on certain days or even hours bring a loss. For example, it can be transactions on Friday evening, the result of which, when transferred through the weekend, is often unpredictable. How to be? Manually enable and disable the adviser? This is not very convenient, and we are all human - you can just forget to do it.

Problem Solving - Assistant Advisor Trade Scheduler, which allows you to limit the time of work of other Expert Advisors according to the schedule set by the trader. For example, you can restrict robot trading from 7 a.m. to 11 a.m. Monday. This development is from our friends from ArgoLab and today we will get acquainted with it in detail.

Statistics analysis

Before limiting the work of the adviser, you must first determine at what time the strategy gives up. To do this, you can use one of the monitoring services, such as myfxbook, which gives detailed trading statistics over time. In order for the analysis to be reliable, it is desirable to have trading statistics for at least three months.

So, for starters, you need to start monitoring on myfxbook. For information on how to do this, see our website. . For example, let's take the monitoring of an adviser Forex Hunter.

You can also upload a report from the strategy tester to the site. First of all, this is necessary for those who do not yet have enough accumulated history on a real account, but there is a robot that can be tested in the tester. How to do this, again, read inseparate article .

Further, after the monitoring has been loaded and processed, go to the extended statistics section, to the “Daily” tab. It displays the number of profitable and losing trades by day of the week. As you can see, on Thursday and Friday the largest relative number of losing trades is 73% and 74%, respectively. This means that the market conditions these days are not suitable for this strategy, the forecasts are less accurate and the EA is losing money. To improve the efficiency of the automatic strategy, it is reasonable to remove these days from trading.

Then we look at the statistics by the hour. The arrows in the screenshot mark the hours with the largest number of losing trades. In addition to the fact that during the night period (mainly the Asian session) there are not only much fewer transactions than in the middle of the day, but the quality of entries also leaves much to be desired.

This means that if we block the work of the Expert Advisor on Thursday and Friday, leaving it to work on other days from 11 am to 7 pm, the result is guaranteed to improve.

The EA settings for changes in this example will look like this:


Installation and setup

The advisor is installed in a standard way. Open the terminal data directory via File - Open data directory, and go to the MQL4 - Experts directory. Here we copy the previously downloaded Expert Advisor file with the “.ex4” extension. To make the Expert Advisor appear in the Navigator window, restart the terminal.

In the settings, you need to specify the operating time according to the days of the week. There are three input parameters for each day. The first one is responsible for enabling/disabling trading on a certain day, the second - for the start time of trading, the third one - for the end of trading. Time can be specified to the nearest minute. The start time can be greater than the end time, such as 19:00 and 9:00. In this case, trading will be allowed from 00:00 to 9:00 and from 19:00 to 24:00.

The additional CloseBeforeSwitchOFF parameter is responsible for closing all positions immediately before turning off autotrading. In total, the parameter can take three values: No - positions are not closed; CloseAllProfitable - only profitable ones are closed; CloseAll - exit from all open positions. The slip parameter is responsible for the maximum slippage.


Don't forget to enable autotrading and import functions from DLL libraries.

The time must be specified, focusing on the terminal time, which is displayed in the title of the Market Watch window. It's your broker's time.

Also, do not try to install multiple instances of the advisor on one account - just one instance is enough. Otherwise, none of them will work correctly.

Conclusion

Time limiting is the easiest and most effective way to improve your trading performance. For example, if the adviser consistently merges from 4 to 8, then there is a different pattern on the market, which the robot cannot handle. Just not trading during this period - you increase the overall profitability and unload the deposit from unnecessary transactions.

Forum thread

Sincerely, Alexey Vergunov
TradeLikeaPro.ru

Source http://tradelikeapro.ru/sovetnik-tradescheduler/

Today we will talk about the Trade Scheduler robot, which has a very interesting feature. When using automatic systems in Forex trading, have you noticed that on certain days of the week or hours they often bring losses? For example, on the first day of the week, the adviser opens very few trades, and most of them are also unprofitable. In such cases, it makes sense to turn off the adviser before Saturday and turn it on on Tuesday. You can carry out this simple operation manually, but it is also easy to forget to turn off or turn on the adviser at the right time.

The solution to this problem (and a couple of others) can be robot use Trade Scheduler, which does not trade itself, but allows you to limit the time of work of other Expert Advisors according to the schedule, based on the analysis of the work of these Expert Advisors.

Before making adjustments to the temporary mode of operation, it is necessary to find out at what moments it often trades in the red. In this case, the MyFXbook service will be of help, where detailed statistics of the system's trading by days of the week and hours are presented. The optimal trading period for analyzing the operation of the system is 3 months. To conduct it, you need to start monitoring on the service. You can read about installing a robot on MyFXbook. As an example, let's consider the results of the work of the Expert Advisor, the monitoring of which can be found by clicking on the picture:

Rice. 1. Monitoring the operation of the Transient Zones 2.0 Expert Advisor on the MyFXbook service.

As an option for those who do not yet have enough trading history of the robot to analyze it on a real account, but at the same time it can be tested, feel free to upload the report obtained from .

After loading and processing the monitoring, you need to go to the extended statistics section, the Daily tab. Here you can find information on the relative amount by day of the week. In our example, the largest number of losing trades falls on Thursday and Friday, which means that it would be reasonable to suspend the Expert Advisor on these days. The reason for this behavior may lie in the state of the market, which these days is not suitable for the strategy of the robot, and its calculations are less accurate:


Rice. 2. The ratio of profitable and unprofitable transactions of the Transient Zones 2.0 Expert Advisor for the week.

After analyzing by day, you can analyze the effective work by hours. To do this, go to the Hourly tab and see when the relative number of losing trades is greater:


Rice. 3. The relative number of losing and profitable trades by hours.

Conclusion: it would be reasonable to stop the trading process on Thursday, Friday, and for other days to block its work in the first two hours of a new day, and during the day during those hours when losing trades prevail - in particular, at 12, 13, 14 hours of the day . That is, leave him to work at night from 2 to 8 in the morning inclusive, and from 13 to 21 in the afternoon. The result of the adviser's work should improve significantly.

Installing and configuring the expert.

The installation of the Trade Scheduler auxiliary adviser is carried out by analogy with any other adviser, more about this is written in . You can download the archive with the expert from the link below:

Download trade-scheduler.rar (downloads: 139)

Unzip the trade-scheduler.rar archive, copy the TradeScheduler v2.3.ex4 expert file to the data_folder\MQL4\Experts\ folder. To open the data catalog, select the Open data catalog item from the File menu. Then the terminal restarts and after that the adviser can be found in the Navigator - Expert Advisors window.

When installing an Expert Advisor on a chart, the required time of work is set in the settings window by days of the week and hours. The time is set depending on the time of the terminal, it is also the time. There are 3 input parameters for each day. The first parameter is responsible for enabling/disabling the robot on a specific day of the week, the second parameter is for the trading start time, and the third is the stop time. The time is specified in the format hours: minutes:


Rice. 4. Input parameters set after the analysis of the Expert Advisor.

Also in the settings there is an additional parameter CloseBeforeSwitchOFF . If set to CloseAll, all trades will be closed automatically before the robot is turned off. If CloseAllProfitable - only profitable orders will be closed, if No - trades will not be closed. The parameter Slip is responsible for the maximum allowable slippage.

Make sure that autotrading and import of functions from DLL are allowed in the terminal. One version of the advisor is installed for one terminal.

Conclusion.

Want to improve performance your adviser? Try the method of limiting its work and analyze the results. If the statistics show that your Expert Advisor "constantly merges" at a certain time of the day, it means that there is a pattern on the market that it cannot handle. Stop trading during this unfavorable period and increase its profitability!

If your trading system is not based on news jumps, then it can be very beneficial for financial and mental health to stop the adviser before the release of important news. And after the volatility settles down, after a few hours, turn it on again. It's good if you have access to a working terminal at hand. And if not? This is where automation comes in handy.

One of the options for solving our problem is to compile a file with a schedule of important events. Reading this file by our expert, and determining when it is possible to work and when not. The MQL4 tutorial provides an example of working with a csv text file, which we will take as a basis, getting rid of a couple of mistakes that the authors made unintentionally or in order to test our attentiveness (which they themselves warn about - you should not blindly believe anyone, mistakes happen always).

So, let's make a schedule of important events for next week in the following format:
Event date and time; tool; event description

2016.04.01 14:00;USD;ISM business activity index in the manufacturing sector 2016.04.01 14:00;USD;Inflation gradual acceleration index from ISM 2016.04.04 09:00;EUR;Producer price index (mom) 2016.04. 04 09:00;EUR;Producer Price Index (YoY) 2016.04.05 04:30;AUD;Reserve Bank of Australia Interest Rate Decision 2016.04.05 04:30;AUD;Accompanying Statement of the Reserve Bank of Australia 2016.04.06 07: 00;EUR;ECB meeting 2016.04.06 18:00;USD;Minutes of the meeting of the Open Market Committee of the US Federal Reserve 2016.04.07 11:30;EUR;Information on the ECB meeting on monetary policy

Let's write it to the ht-news.csv file and place it in the required directory \MQL4\Files\ht-news.csv, from where our EA can read it.

First, let's set external variables for configuration, comments explain their purpose:

Extern string startNewsEvent="Restriction of work on news"; input bool StopOnNewsEvent=true; //Enable constraint input string NewsEventFileName="ht-news.csv"; //Schedule file input uint LoadNewsEventTimerInDay=7;//How often in days to reload the file input uint StopPriorEventHours=2; //Stop X hours before the event input uint StartAfterEventHours=3; //Start X hours after the event extern string stopNewsEvent="----------------";

The following structure will help us access the description of the handled event:

Struct NEWS_EVENT ( datetime EventTime; //time of event occurrence string Instrument; //event instrument string EventComment; //event comment );

Custom function for reading information from a file

Bool LoadNews() ( int handle; // File descriptor string instrument, // Event currency name firstInstrument,secondInstrument, // 1st and 2nd parts of the name of the current pair eventComment, // Event description text stringDateTime; // String expression of the date and time of the event datetime eventDateTime; // Date and time of the event in datetime format handle=FileOpen(NewsEventFileName,FILE_CSV|FILE_READ,";");// Open file if(handle<0) // Неудача при открытии файла { int lastError=GetLastError(); if(lastError==4103) // Если файла не существует, сообщим Alert("Нет файла с именем ",NewsEventFileName); else // При любой другой ошибке Alert("Ошибка при открытии файла ",NewsEventFileName," :",lastError); PlaySound("Bzrrr.wav"); // Громко ругнемся и вернем фалсе return false; } int cnt=0; while(FileIsEnding(handle)==false) { stringDateTime =FileReadString(handle);// Дата и время события instrument=FileReadString(handle); //Инструмент eventComment =FileReadString(handle);// Текст описания события, может не быть eventDateTime =StrToTime(stringDateTime); // Преобразование типа данных firstInstrument=StringSubstr(Symbol(),0,3);// Извлекаем первые 3 символа secondInstrument=StringSubstr(Symbol(),3,3);// Извлекаем вторые 3 символа if(StringCompare(instrument,firstInstrument,false)!=0 && StringCompare(instrument,secondInstrument,false)!=0) { continue; //не наши инструменты } cnt++; ArrayResize(NewsEvent,cnt,1000); //изменяем размер массива с запасом для ускорения ArrayResize(NewsEventTime,cnt,1000); NewsEvent.EventTime= eventDateTime; NewsEvent.Instrument=instrument; NewsEvent.EventComment=eventComment; NewsEventTime=eventDateTime; //удобнее искать в одномерном массиве } FileClose(handle); // Закрываем файл ArraySort(NewsEventTime,WHOLE_ARRAY,0,MODE_ASCEND); //сортируем массив для последующего поиска return true; }

We search for the required time in the NewsEventTime array, and if the time is found, we will get its description from the array of the NewsEvent structure

String GetEventInfo(datetime date) ( for(int i=0;i

Helper function to determine if the current time falls within the idle period

//check if it is necessary to disable the advisor on the news True - we are working False - we are resting bool CheckEnableNewsWork() ( if (ArraySize(NewsEventTime)==0) return true; //for some reason, the schedule array turned out to be empty, so we are working //now you need to find the nearest date in NewsEventTime before which you need to stop work for StopPriorEventHours hours datetime timeCurrent =TimeCurrent(); datetime timeStopWork=timeCurrent+StopPriorEventHours*3600; //If NewsEventTime has a time less than timeStopWork, then stop working int dateindex= ArrayBsearch(NewsEventTime,timeStopWork,WHOLE_ARRAY,0,MODE_ASCEND); datetime foundEventTime=NewsEventTime; timeStopWork=foundEventTime-StopPriorEventHours*3600; //calculate the stop time from the found time datetime timeStartWork=foundEventTime+StartAfterEventHours*3600; //this is the rest end time / /now check if we are now timeCurrent between timeStopWork and timeStartWork, if yes then don't work if (timeCurrent>=timeS topWork && timeCurrent<=timeStartWork) { DrawLabel("EnableNewsWork","Не работаем, новость: "+GetEventInfo(foundEventTime)+"",5,80,Red); return false; } else { DrawLabel("EnableNewsWork","Нормальная работа, новостей нет",5,80,Green); return true; } }

To periodically read from the schedule file, we need a timer that runs for example once a week, as configured

//Check for the presence of a file with news by timer void OnTimer() ( if (StopOnNewsEvent) ( LoadNews(); //read the file ) )

When initializing the adviser, you need to start the timer and read the news for the first time

OnInit() .... if (StopOnNewsEvent) //If set, load the news file ( bool tm=EventSetTimer(LoadNewsEventTimerInDay*86400); //start the timer to load the schedule file if (!tm) Alert("EventSetTimer error :",GetLastError()); OnTimer();//First run immediately )

In each tick, we check if we can open positions. By the way, this should not affect the trailing.

OnTick() .... bool enableNewsWork=true; //you can work on news events if (StopOnNewsEvent) ( enableNewsWork=CheckEnableNewsWork(); //If the limit is on news, check the time ) if (HaveMoney && enableNewsWork) Traiding(Pairs); //checking the conditions and opening a trade on the pair

That's all. Unfortunately, I have not yet tested this code on a real account, since I wrote it on weekends, emulated ticks with a timer, and changed the current time, which stops on weekends, manually. But next week I'll have a look in real life, in the new version of "Forex Grail 1.11", where I built the above code.

In the future, it may be necessary to make a convenient utility for generating the ht-news.csv file, for example, in the same

This Expert Advisor is ideal for those who trade by levels and any strategies using pending limit orders. The EA will place orders at the right time at the right distance from the current price! In the robot settings, you can set stop losses, take profits of orders, as well as the lot of each order. Everything is set for each order separately. You can only place buy limit, or sell limit, or both orders together!

The adviser is ready to work on any trading instrument, in any Metatrader 4 trading terminal. The robot is also ready to work on several currency pairs at once. That is, you can open any number of pairs and install an adviser on them, setting each one with its magic number and time settings. After that, each pair will work strictly individually. If you are still working with limit orders manually, this robot is for you!

  • BUY_limit- Whether to place an order to buy a limit.
  • lot_buy_limit- Lot orders buy limit.
  • R_buy_limit- Distance from the current price to the buy limit order in points.
  • Stop_Loss_buy_limit- Stop loss buy limit orders.
  • Take_Profit_buy_limit- Take profit buy limit orders.
  • SELL_limit- Whether to set a sell limit order.
  • Lot_sell_limit- Lot orders sell limit.
  • R_sell_limit- Distance from the current price to the sell limit order in points.
  • stop_loss_sell_limit- Stop loss orders sell limit.
  • Take_Profit_sell_limit- Take profit orders sell limit.
  • slippage- Maximum slippage in points.
  • Close_Orders- Closing the second order when opening the first one.
  • Times- Order lifetime in minutes.
  • Time_Start- Set orders on time?
  • Time_Hour- Hour of opening orders 0-23
  • Time_Minute- Minute of opening orders 0 - 59. For example, hour = 5, minute 40, so at 5.40 orders will be placed from the price at that moment.
  • Expert_I- magic number to determine your orders and multi-currency trading.

Achieving success in the forex market today is almost impossible to take into account the stable patterns of price behavior, which can be expressed in any of its actions.

One of such striking patterns, which is familiar to almost every trader, is manifested in the activity of the price at a certain time of the day.

Actually, that is why most advisers and trading strategies today are endowed with a trading filter by time, when a trader prohibits trading on a strategy in an unfavorable time period.

Trade high only with a leading broker

However, the time factor can often be a signal pattern, and the trader needs to implement it somehow.

It is natural to constantly be at the monitor at a certain time with an accuracy of seconds in order to open the planned position is not always possible.

That is why traders use special scripts and advisors that allow you to open a position at a specified time for them. Actually, we will get acquainted with one of these advisers in this article.

The OpenTime 2 Time Advisor is a completely independent trading expert for the MT5 trading terminal, which allows you to implement strategies based on the patterns of price movement at a certain time of the day.

A notable feature of OpenTime 2 is the fact that the functionality of the robot allows you to make it a completely independent expert and find patterns of price movement on a particular asset using optimization.

Thus, a trader can create strategies based on time patterns, as well as use it as an assistant to implement their ideas, for example, to open deals during news releases (trading on expectations).

Installing the script on the chart.

The first version of the Time Advisor for the MT5 trading terminal was developed back in 2017, however, the functionality of the robot was so limited that it could be safely attributed to simple scripts rather than full-fledged robots.

However, after expanding the functionality in 2018, following the recommendations of many traders, the robot not only gained popularity, but two versions of it were published in the official library of MT5 developers.

Thus, the adviser can be installed in two ways, namely through the library in your MT5, or through the data directory according to the standard scheme.

To install an adviser through the library, launch your MT5 trading terminal and move to the "Tools" panel, where you can find information on your positions and balance.

Then move to the "Library" tab and perform a simple sorting so that only advisers appear in the list.

After you sort the list, find the OpenTime 2 time adviser in it and load it using the additional menu as shown in the image below:

If installation in this way caused difficulties, go to the end of the article and download the robot file, which you will install according to the standard scheme.

To do this, you just need to drop the downloaded robot file into the MT5 terminal directory, namely into the Experts folder.

Regardless of the installation method you choose after installing the Expert Advisor, you must restart the trading terminal or update it in the Navigator panel, otherwise OpenTime 2 will not appear in the list of Expert Advisors.

Applying the OpenTime 2 Time Advisor

As we noted at the very beginning of the article, the OpenTime 2 time adviser is an assistant that allows you to implement strategies based on the patterns of price movement at a certain time of the day.

The second version of the robot has become more autonomous and flexible, which allows you to more carefully configure the system for opening and tracking deals.

So in the lines Use closing time interval and Closing time interval #2 you can give permission for early closing of deals for the first and second time intervals, while the time for each of the closing intervals can be set in the lines Closing time interval 1,2.

The Trailing stop variable allows you to activate trailing stop , while the stop movement step is specified in the Trailing step line.

In the Trade on Monday - Friday variables, you can disable trading on a specific day of the week, and in the Opening start time interval and Opening end time interval lines, you can set the time period during which a position should be opened.

The Duration in seconds variable is responsible for the time an open position is held, and in the Type of trade in time interval line, you can specify the direction of the trade, namely to buy or sell.

The Volume transaction variable is responsible for the trading lot of the opened order, and in the StopLoss time interval and TakeProfit time interval variables, you can specify the profit and stop order for your position.

In conclusion, it is worth noting that the OpenTime 2 time adviser is a more advanced and autonomous assistant that allows you to implement strategies based on opening positions at a certain time of the day.


2022
mamipizza.ru - Banks. Contributions and deposits. Money transfers. Loans and taxes. money and state