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

 

Forum on trading, automated trading systems and testing trading strategies

Libraries: Expert

fxsaber, 2019.06.04 16:40

// MT4-советник показывает, в каком режиме Long/Short был запущен.

#include <fxsaber\Expert.mqh> // https://www.mql5.com/ru/code/19003

int GetLongShortFlag( const int Chart_ID = 0 )
{
  MqlParam Params[];
  string Names[];
  
  const int Res = EXPERT::Parameters(Chart_ID, Params, Names);
  
  return(((Res & 3) << 1) + (Res & 1));
}

string LongShortToString( const int Chart_ID = 0 )
{
  const int Flag = GetLongShortFlag(Chart_ID);
  string Str = NULL;
  
  if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY) && (bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Long & Short";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_LONGONLY))
    Str = "Only Long";
  else if ((bool)(Flag & SYMBOL_TRADE_MODE_SHORTONLY))
    Str = "Only Short";
    
  return(Str);
}

int OnInit()
{
  Alert(LongShortToString());
  
  return(INIT_FAILED);
}


Alternative

Forum on trading, automated trading systems and trading strategy testing

Any newbie questions on MQL4 and MQL5, help and discussion on algorithms and codes

fxsaber, 2019.06.04 19:40

string LongShortToString2()
{
  string Str = "Long & Short";

  if (OrderSend(_Symbol, OP_BUY, 1, 0, 0, 0, 0) && (GetLastError() == ERR_LONGS_NOT_ALLOWED))
    Str = "Only Short";
  else if (OrderSend(_Symbol, OP_SELL, 1, 0, 0, 0, 0) && (GetLastError() == ERR_SHORTS_NOT_ALLOWED))
    Str = "Only Long";
    
  return(Str);
}


It won't always work, but more often than not it's enough.

 
 

The task was to save all the ticks (without losses) from the Market Watch with the least effort.

I wrote a Loader-script, which opens a chart for each symbol and runs the indicator-collector on it.

The whole trick is to run the indicator through loading such a tpl-file (given in full)

<chart>
<window>
<indicator>
name=Custom Indicator
<expert>
name=HistoryTicks_OnlySave
</expert>
</indicator>
</window>
</chart>

It is good because there are no bars. Therefore no resources are spent on them.

At the end of the day there are 60 charts. The same amount of indicators. ~500Kb of ticks per minute are written.

RAM ~450Mb, CPU ~3-8% (8 HyperThreading).


If you want to do something like this, I highly recommend to run Expert Advisor, which keeps track of how often data changes in Market Watch. My EA does not refresh for more than three seconds and then it is forced to re-login. The thing is that MT4 (and MT5 as well) in case of network problems it can re-login itself after 10-15 seconds, and sometimes up to a minute. Only then does the re-login itself. In order not to lose ticks in those 10-15 seconds or even a minute, I recommend to take the task of reconnection. The same applies to terminals with combat TCs.

 
fxsaber:

The challenge is to save all the ticks (without losses) from the Market Watch with the least amount of effort.

Is it lossless? This myth has already been dispelled.

 
Andrey Khatimlianskii:

No losses, then? I think that myth has been dispelled already.

I don't remember exactly how I convinced myself of it. I know that I compared the collected history in MT4 with the one at the broker. I got a 100% match.

I use the HistoryTicks solution from QB. When I compare virtual tester's result on collected ticks and MT5 tester's result on downloaded ticks - 100% match.

Problems can only be due to connectivity. Expert Advisors, of course, miss. Indicators do not.

 
fxsaber:

I don't remember exactly how I convinced myself of this. I know that I compared the collected history in MT4 with the one at the broker. There was a 100% match.

I use the HistoryTicks solution from QB. When I compare virtual tester result on collected ticks and MT5 tester result on downloaded ticks - 100% match.

Problems can only be due to connectivity. Expert Advisors, of course, miss. Indicators do not.

Ahem... I was just talking about your exposure:

Forum on trading, automated trading systems and trading strategy testing

Errors, bugs, questions

fxsaber, 2018.02.26 09:05

If a pack of three ticks came, the Calculate event will be called three times, but SymbolInfoTick will return the latest tick on each of those three calls. I.e. the so-called collection of ticks without passing through indicators is questionable, to put it mildly.


Has something changed?

 
Andrey Khatimlianskii:

Ahem... I was just talking about your exposure:

Has anything changed?

When there was fiddling with CopyTicks, there was a comparison of tick collection and CopyTicks results.

I do not remember exactly, but I think there was a match.

We have to use CustomTicksAdd to add a batch of ticks and look at it. But it's MT5.


For MT4 it can be checked this way. Two neighboring recorded ticks should always be different. And the tick volumes of the bars on the server should coincide with the bars from the collected ticks.

In 2018 I must have known something clever. Can't remember now.

 
fxsaber:

I don't remember exactly how I convinced myself of this. I know that I compared the collected history in MT4 with the one at the broker. There was a 100% match.

I use the HistoryTicks solution from QB. When I compare virtual tester result on collected ticks and MT5 tester result on downloaded ticks - 100% match.

Problems can only be due to connectivity. Expert Advisors, of course, miss. Indicators do not.

Forum on trading, automated trading systems & strategy testing

Give an advisor to collect tick history

zenz, 2018.03.07 11:10

I did the comparison back in September. The Alpari archive has a 1 week publishing delay, so if I do the current comparison, I won't get it before next week (and I don't see much point - I've already figured it out for myself).

So here are two screenshots from 22.09.2017. The terminal was running on an empty computer, with the only indicator that wrote the log. Operating system XP SP3, terminal version MT4 build 1090. Alpari Pro-ECN Real account.



On the left is the picture from the Alpari archive, and on the right are the ticks recorded by the indicator.

Here you may notice that ticks before 17 seconds and after (16 and 18 seconds) coincide completely, i.e. the case, in this case, is not in desynchronization of time. I repeat that it is not only within one second that the ticks skip - i.e. not only the fast ticks - but the "slow" ones are also swallowed. I haven't found any systematicity in this.

Explanation: To the right of the point after the seconds in Alpari's archive is not miles or microseconds, but the number of tick - it is done that way for some reason.

Here's the link to that thread:https://www.mql5.com/ru/forum/229889/page4#comment_6741502 I don't think anything has changed in MT4 since then, although I haven't checked anymore, but I assume that both indicators and EAs in MT4 miss ticks.

Дайте советник для сбора тиковой истории
Дайте советник для сбора тиковой истории
  • 2018.03.07
  • www.mql5.com
Дайте готовый советник для записи тиков в csv файл...
 
zenz:

Here is the link to that thread:https://www.mql5.com/ru/forum/229889/page4#comment_6741502. I don't think anything has changed in MT4 since then, although I haven't checked anymore, but I assume that both indicators and EAs in MT4 miss ticks.

There is no certainty that on the trade server side, these "missed" ticks were sent.

 
fxsaber:

There is no certainty that on the trade server side these 'missed' ticks were sent.

I was pondering this too, I agree. I was just doing research at the time and found that the discrepancies were not isolated, but recurring - so I let it go.