Questions about MQL4 - page 7

 
Somewhere on the forum the developers have written in some detail about how init/deinit works. Maybe someone could provide a link?
 
Hi all, here's a question:
I made a DLL in Delphi, I call it from MT4. Everything works except simple parameters passed by reference. In Delphi, declared as follows:

procedure Test2(var i: integer); stdcall;
begin
if addr(i) = nil then ShowMessage('What the hell?');
end;

stop to call it as

#import "DLL1.dll"
void Test2(int& i);

I call
int init() {
int x = 5;
Test2(x);
return(x);
}

when called, a reference to the variable integer should be in the stack, but null is there
so how to pass an int parameter by reference?
When passing arrays, the array value is passed by reference

using
MetaEditor 4.00 build 183
MetaTrader 4.00 build 186

one more question: if I pass a string as reference, what is the size of the string buffer?

one more question:
If I pass a string as function result, where should the memory area for the string be allocated? Should I pass a pointer to a global variable in the DLL? In this case, may I be sure that the DLL will not be called from different threads simultaneously in any mode of metatrader?

Thanks in advance
 
the current implementation is such that you can only pass parameters by reference within a single source code. the exception is arrays. if you pass an array to the dll, you can change the values of its elements and these changes will be available in the calling function. i.e. you can pass a very small array.
 
How to implement this in MQL4
at the beginning of the day set two pending orders
Once one (any) triggered - the second is removed
Five minutes before the close of the bar (say a daily) to close the triggered (if it was not closed by SL or TP)
If no pending order triggered, five minutes before closing the bar delete them both
Thank you very much
 
1) If I pass the string as reference, what is the size of the receiving buffer for the string?

2) If I pass the string as a function result, where should the memory area for the string be allocated? Should I pass a pointer to a global variable in the DLL? In this case, I can be sure that the DLL will not be called from different threads simultaneously in any mode of the metatrader?

Thanks in advance
 
How to implement this in MQL4 <br/ translate="no"> At the beginning of the day set two pending orders
When one (any) triggered - the second is deleted
Five minutes before the close of the bar (say a daily) to close the triggered (if it was not closed by SL or TP)
If no pending order triggered, five minutes before closing the bar delete them both
Thanks in advance

You set pending orders at the right time (that's easy). And you start to check orders. As soon as a Buy or Sell order appears, you work through removing the pending order (even easier). And then, at the right time, work to close all orders (this is easy).
 
Как в MQL4 реализовать такое
в начале дня устанавливаем два отложенных ордера
После того как один(любой) сработал - второй удаляется
За пять минут до закрытия бара(допустим дневного) закрыть сработавший (если он не был закрыт по SL или TP)
Если ни один отложенный ордер не соработал то за пять минут до закрытия бара удаляем их обоих
Заранее спасибо

This is how you implement it, you put pending orders at the right time (it's easy). And then you start to check the orders. As soon as a Buy or Sell order appears, you work through removing the pending order (this is even easier). And then, at the right time, work to close all orders (it is very easy).


I asked for a working code (maybe someone has implemented it).
All I did was not working ... The odrerdelete process is somehow confusing.
Another question: sometimes the price freezes (no ticks) for some minutes, i.e., we cannot close an order as the int start() body is not executed, though ticks are received for other symbols, is it possible to pass the Curetime value from any symbol with ticks?
To put it simply, the Curetime value should practically not freeze
 
What you want to do is the ABCs. Without understanding how the basic operators work, you cannot get into the deep end. And you can close all orders from any chart. You may do it this way:
 cnt=0; while(cnt<1) { if(OrdersTotal()<1)break; OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); cmd=OrderType(); for(z=0;z<3;z++) { RefreshRates(); if(cmd==2||cmd==3|cmd==4|cmd==5)result=OrderDelete(OrderTicket()); 
     if(cmd==0) result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,CLR_NONE); if(cmd==1) result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,CLR_NONE); if(result) break;Sleep(1000); } Sleep(10000); }
 
What you want to do is the ABCs. Without understanding how the basic operators work, you cannot get into the deep end. And you can close all orders from any chart. You can do it this way:<br/ translate="no">
 cnt=0; while(cnt<1) { if(OrdersTotal()<1)break; OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); 
    cmd=OrderType(); for(z=0;z<3;z++) { RefreshRates(); if(cmd==2||cmd==3||cmd==4||cmd==5)result=OrderDelete(OrderTicket()); 
     if(cmd==0) result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,CLR_NONE); if(cmd==1) result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,CLR_NONE); if(result) break;Sleep(1000); } Sleep(10000); }



And what does this code fragment do?
Deletes both pending orders that have not triggered yet
 
You asked him to destroy all orders five minutes before the bar closes, so he will take them all down. Just set the time correctly. And use other pieces of code to close unnecessary orders. Or, do you want the entire program to be written for you?