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

 
Artyom Trishkin:

It is possible to read an order ticket.

Is there a similar function

OrderGetTicket();

for mql4?

 
Seric29:

Is there a similar function

for mql4?

There is, only not exactly the same. After selecting an order you have to define the order type and the ticket by other functions.

OrderSelect - Торговые функции - Справочник MQL4
OrderSelect - Торговые функции - Справочник MQL4
  • docs.mql4.com
Чтобы определить, из какого списка выбран ордер, необходимо проанализировать его время закрытия. Если время закрытия ордера равно 0, то ордер является открытым или отложенным и взят из списка открытых ордеров терминала. Отличить открытый ордер от отложенного ордера можно по типу ордера. Если время закрытия ордера не равно 0, то ордер является...
 

Good afternoon.

There is a function to open a grid of orders with lot incremented by i,

I need the grid (lots) to be built by lot, i.e. lot1 = 0.01, lot2 = 0.02, lot3 = lot2 + lot 1. ,

how should this be described in the fLots() function?

extern int Count       = 4;      //Количество устанавливаемых ордеров
\\


for(i=1;i<=Count;i++)
    {
     {         
      res=OrderSend(Symbol(),OP_BUYLIMIT,fLots()*i,fND(Ask-(Distance*Point+i*Step*Point)),3,fND(BuyPrice-StopLoss*Point), fND(Ask-(Distance*Point+i*Step*Point))+TakeProfit*Point,"",MAGIC,expiration,Blue);    
  
      Sleep(3000);
      if(res<0) 
         {
            Print("ОШИБКА: ",GetLastError()); 
         } else {
            RefreshRates();
         }    
     }
    }
 

I want to check if there are any open positions in onInit, but for some reason I can't select them:


   for(int i=PositionsTotal(); i>0; i--)
      {
      smbol = PositionSelect(PositionGetSymbol(i));
      tickett = PositionGetTicket(i);
      
      Print("ticket(",i,") = ", tickett);
      Print(smbol);

      }
   Print("Position Total = ", PositionsTotal());

I get:


2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) ticket(1) = 0

2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) false

2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) Position Total = 1



 
psyman:

I want to check if there are any open positions in onInit, but for some reason I can't select them:


I get:


2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) ticket(1) = 0

2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) false

2019.05.01 00:11:32.177 breakeven (GBPUSD,H1) Position Total = 1



Right away it catches my eye:

for(int i=PositionsTotal(); i>0; i--)

I didn't look further because it should be like this in a reverse cycle:

for(int i=PositionsTotal()-1; i>=0; i--)
 
Artyom Trishkin:

Immediately that caught my eye:

I didn't look any further, because that's how it should be on the reverse cycle:

I prefer this notation

for(int i = PositionsTotal(); i-- > 0;)
 
Alexey Viktorov:

I prefer this entry

Well... I showed an understandable one for beginners ;)

 

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   | //+----------------------------------------------------------------------------+ //|  Версия   : 19.02.2008                                                     | //|  Описание : Возвращает суммарный профит в валюте депозита                  | //|             закрытых с определённой даты позиций                           | //+----------------------------------------------------------------------------+ //|  Параметры:                                                                | //|    sy - наименование инструмента             (""   - любой символ,         | //|                                               NULL - текущий символ)       | //|    op - операция                             (-1   - любая позиция)        | //|    mn - MagicNumber                          (-1   - любой магик)          | //|    dt - Дата и время в секундах с 1970 года  ( 0   - с начала истории)     | //+----------------------------------------------------------------------------+ double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0) {   double p=0;   int    i, k=OrdersHistoryTotal();   if (sy=="0") sy=Symbol();   for (i=0; i<k; i++) {     if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {       if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {         if (OrderType()==OP_BUY || OrderType()==OP_SELL) {           if (mn<0 || OrderMagicNumber()==mn) {             if (dt<OrderCloseTime()) {               p+=OrderProfit()+OrderCommission()+OrderSwap();             }           }         }       }     }   }   return(p); } // код Кима изменил на это и теперь от считает профит за сегодня и обнуляется в полночь double GetProfitFromDateInCurrency1(string sy="0", int op=-1, int mn=-1) {   double p=0;   int    i, k=OrdersHistoryTotal();   datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));   if (sy=="0") sy=Symbol();   for (i=0; i<k; i++) {     if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {       if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {         if (OrderType()==OP_BUY || OrderType()==OP_SELL) {           if (mn<0 || OrderMagicNumber()==mn) {             if (dt<OrderCloseTime()) {               p+=OrderProfit()+OrderCommission()+OrderSwap();             }           }         }       }     }   }   return(p); }

Hello. Please help me calculate the profit of closed trades yesterday, the day before yesterday, etc. I want to do Profit for today:. Profit for yesterday, profit for the day before yesterday

I copied the code/ for today's profit calculation.

or how to set profit today to postpone this value to yesterday's profit and then to the profit the day before that
Files:
 
Lomonosov1991:

Hello. Please help me calculate the profit of closed trades yesterday, the day before yesterday, etc. I want to do Profit for today:. Profit for yesterday, profit for the day before yesterday

To calculate today's profit, copy code/.

or how to make value from today's profit move lower to yesterday's profit, then to the day before yesterday's profit

Add one more parameter to the function description and change the check condition:

double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dtstart, datetime dtstop)
....
if (OrderCloseTime()>=dtstart &&  dtstop<=OrderCloseTime()) {
 
Thanks to Igor Makan. I made the function yesterday like this
double GetProfitFromDateInCurrency2(string sy="0", int op=-1, int mn=-1)
{
  double p=0;
  int    i, k=OrdersHistoryTotal();
  datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))-24*60*60;
  datetime dtstart=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
               if (dt<OrderCloseTime() && OrderCloseTime()<=dtstart) {              
                  p+=OrderProfit()+OrderCommission()+OrderSwap();
                 
            }
          }
        }
      }
    }
  }
  return(p);
}
I made the function the day before yesterday like this
double GetProfitFromDateInCurrency3(string sy="0", int op=-1, int mn=-1)
{
  double p=0;
  int    i, k=OrdersHistoryTotal();
  datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))-24*60*60*2;
  datetime dtstart=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE))-24*60*60;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
               if (dt<OrderCloseTime() && OrderCloseTime()<=dtstart) {              
                  p+=OrderProfit()+OrderCommission()+OrderSwap();
                 
            }
          }
        }
      }
    }
  }
  return(p);
}
And you can make it not reset to zero on weekends? i.e. Monday yesterday was Friday. i.e. to remove weekends as well?
Files:
Screenshot_2.png  844 kb