Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 845

 
Anatoliy Ryzhakov:
Hello. Can you tell me how to return the type value of the penultimate order in the history.

You need to find the time of the last closed order and then search for orders with a maximum closing time, but less than the last memorised time, this is what I did:

https://www.mql5.com/ru/forum/247136#comment_7555643

in my example the ticket was searched for, you would need to return the order type instead of the ticket, or knowing the order's ticket, you can find out its type...

История ордеров
История ордеров
  • 2018.05.24
  • www.mql5.com
Всем привет! Столкнулся с проблемой... сделал робота, который читает историю и открывает сделку...
 

Is it possible to apply a template to an exportable function to be exported from c++ to mql4?

I created a file of regular type with extension "srp" and wrote a primitive function there.

#define  MT4_EXPFUNC extern "C++" __declspec(dllexport)
MT4_EXPFUNC  int __stdcall  add(int a=0, int b=0)//stdcall //cdecl
{return (18);}

Then I created a file with "def" extension and specified the name of function to be exported

LIBRARY "dllmt42"
EXPORTS
add

Then ran it through Build - Build Solution.
I want to apply a template to my function because we are going to develop functions that work with arrays and can't do without a template.

#define  MT4_EXPFUNC extern "C++" __declspec(dllexport)
template<typename T>MT4_EXPFUNC  int __stdcall  add(T a=0, T b=0){ return (18);}

T is highlighted but writes that there is an error help advice and is it possible, tried to rearrange? Also how such function if possible will be called from mql4 side?




 
Roman Shiredchenko:

look in the codebase - on MT4 they definitely were...

Right on the front page, in this thread.

 

Good evening. In the process of studying and learning MT5 trying to implement a generally not difficult task, but little experience and gaps in knowledge....... in general does not work, please help and assistance.

I have an indicator and expert advisor, both with open source code, both by the same author (Artem Trishkin, respect and commendation). I am trying to ask the indicator to get the actual direction at the time of asking. The indicator shows this direction with up or down arrows. The direction obtained will be used by the Expert Advisor either as a signal or as a filter, but it is still far away.

I got the indicator handle but the data values of the arrows from the indicator are a mess and I cannot figure them out.

I have not changed the indicator. I have added OnInit in my Expert Advisor:

   CrossAD = iCustom(asymbol.Name(), _Period, "iCrossAD");
   if (CrossAD == INVALID_HANDLE)
   {
      Print("Не удалось создать описатель индикатора iCrossAD!");
      return(INIT_FAILED);
   }
      else Print("Хендл iCrossAD = ",CrossAD);

I added OnTick:

   int n=0;
   if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find || ArraySize(Buf_Arrow_Buy) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 2-го буфера индикатора iCrossAD, error code %d",GetLastError());
      }
      else 
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Buy_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Buy_index  = n;
         Print("Last_Arrow_Buy_volume = ",Last_Arrow_Buy_volume,", Last_Arrow_Buy_index = ",Last_Arrow_Buy_index);
         
   if (CopyBuffer(CrossAD, 2, 0, period_find, Buf_Arrow_Sell) != period_find || ArraySize(Buf_Arrow_Sell) != period_find)
      {  
         Print("НЕ удалось правильно скопировать данные из 3-го буфера индикатора iCrossAD, error code %d",GetLastError());
      }
      else 
         for(n=0; n<period_find; n++)
            {
               if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)break;
            }
         Last_Arrow_Sell_volume = Buf_Arrow_Buy[n];
         Last_Arrow_Sell_index  = n;
         Print("Last_Arrow_Sell_volume = ",Last_Arrow_Sell_volume,", Last_Arrow_Sell_index = ",Last_Arrow_Sell_index);

Of course I described and initiated the appropriate overpens, arrays, defined as timeseries and td......

Used Comment and Print to check. Not immediately, but no errors, only a couple of warnings, I do not understand. But the main thing - the parameters are defined incorrectly. Despite the condition below, maximum number for double for up arrow and some negative number for down arrow are output.

if(Buf_Arrow_Buy[n]!=EMPTY_VALUE)break;
и
if(Buf_Arrow_Sell[n]!=EMPTY_VALUE)break;
 
Here are the files
Files:
 
Sergey Voytsekhovsky:
Here are the files

You would start by testing getting data from the indicator with a simple test EA, rather than taking it from an article with lots of unnecessary features for the test.

Just create a simple Expert Advisor in the MQL Wizard and use it to practice using iCustom()

 
Sergey Voytsekhovsky:

Good evening. In the process of studying and learning MT5 trying to implement a generally not difficult task, but little experience and gaps in knowledge....... in general does not work, please help and assistance.

I have an indicator and expert advisor, both with open source code, both by the same author (Artem Trishkin, respect and commendation). I am trying to use the EA to ask the indicator to get the current direction at the time of asking. The indicator shows this direction with up or down arrows. The direction obtained will be used by the Expert Advisor either as a signal or as a filter, but it is still far away.

I got the indicator handle but the data values of the arrows from the indicator are a mess and I cannot figure them out.

I have not changed the indicator. I have added OnInit in my Expert Advisor:

I added OnTick:

Of course I described and initiated the appropriate overpens, arrays, defined as timeseries and td......

Used Comment and Print to check. Not immediately, but no errors, only a couple of warnings, I do not understand. But the main thing - the parameters are defined incorrectly. In spite of the condition below, the maximal number for double for up arrow and some negative number for down arrow are printed.

Artyom correctly said and I'll just note needlessness of one comparison

if (CopyBuffer(CrossAD, 1, 0, period_find, Buf_Arrow_Buy) != period_find || ArraySize(Buf_Arrow_Buy) != period_find)

If CopyBuffer returns the number of elements copied to the array, then the size of the array will be exactly that. Accordingly, the highlighted part of the condition simply duplicates the first one.

And a thought out loud: I haven't looked at the code of the indicator and the EA, so I could be wrong. Are you sure that there must be a signal in period_find range?

 
Alexey Viktorov:

Artyom correctly said, and I'll just point out the unnecessaryness of one comparison

If CopyBuffer returns the number of elements copied into the array, then the size of the array will be exactly that. Correspondingly, the selected part of the condition simply duplicates the first one.

I'm thinking out loud: I haven't checked the code of the indicator and Expert Advisor, so I may be wrong. Are you sure that there must be a signal in period_find range?

Yes - it's like a filter - the frequency of signals depends on it.

 
Artyom Trishkin:

You would start with a test of getting data from the indicator with a simple test EA, rather than taking it from an article with a lot of unnecessary functions for the test.

The iCustom() function will be more convenient for you.

Thank you, good advice, I will do so, at least it will be more convenient.

I will start it today.
 

Can you tell me what is wrong with the rationing of the lot?

double lot_=0.01;
double minlot=0.10;
double LotNormalize(double lot_)
  {
   if(minlot==0.001)
     {
      return(NormalizeDouble(lot_,3));
     }
   if(minlot==0.01)
     {
      return(NormalizeDouble(lot_,2));
     }
   if(minlot==0.10)
     {
      return(NormalizeDouble(lot_,1));
     }

   return(NormalizeDouble(lot_,0));
  }
Reason: