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

 
Mitruha:

The idea is very good, have you seen such programs here that would transfer or copy trades to other terminals?

Such a program?
 
ModRed:
There is the MA indicator. And there is a HMA indicator similar to it. How it can be inserted into an EA? Copy the code completely? Or there is a shorter variant?
How to do it.
 

Hello all, I have a problem, I "lost" this indicator, it's some kind of smoothed CCI, which could change two parameters, period and a multiplier. In the original version, these parameters were respectively 20 and 2. And, if I remember correctly, the name of this indicator consisted of two words and the second word started with the English letter "C".

 
alsu:

But in general, of course, you can overload the constructor and use it instead of Init(), after all, it is the same function. What variant to fall back on is a personal matter of everyone, in matters of taste, as we know, there are no advisors)


And if initialization fails, in case of using method, for example, Init(), it can be described as returning a value of the corresponding type and returning an appropriate value in case of error. The calling code will thus know that the initialization failed, and that the object therefore cannot be used. How does the calling code know about failed initialization when the constructor is used?

 

Help guys, how to make the owl do not open an order on the same bar as the position was opened by a signal, and wait for a new bar and check the signal again, I did so - bar by bar

added this

datetime   BARflag  = 0; 
и -
int start()
{
 datetime now = Time[0];
  if(BARflag >= now) return(0);
   BARflag = now;
 
bergkamp.:

Help guys, how to make the owl do not open an order on the same bar as the position was opened by a signal, and wait for a new bar and check the signal again, I did so - bar by bar

added this

и -

Something like this:

   //---
   if(iBarShift(OrderSymbol(),Period(),OrderOpenTime())==0) {
      // выбранный ордер открыт на нулевом (текущем) баре, значит ещё рано открывать следующий
      }
   else {
      // выбранный ордер открыт не на нулевом (текущем) баре, значит можно открывать следующий
      }
 
artmedia70:

Something like this:

Thank you , would it be easy to decipher the prescribed lines for the example ?--// the selected order is open at zero (current) bar, so it is too early to open the next one

//the selected order is not open on the zero (current) bar, which means it is OK to open the next one ......???

 
bergkamp.:

Thank you, would it be possible to decipher the prescribed lines for the example ?--//the selected order is opened on zero (current) bar, so it is too early to open the next one

//the selected order is not open on the zero (current) bar, which means it is OK to open the next one ......???

This is the function which returns the bar to open the last position opened:

//+------------------------------------------------------------------+
   int BarOpenLastPos(string sy, int timeframe, int op, int mn) {
      datetime t=0;
      int      i, j=-1, k=OrdersTotal()-1;
      for (i=k; i>=0; i--) {
         if (OrderSelect(i, SELECT_BY_POS)) {
            if (OrderSymbol()!=sy)        continue;
            if (OrderType()!=op)          continue;
            if (OrderMagicNumber()!=mn)   continue;
            if (t<OrderOpenTime()) {
               t=OrderOpenTime();
               j=i;
               }
            }
         }
      if (OrderSelect(j, SELECT_BY_POS)) return(iBarShift(sy,timeframe,OrderOpenTime()));
      return(-1);
   }
//+------------------------------------------------------------------+

If the function returns -1, then there is no open position whose data has been passed to the function.

Example usage:

if(BarOpenLastPos(Symbol(), Period(), OP_BUY, magic)>0) {
   // бар открытия последней открытой позиции Buy на текущем символе, текущем таймфрейме, 
   // с магиком magic больше нулевого --> можно открывать следующую позицию
   }

or

if(BarOpenLastPos(USDCAD, PERIOD_M15, OP_SELL, magic0)<0) {
   // нет позиций Sell на USDCAD с магиком magic0 --> можно открывать позицию на USDCAD
   }
 

Connoisseurs please ask for your help...

algorithm test01

//+------------------------------------------------------------------+
//test                                                                    
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrGold
#property indicator_color2  clrBlue

#property indicator_level1    0

//--- indicator buffers
double Buf0[];
double Buf1[];

double t1[];
double t2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4);
   SetIndexBuffer(0,Buf0); SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,Buf1); SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,t1); 
   SetIndexBuffer(3,t2); 
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
   
   {
   int i,counted_bars;
   counted_bars=IndicatorCounted();
   i=Bars-counted_bars-1;
   
int sr=24,n;
double sum,sum2;
double m1,m2;

  
   while(i>=0)
   {
   sum=0;
   sum2=0;
   
   for(n=i; n<=i+sr-1; n++) 
   {
   if(Open[i]>Open[i+1]) m1=sum=sum+Close[i]-Close[n];
   if(Open[i]<Open[i+1]) m2=sum=sum+Close[i]-Close[n];
   
   if(Open[i]>Open[i+1]) t1[i]=sum2=sum2+Close[i]-Close[n];
   if(Open[i]<Open[i+1]) t2[i]=sum2=sum2+Close[i]-Close[n];
   }
     
   Buf0[i]=(m1+m2)/sr;
   Buf1[i]=(t1[i]+t2[i])/sr;
   
   i--;
   }
return(0);
  }
//+------------------------------------------------------------------+

why in Buf1 there are different values from Buf0? logically they should be the same?

why is it possible to use a variable for one value, but a buffer (data array)--> (an array is required for further calculation) for another value? how can I use an array as well as variables m1 and m2?

Files:
test01.mq4  2 kb
 
clubsmi:

Connoisseurs please ask for your help...

algorithm test01

why in Buf1 there are different values from Buf0? logically they should be the same?

why is it possible to set one value via a variable, but different values via a buffer (data array)--> (the array is needed for further calculation)? how can I use the same way as with variables m1 and m2 via an array?


why do we need two buffers with the same values?

add to the start

   ArrayInitialize(t1,0);
   ArrayInitialize(t2,0);
then at least the buffer values will be of the same order, although not equal