Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 274

 
STARIJ:
write a script and after each statement display the information + GetLastError() with Alert() - see example script above
How do I do this if I have an error in my code? Alert() won't help me if the script doesn't work!
 
Lowech:
How can I do this if I have an error in my code? Alert() won't help me if the script won't work!

throw out everything but the first line of the script and add Alert. Then add it gradually - learn how to program and debug

 
LRA:
That was quick. How will you search for bars? In a loop or using the time structure?

EUR USD

//+-------------------------------------------------------+
//| Проверка дней недели                       PRVERKA.mq4|
//| если первая пятница месяца была бычьей, а             |
//| 2-й понедельник медвежий - открываем сделку на продажу|
//+-------------------------------------------------------+
#property strict
void OnStart()
{
  int День=Day(), ДеньН=DayOfWeek();
  Alert("----------------------");
  int ДеньНачалаМесяца = (ДеньН-День+36) % 7;

// Если день начала месяца = 6, то число первой пятницы равно 7. Иначе 6 - день начала месяца
  int ЧислоПервойПятницы = ДеньНачалаМесяца==6?7:6-ДеньНачалаМесяца;

// Если день начала месяца < 2, то число второго понедельника равно 9 - день начала месяца. Иначе 16 - день начала месяца
  int ЧислоВторогоПонедл = (ДеньНачалаМесяца<2?9:16)-ДеньНачалаМесяца;
  Alert("ЧислоПервойПятницы = ", ЧислоПервойПятницы, "  ЧислоВторогоПонедл = ", ЧислоВторогоПонедл);

  if(ЧислоВторогоПонедл>=День)
  {
    Alert("Надо подождать числа ", ЧислоВторогоПонедл+1);
    return;   // Отключил до числа, следующего за вторым понедельником
  }

  int Продавать=0;
  for(int Бар=0;;Бар++)  //  Ищем на D1 номера баров для заданных чисел месяца
  {
    if(TimeDay(iTime(NULL,PERIOD_D1,Бар))==ЧислоВторогоПонедл)
    {
      if(iClose(NULL,PERIOD_D1,Бар)<iOpen(NULL,PERIOD_D1,Бар)) Продавать++;
      break;
    }
    if(TimeDay(iTime(NULL,PERIOD_D1,Бар))==ЧислоПервойПятницы)
      if(iClose(NULL,PERIOD_D1,Бар)>iOpen(NULL,PERIOD_D1,Бар)) Продавать++;
  }
  if(Продавать==2) bool x=OrderSend(_Symbol, OP_SELL, 0.1, Bid, 7, 0, 0);
}
 
LRA:

drop everything from the script except the first line and add Alert. Then add it gradually - you will learn how to program and debug

It didn't work( but thanks for your help.
 
int 1 = OrdersHistoryTotal();
if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY))
int tip=OrderType();
Af ternoon. I need help, I need to close sell order and then the next order can only be open buy, I want to use order history to find the last closed order and know its type, but I can not do it (who knows what I'm doing wrong, tell me) if I don't know the answer, which would help me to make the code work, please do not write!
 
Lowech:
int 1 = OrdersHistoryTotal();
if (OrderSelect(1,SELECT_BY_POS,MODE_HISTORY))
int tip=OrderType();
Af ternoon. I need help, I need to close sell order and then the next order can only be open buy, I want to use order history to find the last closed order and know its type, but I can not do it (who knows what I'm doing wrong, tell me) if I don't know the answer, which would help me to make the code work, please do not write!
When we try to translate - displays an error message: '1' - name expected. The variable name is required instead of number 1
 

Good evening, below is the code, I wrote a ticks counter, my idea is that the ticks are counted on every bar in the loop, on every new bar the counter is reset, when I start the indicator it says in the comments that on the previous bar 1 tick and the current ticks starts counting from

If I try to use a different magic sprite, I don't know why I tried to use it but I don't know why I tried to use it. Maybe I wrote it wrong?

#property indicator_chart_window
double old_price;
double count_plus=0,count_minus=0,sum=0,psum=0;
bool Fun_New_Bar=false;
datetime Prev_Time=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

  double price;
  int i=0;
  int limit; 
  double delta; 
limit=rates_total-prev_calculated;
if(prev_calculated<1) limit=rates_total-1;
for(i=limit; i>=0; i--)  
{
 if (Fun_New_Bar==false)                              
  {                                             
   
   if (Prev_Time==0) 
     {
        Prev_Time=time[i];
        Fun_New_Bar=false;
     }
   if(Prev_Time!=time[i])                        
     {
      Prev_Time=time[i];
      psum=sum;
      count_plus=0;
      count_minus=0;
      sum=0;                         
      Fun_New_Bar=false;                            
     }
    } 
  if(old_price==0) old_price=close[i];
   
    price = close[i];
    delta = price - old_price;
     
     //-- считаем "верхние" тики 
    if(delta>=0) {
      count_plus++;
               }
      
     //-- считаем "нижние" тики
    if(delta<0) {
      count_minus++;
        }
    sum=count_minus+count_plus;   
        //----
    old_price=price;
    
  Comment(StringFormat("Выводим цены\ncount_minus = %G\ncount_plus = %G\nsum = %G\npsum = %G",count_minus,count_plus,sum,psum));
}

   return(rates_total);
  }
 
PokrovMT5:

Good evening, below is the code, I wrote a ticks counter, my idea is that the ticks are counted on every bar in the loop, on every new bar the counter is reset, when I start the indicator it says in the comments that on the previous bar 1 tick and the current ticks starts counting from

If I try to use a different magic sprite, I don't know why I tried to use it but I don't know why I tried to use it. Maybe I wrote it wrong?

If I understand the problem and question correctly, the ticks are not saved on the history. Take a look at my indicator.

 
Alexey Viktorov:

If I understood the problem and the question correctly, it doesn't save ticks on history. See my indicator.


The link doesn't work, it says no page

 
PokrovMT5:

Good evening, below is the code, I wrote a ticks counter, my idea is that the ticks are counted on every bar in the loop, on every new bar the counter is reset, when I start the indicator it says in the comments that on the previous bar 1 tick and the current ticks starts counting from

If I try to use a different magic sprite, I don't know why I tried to use it but I don't know why I tried to use it. Maybe I wrote it wrong?

return rates_total-1 or 0