[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 935

 

Hello, I am interested in this question. Does alpari provide a server where you can upload your advisor so it can work round the clock? Would you be kind enough to reply in person?

 
gheka:

It's not working, maybe I need to change something here or put it after the start.

I tried to translate your code on paper into Russian I understand, but it doesn't work,

it's too complicated, especially when the conditions in each condition follow, and one condition out of eight conditions.

Of course I don't argue who created this code is a miracle, but for me it's a complete perversion (in a good way)

I am not lazy to add comments to each operation and condition, except for the standard function.


There is some redundancy in the code, but the code is quite readable

 
question about period change in the program ... for example there is a certain sequence of operators that needs to be applied to different periods ... as I understand it is easier to do this in the form of a cicle ... by changing the period... i find a function in the documentation that returns the period value ... but i can't find a function to change it ... what am i doing wrong ?
 

Something's not working for you, not this code... :)

bool isCloseLastPosByStop(string sy="", int op=-1, int mn=-1) {// Объявление функции. Передаваемые параметры: sy = символ, op - тип, mn - магик
  datetime t;                                                  // Переменная содержит время закрытия ордера
  double   ocp, osl;                                           // ocp - цена закрытия позиции, osl - цена СтопЛосс закрытой позиции
  int      dg, i, j=-1, k=OrdersHistoryTotal();                // k содержит общее количество ордеров в истории

  if (sy=="0") sy=Symbol();                                 // Если в ф-цию передан sy равный 0 или NULL, то использовать символ графика
  for (i=0; i<k; i++) {                                     // Цикл по массиву закрытых ордеров
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {      // Если выбран ордер из массива закрытых ордеров, ...
      if (OrderSymbol()==sy || sy=="") {                    // ... если его символ совпадает с нашим, ...
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {  // ... если его тип Бай или Селл, ...
          if (op<0 || OrderType()==op) {                // ... если тип ордера равен или -1 (имеется ввиду любой) или равен переданному в ф-цию, ...
            if (mn<0 || OrderMagicNumber()==mn) {       // ... если его магик или любой (-1) или равен переданному в ф-цию (магику советника), ...
              if (t<OrderCloseTime()) {    // ... если переменная t содержит время закрытия меньше, чем время закрытия выбранного ордера, то ...
                t=OrderCloseTime();        // ... то присвоим переменной t время закрытия выбранного ордера (этот ордер закрыт позже предыдущего)
                j=i;                                        // Запишем в переменную j индекс найденного ордера с максимальным временем закрытия
              }
            }
          }
        }
      }
    }
  }                                                       // По окончании цикла в переменной j находится индекс последнего закрытого ордера
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY)) {      // Выберем его по индексу
    dg=MarketInfo(sy, MODE_DIGITS);                       // Количество цифр после десятичного точки в цене инструмента, заданного переменной sy
    if (dg==0) if (StringFind(OrderSymbol(), "JPY")<0) dg=4; else dg=2; // Честно... точно не скажу, но вижу, что корректировка под йену
    ocp=NormalizeDouble(OrderClosePrice(), dg);           // Нормализуем цену закрытия ордера для дальнейшего сравнения с ценой СтопЛосс
    osl=NormalizeDouble(OrderStopLoss(), dg);             // Нормализуем цену СтопЛосс ордера для сравнения с ценой закрытия
    if (ocp==osl) return(True);                           // Если эти цены равны, значит поза закрыта по стопу, возвращаем значение "Истина"
  }
  return(False);                                          // Возвращаем "Ложь"
}

That's all the logic... Viktor was right - it's redundant, but as simple as possible... :)

 
Skopcheny:
question about changing the period in the program ... for example there is a certain sequence of operators which should be applied to different periods ... as I understand it is easier to do it in the form of a timeline ... by changing the period... I find a function in the documentation that returns a period value... but I can't find a function to change it... what am I wrong ?

The period of the graph can be any of the following values:

Constant Value Description
PERIOD_M1 1 1 minute
PERIOD_M5 5 5 minutes
PERIOD_M15 15 15 minutes
PERIOD_M30 30 30 minutes
PERIOD_H1 60 1 hour
PERIOD_H4 240 4 hours
PERIOD_D1 1440 1 day
PERIOD_W1 10080 1 week
PERIOD_MN1 43200 1 month
0 (zero) 0 Period of the current schedule
 
Thank you very much, I just need some clarification ... for a group of operators to work on a certain period is it enough just to specify one of the periods in front of them as they are presented in this table?
 
Skopcheny:
Thank you very much, I just need some clarification ... for a group of operators to work on a certain period is it enough just to specify one of the periods in front of them as they are presented in this table?
To correctly answer your question, you need to see at least an example of code where you need to specify the period...
 
artmedia70:
To give the right answer to your question, you need to see at least a sample code where you specifically need to set the period...


string trend()
{int count,count_change;
double bar_centr;
string trend;
bool clear;
for (int i=10;i!=0;i--)
{
bar_centr = (High[i]-Low[i])/2+Low[i]);
if (bar_centr>((High[i+1]-Low[i+1])/2+Low[i+1])
count++;

if (bar_centr<((High[i+1]-Low[i+1])/2+Low[i+1])
count--;
}

Print (count, "period ",Period());


if (count>3) trend="buy";
if (count<-3) trend="sell";
if (count<3||count>-3) trend="uncertain";





return(trend);}

this function needs to be applied consistently to different periods ... It works if I connect it to windows in the terminal with different timeframes ... The question is if it's possible for EA to handle several different periods ...

 
Skopcheny:


this function must be applied successively to different periods ... It works if I connect the EA to windows in the terminal with different periods ... The question is if it's possible for EA to handle several different periods ...

I understand that you want your function to work not only with current chart and period, but with any of periods, passed to it ...

string trend(string sy="", int tf=0)
{
   int count,count_change;
   double bar_centr;
   string trend;
   bool clear;

   if (sy=="" || sy=="0") sy=Symbol();      
   if (tf==0) tf=Period();
   
   for (int i=10; i>0; i--)
      {
         bar_centr = (iHigh(sy,tf,i)-iLow(sy,tf,i))/2+iLow(sy,tf,i);
         if (bar_centr>((iHigh(sy,tf,i+1)-iLow(sy,tf,i+1))/2+iLow(sy,tf,i+1)))
            count++;
         if (bar_centr<((iHigh(sy,tf,i+1)-iLow(sy,tf,i+1))/2+iLow(sy,tfi+1)))
            count--;
      }

   Print (count,"период ",tf);

   if (count>3) trend="покупка";
   if (count<-3) trend="продажа";
   if (count<3||count>-3) trend="неопределенность";

   return(trend);
}

Now, call your function like this

trend(Symbol(), Period()); // It will return values for the chart and period in which the EA is hovering...

trend(USDJPY, PERIOD_D1); // It returns values for the USDJPY symbol and period of "1 day"

Instead of PERIOD_D1 you can enter 1440 - it will give the same result...

If it is called without parameters, the function returns values for the current symbol and period (they are set by default)

 
artmedia70:

I understand that you want the function to work not only with the current graph and period, but also with any graph passed to it...

Now call your function like this:

trend(Symbol(), Period()); // It will return values for the chart and period in which the EA is hovering...

trend(USDJPY, PERIOD_D1); // It returns values for the USDJPY symbol and period of "1 day"

Instead of PERIOD_D1 you can enter 1440 - it's the same...




comprehensive answer... thank you very much ...
Reason: