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

 

Thank you, the window has appeared. Now I'll know.

 

And another question.

How to make for (i=1; i<StartBar; i++) StartBar to be the bar with the specified bend (extern int b= 2)of the older timeframe (extern int = ... ; //W1, MN1)

 
Find the bar time and recalculate it to the bar number of the senior TF
 
FAQ:
Find the bar time and recalculate it to the bar number of the senior TF


Why don't you write the code?

 
gince:


How to make for (i=1; i<StartBar; i++) StartBar to be the bar with the specified bend (extern int b= 2) of the older timeframe (extern int = ... ; //W1, MN1)


Correction

Matching two tops of a specified timeframe (let's say weekly and monthly)

 

Is this the right way to go about it?

Condition tf1 >tf2

datetime GetExtremumZZ_2TF_Bars(string sy="", int tf1=0, int tf2=0, int ne=0, int dp=12, int dv=5, int bs=3) 
{
  if (sy=="" || sy=="0") sy=Symbol();
  double zz1, zz2, p1, p2;
  int    i, k1=iBars(sy, tf1), ke=0;
  int    j, k2=iBars(sy, tf2);
  datetime t;
  
  for (i=1; i<k1; i++) 
  {
    zz1=iCustom(sy, tf1, "ZigZag", dp, dv, bs, 0, i);
    if (zz1!=0) 
    {
      ke++;
      if (ke>ne) 
         {p1=zz1;}
    }
  }
  for (j=1; j<Bars; j++) 
  {
    zz2=iCustom(sy, tf2, "ZigZag", dp, dv, bs, 0, j);
    if (zz2!=0) 
    {
      p2=zz2;
      t=iTime(sy, tf2, j);
      if(p1==p2)
      return(t);
    }
  }
  return(0);
}
 

The question is as follows. In MQL4book , which can be found at MQL4.community , in "GlobalVariables" chapter in "Properties of GV-Variables" section it says: "GV variables can only have type double". Below, in the "GlobalVariableDel() Function" section, there is an example of expert globalvar.mq4 with the following content:

//--------------------------------------------------------------------
// globalvar.mq4
// Предназначен для использования в качестве примера в учебнике MQL4.
//--------------------------------------------------------------------
int    Experts;                                 // Колич. экспертов
double Depo=10000.0,                            // Заданный депозит
       Persent=30,                              // Заданный процент     
       Money;                                   // Искомые средства
string Quantity="GV_Quantity";                  // Имя GV-переменной
//--------------------------------------------------------------------
int init()                                      // Спец. функция init
  {
   Experts=GlobalVariableGet(Quantity);         // Получим тек. знач.
   Experts=Experts+1;                           // Колич. экспертов
   GlobalVariableSet(Quantity, Experts);        // Новое значение
   Money=Depo*Persent/100/Experts;              // Средства для эксп.
   Alert("Для эксперта в окне ", Symbol()," выделено ",Money);
   return;                                      // Выход из init()
  }
//--------------------------------------------------------------------
int start()                                     // Спец. функция start
  {
   int New_Experts= GlobalVariableGet(Quantity);// Новое колич. эксп.
   if (Experts!=New_Experts)                    // Если изменилось
     {
      Experts=New_Experts;                      // Теперь текущ. такое
      Money=Depo*Persent/100/Experts;           // Новое знач. средств 
      Alert("Новое значение для эксперта ",Symbol(),": ",Money);
     }
   /*
   ...
   Здесь долен быть указан основной код эксперта,
   в котором используется значение переменной Money
   ...
   */
   return;                                      // Выход из start()
  }
//--------------------------------------------------------------------
int deinit()                                    // Спец. ф-ия deinit
  {
   if (Experts ==1)                             // Если эксперт один..
      GlobalVariableDel(Quantity);              //..удаляем GV-перемен
   else                                         // А иначе..
      GlobalVariableSet(Quantity, Experts-1);   //..уменьшаем на 1
   Alert("Эксперт выгружен из окна ",Symbol()); // Сообщ. о выгрузке
   return;                                      // Выход из deinit()
  }
//--------------------------------------------------------------------

Question: why in this example the GV variables Expert and New_Expert are of int type , although, as stated earlier, these variables should be ofdouble type ?

Thank you in advance for the answer

 
gince:

Is this the right way to do it?

Condition tf1 >tf2


Something is wrong.

In the first cycle I try to find the price of the specified bend on the high TF. I start the second cycle on the low TF where I look for the price of each bend on the bars as long as it is on the chart and compare it with the price found in the first cycle. If I find such a price, I return the time of the bar of the given bend in this TF.

I started it from 2000.01.01 in the tester.

What is in the log

2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.1688
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2495
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.1192
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2315
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.1069
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.3161
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2351
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.4535
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.338
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.4249
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.3
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.416
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2596
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.3353
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2658
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.3138
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.0344
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.1537
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.0608
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.1216
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.079
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.2401
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.0104
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 1.0917
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 0.8227
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p2= 0.9596
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: t1 1992.09.01 00:00
2012.06.17 10:29:39 2001.07.06 03:30 zz_date v3 EURUSD,M15: p1 1.4104

The same was in 2000, i.e. in the beginning of the testing period.

Where is the error. I am a weak programmer. I want to write a test program. I am having a hard time with it. I cannot ask the programmer to do it, because it is being done in steps, depending on the data I have received.

I need some help here. I also asked for help on previous page to write NewZZ() function.

I will be grateful, if somebody will correct errors and explain them.

datetime GetExtremumZZ_2TF_Bars(string sy="", int tf1=0, int tf2=0, int ne=0, int dp=12, int dv=5, int bs=3) 
{
  if (sy=="" || sy=="0") sy=Symbol();
  double zz1,  zz2, p1, p2;
  int    i, k1=iBars(sy, tf1), ke=0;
  int    j;
  datetime t;
  
  for (i=1; i<k1; i++) 
  {
    zz1=iCustom(sy, tf1, "ZigZag", dp, dv, bs, 0, i);
    if (zz1!=0) 
    {
      ke++;
      if (ke>ne) 
         {p1=zz1;datetime t1=iTime(sy,tf1,i);}
    }
    
  }
  Print("                                  p1   " ,p1);
  Print("                                  t1   ", TimeToStr(t1,  TIME_DATE|TIME_MINUTES));
  for (j=1; j<Bars; j++) 
  {
    zz2=iCustom(sy, tf2, "ZigZag", dp, dv, bs, 0, j);
    if (zz2!=0) 
    {
      p2=zz2;
      Print("p2=   ",p2);
      t=iTime(sy, tf2, j);
      if(p1==p2)
      {
         Print("skaiciavimo pradzia nuo   ",TimeToStr(t, TIME_DATE|TIME_MINUTES));
         return(t);
      }
    }
  }
  return(0);
}
 
gince:


Something is wrong.

Help the weak.

 

Good afternoon. Found a trailing function on the website:

for(i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderType()==OP_BUY)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop_)
{
{ if(OrderStopLoss()<Bid-Point*TrailingStop_)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop_,OrderTakeProfit(),0,Green);
return(0);
}
}
}

if(OrderType()==OP_SELL)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop_))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop_)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop_,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}

When testing the strategy, after the first order opens, this function works fine, i.e. trailing runs and the order closes. But after opening the second order, a zero divide error occurs when referring to the trailing function. Please help me to get trailing function working for the second order, the third order, etc.