Features of the mql5 language, subtleties and tricks - page 157

 
Andrey Khatimlianskii:

Hi!

MT4's analogue of off-line charts is castum instruments. You can fill in any history, including making 1 bar = 1 tick.

But, like in MT4, each bar has to be at least a minute different in time from the previous one, so there won't be a normal time scale.

ps: there is a ready-made indicator here - https://www.mql5.com/en/blogs/post/719145

In MT4 the time of a bar just needs to be longer than the previous bar, and then MT4 will display the bar, i.e. in MT4 you can draw bars on offline charts with an accuracy of seconds, I posted a seconds chart in QB

but with MT5 this "will not work", if you try to send to the custom symbol 2 bars with the same open time, without taking into account the seconds, then only one bar will be displayed, that is, the accuracy of less than M1 on the custom charts of MT5 will not work

 
fxsaber:

There's a diagramhere. It works.

Without moving the TA? Does it work every time? No more than luck.


fxsaber:

Where is the boundary of perfection that can/should be tolerated? What do regressions and requotes occasionally occurring have to do with the Tester?

Rejects have nothing to do with it.

A Limit order does not need to be executed at the last known price either in the tester or in real time. The price can go anywhere during its sending.

Another point is that in the mode of 0-th lag (ideal execution), the tester can pretend that the order has been sent to the broker and executed immediately, but I do not see any profit in it, because, again, there is no sense in ideal testing if the opposite will happen in the real situation anyway.

 
Igor Makanu:

In MT4 the bar time simply needs to be longer than the previous bar and then MT4 will display the bar, i.e. in MT4 you can draw bars on offline charts to the nearest second, I posted a seconds chart in KB

Thanks for the edit, had forgotten already. Once upon a time there were definitely errors if the time was not a multiple of minutes, then it seemed to work that way too.

You definitely can't do it that way in 5.

 
Andrey Khatimlianskii:

Hi!

MT4's analogue of off-line charts is castum instruments. You can fill in any history, including making 1 bar = 1 tick.

But, like in MT4, each bar has to be at least a minute different in time from the previous one, so there won't be a normal timeline.

ps: there is a ready-made indicator here - https://www.mql5.com/en/blogs/post/719145

Oh, the custom symbols are just the thing ! And tick time doesn't matter to me. Thanks, that's an impulse in the right direction. )))

 
Andrey Khatimlianskii:

Without moving the TA? Does it work right every time? No more than luck.

No, of course it doesn't. That is why the cycle.

Forum on trading, automated trading systems and strategy testing

Features of mql4 language, intricacies and tricks

fxsaber, 2019.12.13 00:27

Schematically urgent closing of a position is done as follows
const double ClosePrice = OrderType() ? MathMin(OrderClosePrice(), Bid + MaxSpread * _Point) 
                                      : MathMax(OrderClosePrice(), Ask - MaxSpread * _Point);
    
OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), ClosePrice, 0); // StopLoss оставлен для истории
In the loop, of course. Do you have any other options?

Regs have nothing to do with it.

Limiter does not have to be triggered at the last known price either in the tester or in real life. The price can go anywhere during the time it is sent.

Another point is that in the mode of 0-delay (ideal execution), the tester can pretend that the order has been sent to the broker and executed instantly, but I do not see any profit in it, because, again, there is no sense in ideal testing if the opposite will happen in the real world anyway.

In reality, it will either be a full (or partial) execution at the current price (or better), or a rebuttal. I.e. the execution may or may not be perfect.

Thus, the Tester always performs perfectly for a market, while it always fails for a limit order.

 
fxsaber:

This means that the tester always performs perfectly for a market, but not for a limiters.

I would rather make the next tick for a market. It is better for the tester to show a loss than a real one. And the grail is unlikely to be lost from this.

 
Andrey Khatimlianskii:

Here I would rather make the execution next tick for the markets. Better a tester would show a plummet than a real one. And the grail is unlikely to be lost from this.

The next tick is not correct, your market should generate a tick, and be executed at the nearest bid or ask, taking into account the volume of the trade.
Limit should also be filled at a guaranteed price based on volume.
All other algorithms that are made now, only misleading, getting real results.
For this reason I do not use the tester at all. There is no point, when on the very basics, there is a substitution of execution.

 
Roman:

The next tick is not correct, your market should give rise to a tick, and will be executed at the nearest bid or ask, taking into account the volume of the trade.
Limit order should also be filled at a guaranteed price based on volume.
All other algorithms that are made now, only misleading, getting real results.
For this reason I do not use the tester at all. There is no point, when on the very basics, there is a substitution of execution.

Well, for that you need the history of the cup or at least the volumes of the extreme bid/ask. And there aren't any.

And a market should not generate a tick in the tester, otherwise the history would depend on the strategy being tested.

 
Andrey Khatimlianskii:

Well, for that you need the history of the cup or at least the volumes of the extreme bid/ask. And there aren't any.

And the market should not generate a tick in the tester, otherwise the history would depend on the strategy being tested.

As one of the moderators stated that mt5 was developed for stock markets,
but looking at the implementation of the tester, its development has been reduced to the same principle of dealing execution, even on real ticks.

How do you test at all then? On what historical data?
And then do you trust the tests on such historical quotes?
:))

Of course you need a tick history, and test on real ticks.
Where to get the tick history is the user's problem, collect it yourself, buy it, take it from someone who has it, etc.

Yes I agree that volumes for bid asc are not saved now, but what prevents developers from adding three columns!

  1. Volume column Ask
  2. Volume column Bid
  3. Column Last trade direction, Buy or Sell


Then all problems concerning the correctness of testing on real ticks will automatically disappear.
The execution of exchange orders in the tester will be as it should be.

Yes, the generating tick, not so I meant that the market in the tester should be executed at the nearest Bid Asks, collecting liquidity at price levels.
That is, if we send a BuyMarket with a volume of 25, the execution price will gather two levels, 10 and 15, and automatically average the net price of the position.

182.13 Ask1 15
182.12 Ask0 10
--------------------
182.11 Bid0 5
182.10 Bid1 8

For limit orders, the volume of Last trade should fill the volume of your limit order at the guaranteed price at which the limit order is placed.
That is, your limit order should be partially filled. If your limit order is placed with a volume of 25, then the Last trade with a volume of 5 will take 5 out of your limit order.
Your limit order now has volume 20, next Last trade passed with volume 10, your limit order now has volume 10,
another Last trade passed with volume 10, your limit order is filled completely.
If the price turned around and didn't execute the entire volume of your limit order, this is the real situation, the real execution.
And your remaining limit order volume continues to wait until Last comes to it again, or you withdraw that order yourself.

Therefore, the way the algorithm is implemented in the tester, has nothing to do with reality.
It's like an eye-washing toy.


 

I am not fiddling with my POD structures to open one format. There are many fields in the structures. Some structures are inherited, some have private fields.


Anyway, the task of zeroing these structures in order to edit the format under study has arisen. And nothing really comes out. As the result I decided to use this variant.

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

// Обнуление переменной.
template <typename T>
void ToNull( T &Value )
{
  uchar Bytes[sizeof(T)];
  ArrayInitialize(Bytes, 0);
  
  _W(Value) = Bytes;
}


Application.

struct A
{
private:
  int i;
  
public:
  int j;  
};

void OnStart()
{
//  A a = {0};     // 'a' - cannot be initialized with initializer list
//  ZeroMemory(a); // 'a' - not allowed for objects with protected members or inheritance
  
  ToNull(a);
}


An alternative is welcome.

Reason: