Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 159

 
artmedia70:

Move it from the library to the wha-tam-do code. If the error goes away, it means there is a problem with the correct connection of the library in the wha-tam-do code. First of all.

If it doesn't go away - look what parameters are passed to the function. In idea, there should be a parameter of type string with the name of currency pair. Just pass Symbol().



It really helps. I'll think about it.

This is so weird. Why should I look in the library if passing of parameters is correct? The error is clearly written. Or is there nothing specific? I just wish I knew what was needed.

This function is borrowed, so I'm posting it with the author's contacts:

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Получаем торговую информацию по символу                                    |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
void fGet_MarketInfo (string fs_Symbol, int fi_Ticket = 0)
{
//----
         if (fs_Symbol != bs_Symbol || fi_Ticket < 0)
         {
                  if (fi_Ticket > 0)
                  {
                     bs_Symbol = OrderSymbol();
                  }
                  else
                  {
                     bs_Symbol = fs_Symbol;
                  }
                  if (bs_Symbol == Symbol())
                  {
                      bi_SymDigits = Digits;
                      bd_SymPoint = Point;
                  }
                  else
                  {
                      bi_SymDigits = MarketInfo (fs_Symbol, MODE_DIGITS);
                      bd_SymPoint = MarketInfo (fs_Symbol, MODE_POINT);
                  }
        if (bd_SymPoint == 0.0)
        {
           bd_SymPoint = fGet_Point (fs_Symbol);
        }
                  bd_ProfitMIN = NDP (ProfitMIN_Pips);
         }
         if (fi_Ticket > 0)
         {
            fGet_OrderDetails (fi_Ticket);
         }
    //---- Получаем текущие цены по инструменту
    RefreshRates();
    bda_Price[0] = NDD (fGet_TradePrice (0, bb_RealTrade, bs_Symbol));
    bda_Price[1] = NDD (fGet_TradePrice (1, bb_RealTrade, bs_Symbol));
    bd_Spread = NDD (bda_Price[1] - bda_Price[0]);
//----
}

This is how I imported it:

#import "hoz_Base@Library.ex4"
    double ND (double v);
    string DToS (double v);
    string DToSByLots (double v);
    void fGet_MarketInfo (string fs_Symbol, int fi_Ticket = 0);
#import

The call now is like this:

fGet_MarketInfo (fs_Symbol);

How do you solve such problems?

 
hoz: How are such problems solved?

Study the documentation. Compiled libraries do not pass parameters by default - you must pass ALL parameters when calling a function. Read it carefully. Excerpt:

Since the imported functions are outside the module being compiled, the compiler cannot verify that the parameters passed are correct. Therefore, the composition and order of parameters passed to imported functions must be accurately described to avoid run-time errors. Parameters passed to imported functions (both from EX4 and DLL modules) cannot have default values.
 
TarasBY:

No default parameters are passed to compiled libraries - you must pass ALL parameters when calling a function. Read it carefully. Excerpt:

Since the imported functions are outside the module being compiled, the compiler cannot verify that the parameters passed are correct. Therefore, the composition and order of parameters passed to imported functions must be accurately described to avoid run-time errors. Parameters passed to imported functions (both from EX4 and DLL modules) cannot have default values.

Ah, that's it. Live and learn! Thank you, I'll keep that in mind.
 

When running optimization in MT4, we need to receive information about a pass in the "Optimization results" tab similar to the one generated by a single pass in the "Report" tab.

How can this be implemented?

 

I decided to get acquainted with the library. I took a part of code from my indicator and put it into the function, and I multiplied this function and pasted it into two library files.

I named the first one "indi.mqh" and the second one simply "djo.mq4".

int countbars(int& hist, int obrax, bool tikk)
{ 
 int z=0;
 static int PreBars=0; 
 static datetime BarTime=0;
 if (Bars == PreBars && tikk==false)return(-1);
 if (Bars < hist+obrax)  
 {
  if (Bars-obrax<=1) {Alert (" Недостатьньо історії");return(-1);}
  hist=Bars-obrax;
 }
 
 if (Bars-PreBars == 0 && BarTime==Time[0] && tikk==true) return(0);
 else  
 {
  if (Bars-PreBars == 1 && BarTime==Time[1]) z=1;
  else  z=hist;
 }
 PreBars = Bars;  
 BarTime=Time[0];
 return (z);
}

To the point: when referring to the first one, everything works as planned;

 include <indi.mqh>

when replacing the first by the second and accessing the second by a method:

#import "djo.ex4"  int countbars(int& hist, int obrax, bool tikk);  #import

But nothing works at all, not even alerts - nowhere after start. And just now and the terminal closed itself ))

As I guess all constants are re-initialized each time I access the imported function?

Where can I read about mql4 import in details, which bugs are either fixed or not and so on?

Thanks, I'm going to sleep............

 
ALXIMIKS:

I decided to get acquainted with the library. I took a part of code from my indicator and put it into the function, and I multiplied this function and pasted it into two library files.

I named the first one "indi.mqh" and the second one simply "djo.mq4".

To the point: when referring to the first one, everything works as planned;

when replacing the first by the second and accessing the second by a method:

But nothing works at all, not even alerts - nowhere after start. And just now and the terminal closed itself ))

As I guess all constants are re-initialized each time I access the imported function ?

Where can I read about mql4 import in details, which bugs are either fixed or not and so on?

Thanks, I'm going to sleep............

It is possible to pass parameters by reference. In this case, modification of such parameters will affect the corresponding variables in the called function passed by reference. You cannot pass elements of arrays by reference. Parameters can be passed by reference only within the limits of a single module, such an opportunity is not provided for library functions. In order to specify that the parameter is passed by reference, the modifier & must be placed after the data type. And here are some more experiments.
 
Tell me. I get a sound message when I cross two sliding averages. When opened, this sound message is repeated as many times as there have been crossings in the history. Question. How can I get it to produce a message only for the signals that have been generated in the present time. That is, only at the time and the signal that was received literally at the moment...
 
Zolotai:
Tell me. I get a sound message when I cross two sliding averages. When opened, this sound message is repeated as many times as there have been crossings in the history. Question. How can I get it to produce a message only for the signals that have been generated in the present time. That is, only at the time and the signal that was received literally at the moment...
At the opening of what? It feels like an indicator. There are many solutions. It all depends on the code.
 
artmedia70:
When opening what? It feels like an indicator. There are many solutions. It all depends on the code.


It's got nothing to do with the code. I just need the right condition. The question is if there is a possibility to know the time of the current bar? How do I know the time of the bar at all?
 
Zolotai:

It has nothing to do with the code. I just need the right condition. The question is, is there any way to know the time of the current bar? How do I know the time of a bar?
Time[] and iTime().
Reason: