[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 306

 
nelisgar:
Hi everyone, could you please advise how to make the EA give out only one action (buy/sell/signal/message etc.) for 1 candle, i.e. if there is a buy signal, it won't close the buy on this candle, there should be some functions, so as not to try to re-invent the wheel myself


We declare a variable before the EA initiation function:

int  myBars; 

After the EA's start(){} function, we write a subprogram:

//+------------------------------------------------------------------+
//| функция isNewBar() - возвращает признак нового бара                                              |
//+------------------------------------------------------------------+
bool isNewBar(){
  bool res=false;
  if(myBars!=Bars){
    res=true;
    myBars=Bars;
  }   
        return(res);
}
//--------------------------------------------------------------- 

In EA's start() function use this subroutine and variable as follows:

if(isNewBar()==true){
  // это первый тик новой свечи - выпоняем необходимые действия
}
 

Hello!

I'll start with a simple example, otherwise will be difficult to explain.

double result()

{

double x = Bid;

return(x);

}

double result_y()

{

double y = Bid;

return(y);

}

It needs to be merged into one.

The result() is then needed as X in one function and as Y in the other . Is it possible? How to do it?

double result() // ????

{

double x = Bid;

double y = Ask; // have to return this too

return(x);

return(y); // ?

}

 

No, there can only be one result. pass the values by reference :

double _bid = 0, _ask = 0;

Print(_bid,":",_ask);

ResFunction(_bid,_ask);

Print(_bid,":",_ask);


void ResFunction(double &x, double &y){
   x = Bid;
   y = Ask;
   return;
}
 
abeiks:

Hello!

I will start with a simple example, otherwise will be difficult to explain.

Well, due to the fact that in both cases the same value is returned from your subroutines - price Bid, then one of these two functions can be dropped from the code. If the returned values are different, you can, for example, assemble them to a string - return from the subroutine these two values, separated by some separator, such as semicolon. And return it as a string. Then, in the main code, extract 2 values from the string and convert them to double.
 

Send something to the subprogramme so that it can understand what is needed.

 
abeiks:

Hello!

...

Hello! As people have already commented on your question, I would like to ask you: Are you the 2008 champions ?

If so, could you tell us about your GRAAL, without revealing all the "secrets of the madrid court" and without telling us "all the tales of the Vienna Woods". Just lift the veil a bit... You can - in this branch, I'm sure, people will find it useful!

I'm actively preparing for the Championship myself...

Thank you!

 
drknn:

Please tell me, why do you reset a variable to zero when a function is declared? It's right here:


Is this how you set it to the default value if you don't set it explicitly when you call it, or am I wrong?
 
Skydiver:

So is this how it's set to the default value in case it's not explicitly set when called, or am I wrong?


I don't know. But I am interested. I will check it out.

P.S.

It works!

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start(){
  Alert("func1(100) вернула значение = ",func1(100),"  func1() вернула значение = ",func1());
  return(0);
}
//+------------------------------------------------------------------+
int func1(int i=25){
        return(i);
}

 
Skydiver:
Try to preprint each value on each iteration of the loop. Your array size is small, so there will be no data mishmash.
 

How can I make the difference between open orders of the same sign be 1 bar?

Reason: