Questions from Beginners MQL5 MT5 MetaTrader 5 - page 353

 
_new-rena:

this (below) doesn't work, I typed F_Path into explorer, clicked enter, file opens... Does WinApi info look like this?

Who prevents the FILE_COMMON flag from being used when writing and reading? The file will be available to all terminals installed on the system. It will be in the shared folder of all terminals.

In ME File --> Open shared data folder

 
artmedia70:

Who prevents the FILE_COMMON flag from being used when writing and reading? The file will be available to all terminals installed on the system. It will be located in the shared folder of all terminals.

In ME File --> Open shared data folder

thanks (!!!), I will try it.
 

Hello, has anyone encountered this problem when creating a trade request with parameters:

if I put the following parameters:

mrequest.action=TRADE_ACTION_DEAL;
mrequest.type_filling=ORDER_FILLING_FOK;

mrequest.type=ORDER_TYPE_BUY;

the terminal announces that I have specified an invalid method mrequest.type_filling(order execution policy); if I specify mrequest.type_filling=ORDER_FILLING_RETURN, the order is opened but I cannot close it programmatically because the terminal reports that an invalid method is being used. I am running the Expert Advisor on a forex server and everything is working fine on other servers. Can someone write an order execution policy that can be used when developing trading robots for this broker? Thank you.
 

There is an mq4 indicator with Alert function.

For example:

//+------------------------------------------------------------------+
//|                                                    RSI-Alert.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
//#property indicator_minimum 0
//#property indicator_maximum 100
#property indicator_buffers 3
#property  indicator_color1 LightSeaGreen
#property  indicator_color2 CLR_NONE
#property  indicator_color3 CLR_NONE
#property  indicator_width1 1
#property  indicator_width2 1
#property  indicator_width3 1
#property  indicator_style1 STYLE_SOLID
#property  indicator_style2 STYLE_DOT
#property  indicator_style3 STYLE_DOT
//---- input parameters
extern int RSIPeriod=48;
extern int ApplyTo=0;
extern bool AlertMode=true;
extern int OverBought=0;
extern int OverSold=0;
//---- buffers
double RSIBuffer[];
double RSIOBBuffer[];
double RSIOSBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,RSIOBBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,RSIOSBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="RSI-Alert("+RSIPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   SetIndexLabel(1,"OverBought");
   SetIndexLabel(2,"OverSold");
//----
   SetIndexDrawBegin(0,RSIPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int    i,counted_bars=IndicatorCounted();
//----
   if(Bars<=RSIPeriod) return(0);
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
   {
      RSIBuffer[i]=iForce(NULL,0,RSIPeriod,1,0,i);
      RSIOBBuffer[i]=OverBought;
      RSIOSBuffer[i]=OverSold;
      i--;
   }
   
   if(AlertMode)
   {
      if(RSIBuffer[1]<OverBought && RSIBuffer[0]>=OverBought)
         Alert("RSI = "+ RSIBuffer[i]+ ", Sell.");
      else if(RSIBuffer[1]>OverSold && RSIBuffer[0]<=OverSold)
         Alert("RSI = "+ RSIBuffer[i]+ ", Buy.");
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
How to make it so that either in the upper left corner of the subwindow (where the indicator name and parameters are usually displayed), or somehow else, indicate whether the signal is on(extern bool AlertMode=true;) or off?
 
Nilog:

There is an mq4 indicator with Alert function.

For example:

How to make either in the upper left corner of the subwindow (where the indicator name and parameters are usually displayed), or somehow else, to indicate if the signal is enabled(extern bool AlertMode=true;) or disabled?
Output text by objects for example.
 

The documentation says that:

При тестировании в эксперте можно обрабатывать пользовательские события с помощью функции OnChartEvent(), но в индикаторах эта функция в тестере не вызывается. Даже если индикатор имеет обработчик OnChartEvent() и этот индикатор используется в тестируемом эксперте, то сам индикатор не будет получать никаких пользовательских событий.

At the moment this statement is not relevant - in indicators this function is called in the tester, at least one indicator can receive events generated by another indicator in the tester.

The problem is that once the indicator receives the call of this function, it has no access to data stored in the variables declared at global level, and vice versa - all changes made in this function are not stored in the variables of global access level.

Examples:

1. object is declared globally and initialized in the OnInit function. It can be accessed from the OnCalculate function, but we get an error message in the OnChartEvent function - invalid pointer

2. there is a function which outputs the contents of a variable to the journal (the variable is declared globally). When calling this function from OnCalculate we get the expected value, when calling the same function from OnChartEvent we get nonsense.

 

Good day!

I have faced a problem when using events, particularly the OnChartEvent() function in an indicator. When using it in an Expert Advisor, there is no problem, but in the indicator it does not work correctly. I.e. the event occurs but there is no way to change the existing fields. Example:

//----------------------------------------------------------------------------------------------
int k;
int OnInit()
{
k = 0;
ihandleDE = iCustom(_Symbol, _Period, "DrawExtremums");
//< ... >
return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
Print("OnCalculate(): k =", k);
//< ... >
return(rates_total)

}

void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
string nameEv = "EXTR_UP";
if (sparam == nameEv)
{
Print("OnChartEvent(): k = ", k);
k++;

}

}

//----------------------------------------------------------------------------------------------

As a result we get:

"OnCalculate(): k = 0" - always.

"OnChartEvent(): k = 0,...,123332" - counts from 0 to ...

How can this be and why!? Is there any way to fix it? If anyone understands, an answer would be very much appreciated.

P.S.: This injustice occurs only in strategy tester, in real time everything works fine.

Автоматический трейдинг и тестирование торговых стратегий
Автоматический трейдинг и тестирование торговых стратегий
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
dariamap:

Good day!

I have faced a problem when using events, particularly the OnChartEvent() function in an indicator. When using it in an Expert Advisor, there is no problem, but in the indicator it does not work correctly. I.e. the event occurs but there is no way to change the existing fields. Example:

//----------------------------------------------------------------------------------------------
int k;
int OnInit()
{
k = 0;
ihandleDE = iCustom(_Symbol, _Period, "DrawExtremums");
//< ... >
return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
Print("OnCalculate(): k =", k);
//< ... >
return(rates_total)

}

void OnChartEvent(const int id,
const long &lparam,
const double &dparam,
const string &sparam)
{
string nameEv = "EXTR_UP";
if (sparam == nameEv)
{
Print("OnChartEvent(): k = ", k);
k++;

}

}

//----------------------------------------------------------------------------------------------

As a result we get:

"OnCalculate(): k = 0" - always.

"OnChartEvent(): k = 0,...,123332" - counts from 0 to ...

How can this be and why!? Is there any way to fix it? If anyone understands, an answer would be very much appreciated.

P.S.: This injustice occurs only in strategy tester, in real time everything works fine.

Evening. At their time, Service Desk has given quite a definite answer on this subject: the terminal and the strategy tester are two different programs, and the performance of Expert Advisors/indicators in the tester and the terminal may be different. What often works in the client terminal does not work in the Strategy Tester. Write to Service Desk, provide proof and let them fix it.
 
Tapochun:
Good evening. At their time, Service Desk gave quite a definite answer on this subject: the terminal and the strategy tester are two different programs, and the work of Expert Advisors/indicators in the tester and in the terminal can differ significantly. What often works in the client terminal does not work in the Strategy Tester. Please write to Service Desk and provide them with proofs and let them fix it.
Thank you very much! I'm glad the problem is not me)
 
extern string Symbol1= "EURUSD";
extern string Symbol2= "GBRUSD";

  double Sell1=iFractals(Symbol1,240,MODE_UPPER,2);
  double Sell2=iFractals(Symbol2,240,MODE_UPPER,2);
Can you tell me which command to write so that when Sell1 and Sell2 fractals are opened at the same time an order is opened
Reason: