[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 573

 
//+------------------------------------------------------------------+
//|                                                       iTicks.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <WinUser32.mqh>
extern int  delay_MSecond = 2000;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   while(!IsStopped()){
      PostMessageA (WindowHandle (Symbol(), Period()), WM_COMMAND, 33324, 0);
      PostMessageA (WindowHandle (Symbol(), 0), RegisterWindowMessageA ("MetaTrader4_Internal_Message"), 2, 1);
      Sleep(delay_MSecond);
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 

How are queries made to the strategy tester? How, for example, to execute the following command: "Run an EA test on a specific timeframe with a specific set file and, when finished, save the report".

 
alsu:
It's hard to understand someone else's code at once... If I had to guess, I would check Imin,Imax,Jmin,Jmax values in Neuron.Study() function. On epoch 0, value 32 is passed as lR, which is then used in indexing (usually we index arrays from 0 to size-1). It's quite possible that this is where the error lies.

Indeed, the error was related to these calculations. Thanks
 
alkador:

How are queries to the strategy tester handled? How, for example, to execute the following command: "Run a test on an EA at a certain interval with a certain set file and, when finished, save the report".

Configuration at start-up

The client terminal can be started with predefined settings. For this purpose, the name of the configuration file is passed to the client terminal as a parameter.

For example:

  terminal.exe config\start.ini terminal.exe test1.txt terminal.exe "C:\Program Files\MetaTrader 4\config\settings25.ini"

If full file path is not specified (Drive:\SubDirectory\FileName), the file will be searched in the client terminal directory. The configuration file has the following lines:
[Parameter] = [Value].

Comments begin with a semicolon (;) and are not evaluated.

Parameters of the configuration file can be divided into several groups: general settings, proxy server settings(tab "Server" in the terminal settings table), FTP settings(tab "Publish" in the terminal settings table), Expert Advisor settings(tab "Expert Advisors" in the terminal settings table), settings of a single start of an Expert Advisor or a script, settings of a strategy tester launch.

Common settings

  • Profile - subdirectory name in the profiles directory. Charts will be opened in the client terminal according to the specified profile. If this option is not specified, the current profile will be opened.

  • MarketWatch - name of the file (\symbolsets directory) that contains the list of symbols to be displayed in the market watch window. Such file can be received using the "Market Watch - Symbolsets - Save As" window context menu command.

  • Login - number of the account to connect to at startup. If this parameter is missing the current login will be used.

  • Password - password for login. This parameter will be ignored if the client terminal stores personal data on disk and the account number to be connected is in the list.

  • Server - name of a trade server to which the connection should be made. Server name coincides with the name of corresponding srv file stored in config directory. This parameter will be ignored if information on the account to be connected is saved on disk.

  • AutoConfiguration - "true" or "false" depending on whether auto-configuration should be enabled. If this parameter is missing, the value from the current server settings will be used.

  • DataServer - address of the data centre. If server autoconfiguration is enabled, this entry can be ignored. If this parameter is missing, the value from the current server settings will be used.

  • EnableDDE - "true" or "false" depending on whether the DDE server is to be enabled. If this parameter is absent then the value from the current server settings will be used.

  • EnableNews - "true" or "false" depending on whether the receipt of news should be allowed or not. If this parameter is not present, the value from the current server settings will be used.

Example:

  ; common settings Profile=test 3 MarketWatch=set2.set Login=12345 Password=xxxxxx Server=MetaQuotes-demo AutoConfiguration=false DataServer=192.168.0.1:443 EnableDDE=true EnableNews=false

Proxy settings

  • ProxyEnable - "true" or "false" depending on whether the proxy server should be used to connect with the trade server.

  • ProxyServer - address of the proxy server.

  • ProxyType - type of proxy server. It can be "HTTP", "SOCKS4" or "SOCKS5".

  • ProxyLogin - proxy server login.

  • ProxyPassword - password to access the proxy server.

If any of these parameters is missing, current settings of the client terminal are used (proxy settings in the "Server" tab of the client terminal settings table).

Example:

  ; proxy settings ProxyEnable=true ProxyServer=proxy.company.com:3128 ProxyType=HTTP ProxyLogin=user45 ProxyPassword=xxx

FTP settings

  • FTPEnable - enables/disables publishing. Acceptable values are "true" or "false".

  • FTPPassiveMode - enable/disable passive mode. Acceptable values "true" or "false".

  • FTPAccount - number of account whose status data are to be sent to FTP.

  • FTPServer - address of FTP server.

  • FTPLogin - login for authorization on the FTP server.

  • FTPPassword - password for access to FTP server.

  • FTPPath - name of the directory on the FTP server where the report is placed.

  • FTPPeriod - periodicity of sending report to FTP server in minutes.

If any of the listed parameters is missing, current client terminal settings are used(tab "Publishing" in table of terminal settings).

Example:

  ; ftp settings FTPEnable=true FTPPassiveMode=false FTPAccount=12345 FTPServer=ftp.company.com FTPLogin=admin FTPPassword=pAssWOrd123 FTPPath=/inetpub FTPPeriod=10

Experts settings

  • ExpertsEnable - enable/disable experts.

  • ExpertsDllImport - enable/disable DLL import.

  • ExpertsDllConfirm - enable/disable manual confirmation of DLL function calls.

  • ExpertsExpImport - allow/prohibit import of functions from external Expert Advisors or MQL4 libraries.

  • ExpertsTrades - enable/disable EA trading.

  • ExpertsTradesConfirm - enable/disable manual confirmation of trading operations by the Expert Advisor.

Note: all parameters of an Expert Advisor group can only take values "true" or "false".

If any of the parameters mentioned above is absent, current client terminal settings are used(tab "Expert Advisors" in table of terminal settings).

Example:

  ; Experts settings ExpertsEnable=true ExpertsDllImport=true ExpertsExpImport=true ExpertsTrades=true ExpertsTradesConfirm=false

Single Expert Advisor and/or script settings

  • Symbol - name of the symbol whose chart must be opened right after the terminal start. After closing the client terminal the information about this additional chart is not saved. If the terminal is restarted without a configuration file, this chart will not be opened. If this parameter is absent, no additional chart is opened.

  • Period - period of the chart (M1, M5, M15, M30, H1, H4, D1, W1, MN). If this parameter is absent, H1 is used.

  • Template - name of the template file (\templates directory) to be applied to the chart.

  • Expert - name of the Expert Advisor to be launched after the client terminal start. The Expert Advisor starts on the chart that is opened according to the Symbol and Period parameters. If the Symbol parameter is missing, no additional chart is opened, and EA is started on the first chart in the current profile. If there are no charts in the current profile, the Expert Advisor will not be started. If this parameter is not available, no expert will be started.

  • ExpertParameters - name of the file containing EA parameters (\experts\presets directory). Such a file can be created in the Expert Advisor properties window by pressing the "Input parameters - Save" button. It is usually used to store parameters, which are different from the default ones. If this parameter is absent, default parameters are used.

  • Script - name of the script to be launched after start of the client terminal. The script is launched by the same rules as the Expert Advisor (described above).

  • ScriptParameters - name of the file containing script parameters (\experts\presets directory). This file is generated in the same way as for the Expert Advisor.

Example:

  ; open chart and run expert and/or script Symbol=EURUSD Period=H4 Template=popular.tpl Expert=MACD Sample ExpertParameters=macd.set Script=period_converter ScriptParameters=

Strategy Tester launch settings

  • TestExpert - name of the Expert Advisor to be launched for testing. If this parameter is missing, no testing is performed.

  • TestExpertParameters - name of the file containing parameters (\tester directory). Such file may be created in the Expert Advisor's properties window, by pressing "Input parameters - Save" button. It is usually used for storing parameters different from the default ones. Other parameters of the EA being tested from "Testing" and "Optimization" tabs (and from "Input parameters" tab in case this parameter is absent) are filled with values saved automatically in \tester\[Expert name].ini file after the last testing.

  • TestSymbol - name of the instrument, on data of which the testing of the Expert Advisor is to be performed. If this parameter is unavailable, the last value used in the tester is used.

  • TestPeriod - chart period (M1, M5, M15, M30, H1, H4, D1, W1, MN). H1 is used if this parameter is absent.

  • TestModel - 0, 1 or 2 depending on the testing model (All ticks, Benchmarks, Open prices). If this parameter is unavailable, value 0 (All ticks) is used.

  • TestOptimization - enable/disable optimization. Acceptable values are "true" or "false". If this parameter is not available, value "false" is used.

  • TestDateEnable - enable/disable "Use dates" option. Acceptable values are "true" or "false". If this option is not available, "false" is used.

  • TestFromDate - start date of the testing range as YYYY.MM.DD. If this parameter is absent, "1970.01.01" is used.

  • TestToDate - testing range end date in the form YYYY.MM.DD. If this parameter is absent, it will be 1970.01.01.

  • TestReport - name of the test report file. The file will be created in the client terminal directory. Relative path can be specified, for example: tester\MovingAverageReport". If no extension is specified in the report file name, the ".htm" extension will be used. If this parameter is not specified the test report will not be generated.

  • TestReplaceReport - allow/disallow repeated writing of the report file. Acceptable values are "true" or "false". If "false" is set and the report file with this name already exists, the report file name will be appended with a sequence number in square brackets. For example, "MovingAverageReport[1].htm". If this parameter is absent, "false" will be used.

  • TestShutdownTerminal - enable/disable terminal shutdown after testing. Acceptable values are "true" or "false". If this parameter is absent, "false" is used. If during testing the user pressed the "Stop" button, the value of this parameter is reset to "false", because the user took control.

Example:

  ; start strategy tester TestExpert=Moving Average TestExpertParameters=ma0.set TestSymbol=EURUSD TestPeriod=H1 TestModel=2 TestOptimization=false TestDateEnable=true TestFromDate=1970.01.01 TestToDate=2006.06.06 TestReport=MovingAverageReport TestReplaceReport=false TestShutdownTerminal=true

 
AndEv:
If anyone knows, I have a question: I need a looped script that would "press" the "Refresh" button once every 0.5 seconds in the current chart and re-initialize indicators. "I tried to make a looped script using WindowRedraw(). I tried to make a looped script using WindowRedraw() and Sleep(500), but indicators are not reinitialized.
This library contains various functions for MT4 control. Including functions for updating the chart for Expert Advisors and indicators. There are even standalone functions. I ran the script once and that's it. It is unloaded and the charts continue to update until you unload MT4.
 

Adapted from

Armen63 18.02.2012 14:47 |

Hi all help please dont know how to implement it...can someone please advise ? xocu chtobi v sovetnike obshee chislo sell ili buy ordersov kontrolirovalos int Total1 = OrdersTotal();

if (Total1 <= MaxOrders || MaxOrders == 0) tak ya kontroliruyu v all tipi orders a nado po otdelnosti i dlya sell i dlya buy

 

to Armen63

int CountBuys() 
{
   int l_count_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderType() == OP_BUY) l_count_4++;
   }
   return (l_count_4);
}

int CountSells() 
{
   int l_count_4 = 0;
   int l_ord_total_12 = OrdersTotal();
   for (int l_pos_8 = 0; l_pos_8 < l_ord_total_12; l_pos_8++) {
      OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderType() == OP_SELL) l_count_4++;
   }
   return (l_count_4);
}
 

Hello, Dear forum users!

I just started to learn mql4 and decided to write my own EA.

Do you know how to write the following condition in the code: if the last three ask prices are higher than the previous one (ask3>ask2>ask1), then place a buy order

I hope I stated the idea clearly), if something is wrong, please ask, I will specify)

I will be very grateful for your help ))

 
like this.
datetime ask=TimeCurrent();
   double ask1=0,ask2=0,ask3=0;
   ask1=Ask;
   if(ask!=TimeCurrent()){ask2=Ask;ask=TimeCurrent()}
   if(ask!=TimeCurrent()){ask3=Ask;}
   
Maybe I'm wrong. I'm just learning.
 
openlive:
for example maybe I'm wrong, I'm just learning


If we assume that the EA handles every tick, then we should do things a little differently.

int start(){
   static double ask1=1, ask2=-1, ask3=-1;
   ask3=ask2;
   ask2=ask1;
   ask1=Ask;

   if (ask3>0) {
      if (ask1>ask2) {
         if (ask2>ask3) {
             //условие выполнено для бай
         }
      }
      if (ask1<ask2) {
         if (ask2<ask3) {
             //условие выполнено для селл
         }
      }
   }
}