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

 

scripts are indistinguishable from EAs...

Sometimes scripts use #property show_inputs, to display a dialog with parameters, as in EA (it's there as a matter of course), but it's hard to tell the difference...

 

Can you suggest an algorithm... We need to find the time of high and low of the high timeframe in the low timeframe.

   double H=iHigh(NULL,TF2,i);
   double L=iLow(NULL,TF2,i);  
   datetime timeH=
   datetime timeL=
 
zfs:

Can you suggest an algorithm... You need to find the time of high and low of the high timeframe in the low timeframe.

Remember or immediately use i - the index found.

And iTime(NULL,TF2,i) will be the time.

 
Craft:

Didn't hold out until the morning. It got a little better, but the order bloom placements could not be avoided. How can I set up a single order at the required condition? You mentioned: No, that would not work. Only through analysis of the order history - how should we do that or what else is suitable?

like this

int i,orders_total=OrdersTotal();

bool order_on_last_bar=false;

if(orders_total>0) //если есть ордера
{
   for(i=orders_total-1;i>=0;i--) //перебираем их все
   {
      OrderSelect(i,SELECT_BY_POS);
      if(iBarShift(OrderOpenTime())==0) //если номер бара, соответствующего сремени открытия, равен 0
         order_on_last_bar=true; //фиксируем этот факт
   }
}

if(order_on_last_bar==false) // на нулевом баре нет открытых ордеров
{
   //делаем то что нам нужно
}
 

I've asked this question before, but now I need it again, to calculate the maximum volume to open a position. I write it this way:

// Расчет максимального объема
   for (double m = 0.1; AccountFreeMarginCheck(Symbol(),OP_SELL,m)>30; m = m + 0.1)
      {
       Max_lots   = m;
       double Ost = AccountFreeMarginCheck(Symbol(),OP_SELL,m);
      }

But Max_lots equals zero all the time... I don't know, may be someone knows more competent construction of calculation of such a thing?

 
alsu:

like this

I filled all iBarShift function values (compilation caused error before), int i has already been declared above. I tried to remove this replay and replace it with j for the sake of experiment, but it didn't work - I got multiple order open/close on some bars. Below is the code with opening conditions, maybe I have messed up something. What else can we do?

   int j,orders_total=OrdersTotal();

bool order_on_last_bar=false;

if(orders_total>0) //если есть ордера
{
   for(j=orders_total-1;j>=0;j--) //перебираем их все
   {
      OrderSelect(j,SELECT_BY_POS);
      if(iBarShift(NULL,0,OrderOpenTime())==0) //если номер бара, соответствующего времени открытия, равен 0
         order_on_last_bar=true; //фиксируем этот факт
   }
}

if(order_on_last_bar==false) // на нулевом баре нет открытых ордеров
{
while(true)                                  // Цикл закрытия орд.
     {
      if (Total==0 && Opn_B==true)              // Открытых орд. нет +
        {                                       // критерий откр. Buy
         RefreshRates();                        // Обновление данных
         Alert("Попытка открыть Buy. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_BUY,Lts,Ask,2,0,0);//Открытие Buy
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Buy ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      if (Total==0 && Opn_S==true)              // Открытых орд. нет +
        {                                       // критерий откр. Sell
         RefreshRates();                        // Обновление данных
         Alert("Попытка открыть Sell. Ожидание ответа..");
         Ticket=OrderSend(Symb,OP_SELL,Lts,Bid,2,0,0);//Открытие Sel
         if (Ticket > 0)                        // Получилось :)
           {
            Alert ("Открыт ордер Sell ",Ticket);
            return;                             // Выход из start()
           }
         if (Fun_Error(GetLastError())==1)      // Обработка ошибок
            continue;                           // Повторная попытка
         return;                                // Выход из start()
        }
      break;                                    // Выход из while
     }
  }
 
Craft:

I filled all iBarShift function values (compilation caused error before), int i has already been declared above; I tried to remove this replay and replace it with j for clean experiment; it didn't work - I got multiple order open/close on some bars. Below is the code with opening conditions, maybe I have messed up something. What else can we do?

1. What is the Total variable, where is its value assigned?

2. It would be better to put else before the second if(Total==0 if(

 
alsu:

1. What is the Total variable and where is its value assigned?

This is based on the example from the article Simple Expert: https://book.mql4.com/ru/samples/expert

int start()
  {
   int
   Total,                           // Количество ордеров в окне 
...
   // Учёт ордеров
   Symb=Symbol();                               // Название фин.инстр.
   Total=0;                                     // Количество ордеров
   for(int i=1; i<=OrdersTotal(); i++)          // Цикл перебора ордер
     {
      if (OrderSelect(i-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:
         if (OrderSymbol()!=Symb)continue;      // Не наш фин. инструм
         if (OrderType()>1)                     // Попался отложенный
           {
            Alert("Обнаружен отложенный ордер. Эксперт не работает.");
            return;                             // Выход из start()
           }
         Total++;                               // Счётчик рыночн. орд
         if (Total>1)                           // Не более одного орд
           {
            Alert("Несколько рыночных ордеров. Эксперт не работает.");
            return;                             // Выход из start()
           }
         Ticket=OrderTicket();                  // Номер выбранн. орд.
         Tip   =OrderType();                    // Тип выбранного орд.
         Price =OrderOpenPrice();               // Цена выбранн. орд.
         SL    =OrderStopLoss();                // SL выбранного орд.
         TP    =OrderTakeProfit();              // TP выбранного орд.
         Lot   =OrderLots();                    // Количество лотов
        }
     }
 

alsu:

2. Before the second if(Total==0 it's better to put else if(.

It didn't help. alsu, sorry to intrude, but I really want to get to the bottom of this.
 
Craft:
It didn't help. alsu, sorry for the intrusiveness, but I really want to figure it out (bring it to an end).

no big deal.

try to commit /* */ piece of code from simple EA, and replace Total with orders_total - a variable we declared ourselves.