Discussion on the implementation of councillors. - page 8

 
altec3:

Good afternoon!

I'm trying to write a function that determines the profit for the current day:

Can you tell me how in the function

Specify period starting from current day. It is clear that end of period to_date=TimeCurrent(), how to correctly specify start of period from_date, so that it starts from 00h:00m:00c of current day?

Choose to taste:

datetime  iTime(
   const string        symbol,          // символ
   ENUM_TIMEFRAMES     timeframe,       // период PERIOD_D1
   int                 shift            // сдвиг
   );
int  CopyTime(
   string           symbol_name,     // имя символа
   ENUM_TIMEFRAMES  timeframe,       // период PERIOD_D1
   int              start_pos,       // откуда начнем 0
   int              count,           // сколько копируем 1
   datetime         time_array[]     // массив для копирования времени открытия. Объявить заранее

Or the most, the most. Which has already been suggested.

 
Vladimir Karputov:

Assuming that there was at least one tick today, the algorithm is as follows: the current time is sent to theMqlDateTime structure. Then set the hours, minutes and seconds to zero in this structure. It remains to convert the edited structure into a time:


Result:

Thank you! Another question, if I add a function

//+------------------------------------------------------------------+
//|Функция возвращает прибыль за текущие сутки                       |
//+------------------------------------------------------------------+
double Day_Profit()
  {
//--Запрашиваем историю сделок за последнии сутки
   HistorySelect(TimeCurrent()-PeriodSeconds(PERIOD_D1),TimeCurrent());
   uint     total       =HistoryDealsTotal();   // количество сделок в истории
   ulong    ticket      =0;                     // тикет сделки в истории
   long     type        =0;                     // тип сделки
   double   profit      =0.0;                   // финансовый результат сделки
   double   commission  =0.0;                   // коммиссия по сделке
   double   DayProfit   =0.0;                   // прибыль за текущие сутки
//--- for all deals
   for(uint i=0; i<total; i++)
     {
      if((ticket=HistoryDealGetTicket(i))>0)       //--- если имеются сделки, то...
        {
         profit      =HistoryDealGetDouble(ticket,DEAL_PROFIT);
         commission  =HistoryDealGetDouble(ticket,DEAL_COMMISSION);
         if(HistoryDealGetInteger(ticket,DEAL_TYPE)!=DEAL_TYPE_BALANCE)
           {
            DayProfit+=(profit+commission);
           }
        }
     }
   return (DayProfit);
  }
//+------------------------------------------------------------------+

to the Expert Advisor, how will the period for which trades are analyzed be updated? For example, if my Expert Advisor works for a couple of days, then when the next day comes, the period will be updated?

Implementation of the above function in the Expert Advisor:

void OnTick()
  {
   if(Day_Profit()<ProfitMax)
     {
      ExtExpert.OnTick();
     }
   return;
  }
 
altec3:

Thank you! Another question, if I add the function:

to the Expert Advisor, how will the period for which trades are analysed be updated? For example, if the Expert Advisor works for a couple of days, then with the next day the period will be updated?

The implementation of the above function in the Expert Advisor:

The time should be set from the beginning of a day to the current time + day or + three days.

You already know how to determine the beginning of day.

 

Good afternoon!

There is a need to determine the spread for a symbol before placing an order on it. The standard MQL5 library includes CSymbolInfo class. That's when I started wondering, which way is better to implement this check - via CSymbolInfo or using a function? Please, expert, advise me on what to do! If this question has already been raised, I will be very grateful if you direct me in the right direction.

 

Good afternoon!

I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?

For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open - it means that on M15 the condition for the deal should be fulfilled as well.

Files:
H1.png  43 kb
M15.png  21 kb
 
altec3:

For example, there is a simple Expert Advisor that includes two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one for H1, the other for M15.

Zero bar is evil! The indicator on the history you see calculated as if on 1 bar - closed (well, simplified, if not taking into account the possibility of re-crossing). Accordingly, the strategy is built on a closed bar and in the tester, the indicator from the major TF in MT4 will show the result of even a zero bar, as a closed one - i.e., from the future.
The result is disappointment: one thing is different in the tester, while the opposite is true in real time.
Take my word for it - I've lost half of my life while trying to figure out where the system error is. For correct mapping of indicators of higher TFs on a lower one special approach is needed. Usually with Pushka, for example, everything is simple - multiply period by TF ratio and the order, but if there are non-linear calculations, then there is only imitation of calculation on 0 bar.
I was breaking RSI for a year to get it to correctly display the major TF on the chart.
I do not insist, I recommend as a minimum to use signals from closed bars, especially from higher in relation to the current timeframe, and also check especially custom indicators for re-rating.
 
altec3:

Good afternoon!

I am in need of some advice. How bars are calculated when an EA contains signal modules from different timeframes?

For example, I have a simple Expert Advisor that has two signal modules based on stochastic (when the main line is above the signal line on 0 and 1 bars - BUY, below the signal line on 0 and 1 bars - SELL) - one on H1 and the other on M15. Weights of both modules are the same and in the Expert Advisor the threshold for opening of a deal is set in such a way that signals from both modules should be considered simultaneously. The Expert Advisor works on the chart at timeframe H1. If you look at the screenshot of H1, everything is clear - the main line is higher than the signal line on the last and penultimate bars and that is why we buy. But on the chart of M15 I cannot understand which bar should be considered as 0 and which as 1? The deal is open, it means that on M15 the condition for the deal should be met as well.

On the history you see already closed bars and the zero bar is not an evil, but it is mobile and we have to take it into account, because it is formed depending on the current price and stochastic changes of direction are possible when prices jump, soit is more sensitive, it can close for example.

Try adding one more bar just to open 0 && 1 && 2. maybe the plums will be reduced.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Приказы на проведение торговых операций оформляются ордерами. Каждый ордер имеет множество свойств для чтения, информацию по ним можно получать с помощью функций Идентификатор позиции, который ставится на ордере при его исполнении. Каждый исполненный ордер порождает сделку, которая открывает новую или изменяет уже существующую позицию...
Reason: