[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 60

 
7777877: parameter transfer from parameter transfer by reference?

here's the parameter transfer by reference, make a script like this:

int start(){
   int res = 999;
   Print("func = ",func(res)," , res = ",res);
return(0);
}
//__________________________
int func(int &a){
   a = 10;
   return(a*10);
}

the Expert tab will show the following record: 2012.04.08 11:19:35 test EURUSD,M5: func = 100, res = 10

and try to answer the question why we assigned res = 999; and the log got res = 10

 

Can you tell me how to connect the libraries? They are present in the mqh files, but when copying they give out

'strlib.mqh' - cannot open the program file

 
IgorM:

here is the parameter transfer from the link, make a script like this:

the Expert tab will show the following entry: 2012.04.08 11:19:35 test EURUSD,M5: func = 100, res = 10

And try to answer the question why we have assigned res = 999; but in the log got res = 10


Here is my explanation:

The Print function calls the user function func. The parameter res=999 is passed to the func function. When the func function itself is evaluated, the parameter a=10 is used. The value a*10=100 is passed back to the place where the func function is called. Since we end up with res=10, I deduce from this that passing a parameter by reference means the following: you can pass ANY value of the relevant type (in this case, res=999) to the called function (in this case, to func), but the function itself will be evaluated already with that value (i.e.(i.e. in our case with a=10), which will be initialized inside the function itself (which in a particular case can also coincide with the value passed into the called function, i.e. in this case, into func). And at transferring the value calculated in the function (in this case, to func) back to the function call string, the variable (in this case, res) will already have a different value than before, i.e., the value it received when the function func was calculated (i.e., in this case, res=10). So: when passing a parameter to a function by reference, within a evaluated function, the parameter value may change, and further, after the calculated value is returned in the function call string, this parameter will have a CHANGED (in a particular case, the same) value, which it received during calculation of the called function.

Did I get it right?

 
7777877: When a parameter is passed to a function by reference, the value of the parameter can change within the evaluated function
yes it does
 
IgorM:
That's right.

Grosse danke schoen!!!
 

Please tell me, I want to make a modification of the order, so the EA will change the value of stop-loss at the time I specify, but it starts to fool.

here is my code

extern int tp = 350; // profit value takeprofit
extern int sl = 400; // loss value stoploss

int ticket;

int start()
{
//----
if (OrdersTotal()==0 && Hour( )==2 && Minute( )==0) // order opens at 2:00 terminal time
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,Ask+sl*Point,Ask-tp*Point,"",123,0,Red);

//----

if (OrdersTotal()==1 && Hour( )==3 && Minute( )==0) // here I set a condition that the order with the selected ticket must be modified at 3h00 terminal time. time.

{
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES); // here I have specified the order selection, trade
OrderModify(ticket, OrderOpenPrice(), Ask+300*Point, OrderTakeProfit(),0,Blue); // modify the order with the selected ticket, from the open position price, change the SL value in points, TP left unchanged


}
//--

}


There is a problem during testing: The Expert Advisor starts to make a lot of useless modifications in time, from 3 o'clock 00 minutes to 3 59 minutes. EA is fooling around and making modifications every second ! Why? What's wrong with the code?

 
oleg_felix:

Please tell me, I want to make a modification of the order, so that the EA will change the value of the stop loss at the time I specify, but it starts fooling around.

here is my code

extern int tp = 350; // take profit value
extern int sl = 400; // stop loss value

int ticket;

int start()
{
//----
if (OrdersTotal()==0 && Hour( )==2 && Minute( )==0) // order opens at 2:00 terminal time
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,Ask+sl*Point,Ask-tp*Point,"",123,0,Red);

//----

if (OrdersTotal()==1 && Hour( )==3 && Minute( )==0) // here I specified a condition that the order with the selected ticket must be modified at 3 pm according to terminal time.

{
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES); // here I have specified the order selection, trade
OrderModify(ticket, OrderOpenPrice(), Ask+300*Point, OrderTakeProfit(),0,Blue); // modify the order with the selected ticket, from the open position price, change the SL value in points, leave TP unchanged


}
//--

}


When testing, a problem arises: The Expert Advisor starts to make a lot of useless modifications within time, from 3 o'clock 00 minutes to 3 59. Expert Advisor is fooling around and making modifications every second ! WHY? What's wrong with the code?



Why on time..... on profit!!!

 

How to write the correct function to modify an open order in an ECN account, where you can't place stop and profit at once, but you have to do it through modification.

The problem is that something is wrong, please help me to find the error.

extern int tp = 350; // profit value takeprofit
extern int sl = 400; // loss value stoploss

int ticket;
int start()
{
//----
if (OrdersTotal()==0 && Close[1]<Open[1] && High[1]<Bid) )==0) // order opens on conditions
ticket=OrderSend(Symbol(),OP_SELL,1,Bid,0,0,0t,",123,0,Red);
//----
if (OrdersTotal()==1 ) // here I have set a condition that modifies an order with a single selected order.
{
OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES); // here I have specified the order selection, transactions
OrderModify(ticket, OrderOpenPrice(), Ask+sl*Point,Ask-tp*Point,0,Blue); // modify the order with the selected ticket, from the open position price, change the SL value in points, leave TP unchanged
}
}

 
oDin48:
  • Guys, how do I connect libraries? When I try to compile the EA it gives out

  • 'strlib.mqh' - cannot open the program file

A find the line:
#include <strlib.mgh>

and replace with:

#include <stdlib.mgh>
 
7777877:

People, please explain in a simple form, what is parameter transfer by reference. I have read the documentation, but understood only that it is possible and after the variable identification it is obligatory to put a modifier &. It would be great if the explanation was accompanied by a small program with explanations... What is the difference between usual parameter passing and passing parameters by reference?

The general sense of passing parameters by reference is to pass not the variable itself, but its address into the parameter. In the opposite case, a copy of the variable is passed to the parameter.
Reason: