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

 

Can anyone suggest the following code:

If a grid of orders is CLOSED (more than 2 of the same type), then STOP TRADING until the end of the day (or some time which can be set in hours, minutes).

Counting history as found on the same order types still somehow able to, but how to stop at the end of the day precisely do not know. Happy Pentecost to all)

 
Igor Makanu:

not normal, eight bytes would be a pain in the ass to send something

Well, it depends on the purpose, if it's just a reminder, then eight is enough :)

 
Порт-моне тв:

Can anyone suggest the following code:

If a grid of orders is CLOSED (more than 2 of the same type), then STOP TRADING until the end of the day (or some time which can be set in hours, minutes).

Counting history as found on the same order types still somehow able to, but how to stop at the end of the day precisely do not know. Happy Pentecost to all)

//+----------------------------------------------------------------------------+
//| Подсчет ордеров                                                            |
//+----------------------------------------------------------------------------+
//| -1 - Все типы ордеров                                                      |
//|  0 - ордера типа BUY        3 - ордера типа SELLLIMIT                      |
//|  1 - ордера типа SELL       4 - ордера типа BUYSTOP                        |
//|  2 - ордера типа BUYLIMIT   5 - ордера типа SELLSTOP                       |
//+----------------------------------------------------------------------------+
double GetCloseOrderType(int order_type)
  { double p = 0;
   for(int pos=OrdersHistoryTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         if(OrderCloseTime()>=время начала дня)
           { 
            if(OrderType()==order_type || order_type == -1) cnt++;
           }
        }
     }
   return(p);
  }
 
Порт-моне тв:

Can anyone suggest the following code:

If a grid of orders is CLOSED (more than 2 of the same type), then STOP TRADING until the end of the day (or some time which can be set in hours, minutes).

Counting history as found on the same order types still somehow able to, but how to stop at the end of the day precisely do not know . Happy Holy Trinity to everyone)

/// получаем время конца (по умолч.текущего) дня. То есть время последней секунды дня

datetime EndOfDay(datetime tim=0) {

   if (tim==0) tim=TimeCurrent();

   datetime dt;

   TimeToStruct(tim,dt);

   dt.hour=23;

   dt.min=59;

   dt.sec=59;

   return StructToTime(dt);

}

/// где-то в торговой логике, отрывки

datetime tradeAllowedFrom; // в глобальной области

....

tradeAllowedFrom=EndOfDay(); // где сетку проверяем : запрещаем торговлю до конца дня

....

if (TimeCurrent()>tradeAllowedFrom) { // проверка разрешения торговли

   Buy(); // Sell();

}

If I understood the question correctly, it is approximately like this (the principle itself)

 
Aleksei Stepanenko:

Well, it depends on what purpose, if just to remind of yourself, then eight is enough :)

if you want to remind yourself, it's better to throw a custom event into OnChartEvent(), it's more convenient, imho


MakarFX:

Who can suggest the following code:

if grid of orders is CLOSE (more than 2 of the same type), then STOP TRADING until end of day (or some time which can be set in hours, minutes).

search through the orders history from the date of the day's beginning (today, or from TF D1 to get a zero bar or from a datetime tick time to convert)

if at least one order has been found in the history with a date greater than the set one - exit the function, resulting in true

in OnTick() at the very top of the call of such a function with the date parameter (today)


I'm too lazy to write it, there are about a dozen lines. Kim had functions to search for orders in the history by date

 
Порт-моне тв: Counting history as finding by the same order type I can still somehow manage, but how to stop by the end of the day I don't know exactly. Happy Trinity to all)
bool trade_buy;
bool trade_sell;

if(кол-во закрытых ордеров buy>2)
trade_buy=false;
else
trade_buy=true;

if(кол-во закрытых ордеров sell>2)
trade_sell=false;
else
trade_sell=true;
 
Maxim Kuznetsov:

/// получаем время конца (по умолч.текущего) дня. То есть время последней секунды дня

datetime EndOfDay(datetime tim=0) {

   if (tim==0) tim=TimeCurrent();

   datetime dt;

   TimeToStruct(tim,dt);

   dt.hour=23;

   dt.min=59;

   dt.sec=59;

   return StructToTime(dt);

}

/// где-то в торговой логике, отрывки

datetime tradeAllowedFrom; // в глобальной области

....

tradeAllowedFrom=EndOfDay(); // где сетку проверяем : запрещаем торговлю до конца дня

....

if (TimeCurrent()>tradeAllowedFrom) { // проверка разрешения торговли

   Buy(); // Sell();

}

if I understood the question correctly, it goes something like this (the principle itself)

Thanks for the prompt reply, but this "prohibit trade" thing, I don't know how to implement, thanks for the code.
 
MakarFX:
trade sell / trade buy - function how!?
 
Порт-моне тв:
trade sell / trade buy - function how!?


//+------------------------------------------------------------------+
bool trade_buy;
bool trade_sell;
//+----------------------------------------------------------------------------+
//| Подсчет ордеров                                                            |
//+----------------------------------------------------------------------------+
//| -1 - Все типы ордеров                                                      |
//|  0 - ордера типа BUY        3 - ордера типа SELLLIMIT                      |
//|  1 - ордера типа SELL       4 - ордера типа BUYSTOP                        |
//|  2 - ордера типа BUYLIMIT   5 - ордера типа SELLSTOP                       |
//+----------------------------------------------------------------------------+
double GetCloseOrderType(string symb="",int order_type)
  {
   double p = 0;
   if(symb=="0") symb=_Symbol;
   for(int pos=OrdersHistoryTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==true)
        {
         if(OrderSymbol()==symb || symb=="")
           {
            if(OrderCloseTime()>=iTime(_Symbol,PERIOD_D1,0))
              { 
               if(OrderType()==order_type || order_type == -1) cnt++;
              }
           }
        }
     }
   return(p);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(GetCloseOrderType(_Symbol,0)>2)
      trade_buy=false;
   else
      trade_buy=true;

   if(GetCloseOrderType(_Symbol,1)>2)
      trade_sell=false;
   else
      trade_sell=true;
//---
   if(trade_buy)
     {
      твое условие открытия покупок
     }
   if(trade_sell)
     {
      твое условие открытия продаж
     }
//---
  }
//+------------------------------------------------------------------+
 
Vitaly Muzichenko:

If anything, it's taken from here.

I'm new to programming, not very good, can you redo it and make it available for download ???

Reason: