Features of the mql4 language, subtleties and techniques - page 20

 
fxsaber:

It will not. The TimeCurrent algorithm is affected very indirectly. You can take bar times etc.

You just need to calculate the date of last Sunday (in bar history) in any way - so that there are bars before Sunday and after Sunday. You can use TimeLocal for that.

The result will always be GMT+3 if the date of quotation is near 00:00 (non-stop sessions), or GMT+3+N - where N is the number of hours from session closing to midnight or from midnight to opening. What does this have to do with the time zone of the quotes?

 
Ivan Titov:

The result will always be GMT+3 if there are quotations around 00:00 (24-hour sessions), or GMT+3+N - where N is the number of hours from session close to midnight or from midnight to open. What does this have to do with the time zone of quotes?

I don't remember this topic at all, so I can't answer the question. If there is any inconsistency, you'd better start by demonstrating it.

 
fxsaber:

Don't remember this topic at all, so I can't answer the question. If there is any inconsistency, you'd better start by demonstrating it.

Here from this code on the BCS terminal (symbol ED-9.19) theTimeServerGMT() function returns the time 2019.08.11 22:48:55 when TimeCurrent() is 2019.08.12 11:48:55.

 
Ivan Titov:

From this code on BCS terminal (symbol ED-9.19) function TimeServerGMT() returns time 2019.08.11 22:48:55 when TimeCurrent() is 2019.08.12 11:48:55

Forum on trading, automated trading systems and trading strategy testing

Features of mql4 language, subtleties and tricks

fxsaber, 2018.03.29 14:32

// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю

Didn't pay attention to this comment in the code.

 
fxsaber:

Didn't pay attention to this comment in the code.

Are you saying that if non forex characters have history available, it won't work?

Also here is an example for forex on Alpari-Demo EURUSD,H1 in tester:

For 2019.02.19 14:00:00 returns 2019.02.19 11:00:00

For 2019.06.19 14:00:00-returns 2019.06.19 11:00:00

Although in winter it should be GMT+2 and in summer GMT+3 (EET).

 
Ivan Titov:

Are you saying that if non-forex characters have a history available, it won't work?

I don't remember. But it was probably written for a reason.


It's important to be aware of what the GMT offset is for. Perhaps my view of this value is too narrow, however, I see its usefulness in only one thing - the ability to synchronise different price BPs with each other.

I don't see any other reasons. So these functions must be able to synchronise e.g. EURUSD at different brokers (with different GMT-offset). If this does not happen, only then there is an error.

 
fxsaber:

It is important to realise what the GMT offset is for. Perhaps my view of this value is too narrow, but I see its usefulness for one thing only - the ability to synchronise the various price BPs with each other.

I don't see any other reasons. So these functions must be able to synchronise e.g. EURUSD at different brokers (with different GMT-offset). If this does not happen, only then there is an error.

Or a price BP with some news BP. Then the trick won't work?

 
Andrey Khatimlianskii:

Or a price BP with some kind of news one. Will the trick then fail?

First the two forex symbols on the different sources are synchronised. After which the bias of one relative to the other becomes clear. Based on this data, the rest of the symbols

of these sources.

Synchronization with the calendar would be good to check. Take the news in winter and in summer. And see if it coincides or not.

 
 

Profitability calculation.

// Вычисляет профитность на истории не пересекающихся закрытых позиций.
bool GetSumGain( const double Risk, double &SumGain, double &MaxDD, double &RF, const string Symb, const int Magic = -1 )
{
  bool Res = true;
  const double Leverage = Risk * 100;  
      
  SumGain = 1;
  MaxDD = 0;
  RF = 1;

  double MaxGain = SumGain;
  double DDGain = SumGain;
    
  for (int i = OrdersHistoryTotal() - 1; (i >= 0) && (Res = (SumGain > 0)); i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderType() <= OP_SELL) &&
        (OrderSymbol() == Symb) && ((Magic == -1) || (OrderMagicNumber() == Magic)))        
    {
      SumGain *= 1 - Leverage * ((OrderType() << 1) - 1) * (1 - OrderOpenPrice() / OrderClosePrice());
      
      if (SumGain > MaxGain)
        MaxGain = SumGain;
      else if (1 - SumGain / MaxGain > MaxDD)
      {
        MaxDD = 1 - SumGain / MaxGain;
        
        DDGain = SumGain;
      }
    }
    
  RF = SumGain / DDGain;
      
  return(Res);
}


Applying

#property strict
#property  show_inputs

input int MagicNumber = 1; // Для какого мэджика вычислить профитность?

#define  D(A) DoubleToString(A, 2)

void OnStart()
{
  for (int i = 1; i <= 20; i++)
  {
    double SumGain, MaxDD, RF;    
    const double Risk = i * 0.1;
    
    if (GetSumGain(Risk, SumGain, MaxDD, RF, _Symbol, MagicNumber))   
      Print((string)MagicNumber + ": при риске " + D(Risk) +
                                  " увеличение было бы в " + D(SumGain) + " раза" +
                                  " с максимальной относительной просадкой по балансу " + D(MaxDD) + 
                                  ", фактор восстановления = " + D(RF));   
  }
       
}


Result

1: при риске 0.30 увеличение было бы в 2.16 раза с максимальной относительной просадкой по балансу 0.19, фактор восстановления = 2.01
1: при риске 0.20 увеличение было бы в 1.68 раза с максимальной относительной просадкой по балансу 0.13, фактор восстановления = 1.60
1: при риске 0.10 увеличение было бы в 1.30 раза с максимальной относительной просадкой по балансу 0.07, фактор восстановления = 1.27
Reason: