Errors, bugs, questions - page 2964

 
Roman:

Replace the structure with a single variable ))

Not transferable.

 
fxsaber:

It's not being transferred.

Did you remember to import the function in the Expert Advisor?
I updated the example for the structure, it was not much wrong there.
In general, if you work with a structure, think how to declare a structure object, globally or locally.
And for one variable, all this is not needed, just return the variable and that's all.

Документация по MQL5: Основы языка / Препроцессор / Импорт функций (#import)
Документация по MQL5: Основы языка / Препроцессор / Импорт функций (#import)
  • www.mql5.com
Импорт функций (#import) - Препроцессор - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Roman:

Did you remember to import the function into the EA?

Can you provide the source code of the indicator and EA for your idea or not?

 
fxsaber:

Can you provide the source code of the indicator and EA for your idea or not?

Yes, it's strange. Export for functions in mql4 does not want to work for some reason.
I do not get any results from library or indicator. However, I have seen functions in dependencies.
An example for the library

#property library
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

double value = 0.0;

//+------------------------------------------------------------------+
//| My function                                                      |
//+------------------------------------------------------------------+
double SetValue(double v) export
{
   value = v;    
   return(value);
}

//+------------------------------------------------------------------+
double GetValue(void) export
{
   return(value);
}
//+------------------------------------------------------------------+

An indicator that sets a value

#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window

#import "Lib.ex4"
   double SetValue(double v);
   double GetValue(void);
#import

MqlTick tick;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{

   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason)
{
   Comment("");
}
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{
   
   SymbolInfoTick(NULL, tick);
   SetValue(tick.bid);
   
   //Comment((string)GetValue());   
   
   return(rates_total);
}
//+------------------------------------------------------------------+

An Expert Advisor that should get a value through a function but it doesn't work

#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#import "Lib.ex4"
   double GetValue(void);
#import

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   EventSetMillisecondTimer(10);
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Comment("");
   EventKillTimer();
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
}

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
   double bid = GetValue();
   
   Comment("\r\nЭксперт получил значение из индикатора = "+(string)bid);
   //ChartRedraw();

}
//+------------------------------------------------------------------+
 
fxsaber:

I send ticks from the indicator via this: sparam contains MqlTick, lparam - tick number.

The Expert Advisor catches these ticks in OnChartEvent. And it needs to understand if the current tick is the most actual one or not? I.e., is there a queue of ticks or is it empty?

For this, it reads the number (the task is to read this number) of the latest tick sent by the indicator. If the tick has the same number - the queue is empty, and it's possible to start working with ticks.


And during the operation of OnTick, after OrderSend it's necessary to check if the indicator has sent more ticks. For this, we again need to read the number from the indicator. And there can be more than a hundred of such checks during one OnTick. That's why we need to read it quickly.

If the Expert Advisor is taking the ticks through the CopyTicks, why does it need to know that the queue is empty?

Let it work on each of the events, and skip the events, which have less time than already processed.

 
Andrey Khatimlianskii:

If my Expert Advisor is still taking ticks via CopyTicks, why does it need to know that the queue is empty?

Forum on trading, automated trading systems and trading strategies testing

Errors, bugs, questions

fxsaber, 2021.02.17 21:26

Please share my thoughts on this issue(MT4):

Indicator has to write int-number somewhere. And EA has to read it.

 
fxsaber:

would something like this help?

https://www.mql5.com/ru/code/818

File Mapping без DLL
File Mapping без DLL
  • www.mql5.com
Класс MQL5, который работает напрямую с маппингом, без использования самописной DLL.
 
Mikhail Mishanin:

would something like this help?

https://www.mql5.com/ru/code/818

A quick WinAPI option was suggested above.

 
fxsaber:

A quick WinAPI option was suggested above.

this option is more dangerous and difficult to implement

 
Andrei Trukhanovich:

this option is more dangerous and difficult to implement

Waiting for this one.

Reason: