Spread trading in Meta Trader - page 16

 

One more question for those present. Since the Expert Advisor in the stated theme calculates two instruments, this question will be relevant.

For example. If we take two instruments in tandem - each of them starts at a different time.

(Traded on different platforms or for other reasons)

Commodities BRN and CL (in mt4 BR), for example, often start daily, 2-3 hours apart.

Same (dax+futsi), -hourly difference.

In such cases, the calculation of the average spread between instruments on small timeframes will sometimes be very incorrect! Especially if the session opened with a gap!

It would be desirable to check - how much the last bars coincide in time. Those last bars - on which the average spread is calculated - for example, in the same function from Fduch - CalculateAvarageSpread(Symbol_1,Symbol_2,0, NBars).

In other words, I want to show in my comment, - how many last bars of both symbols at specified timeframe coincide?

Could you tell me how to do it ?

 
rid >>:

Ещё один вопрос присутствующим. Поскольку советник в заявленной теме обсчитывает два инструмента, то этот вопрос будет актуален.

Например. Если мы берем в тандем два инструмента, - каждый из которых начинает работу в разное время.

(Торгуются на разных площадках или по др. причинам)

Сырьевые BRN и CL (в мт4 БР), например, ежедневно начинают работу зачастую, с разницей в 2-3 часа.

Тож самое (дакс+футси), -часовая разница.

В таких случаях расчет среднестат. спреда между инструментами на малых тф иногда будет оч. некорректным! Особенно, если сессия открылась гэпом!

Хотелось бы предусмотреть проверку, - насколько по времени совпадают последние бары. Те последние бары, - по которым ведется расчет среднестатич. спреда - например, в той же функции от Fduch-а - CalculateAvarageSpread(Symbol_1,Symbol_2,0, NBars)

Иначе говоря, хотелось хотя бы отобразить в комменте, - сколько последних баров обоих инструментов на заданном тф совпадают по времени ?

Подскажите, как это сделать ?

What do you mean by "how much time do the ...bars coincide" ? In my function, I take the two bars whose Open bars coincide in time to calculate the spread:

 int symb2Shift = iBarShift( Symbol_2, Timeframe,iTime( Symbol_1, Timeframe, k),true);

If you call it on timeframe M1, you can be sure that the spread will be calculated with pairs of bars, which coincide with each other within a minute. Another question is whether to use iClose or iOpen to calculate the spread. Either way, I don't feel confident about correctness, so now I'm calculating spreads based on tick data collected in real time (matching to the nearest second).

 
Fduch писал(а) >>

What do you mean by "how much time do the ...bars coincide" ? In my function, I take those two bars whose Open bars coincide in time to calculate the spread:

If you call it on timeframe M1, you can be sure that the spread will be calculated with pairs of bars that coincide with each other within a minute. Another question is whether to use iClose or iOpen to calculate the spread. In any case, I don't feel confident about correctness, so I'm currently calculating spreads based on tick data collected in real time (matching to the nearest second).

Absolutely right: the most accurate way to collect spread history yourself is from ticks. It's a stretch to count by opener/close, but they're out of sync, although with enough tick frequency they shouldn't differ much in time. But by no means high/low - here the error is maximal.

 
getch >>:

Хочется все же разобраться в терминологии.

Что такое ассет, коинтеграция и корреляция?

Asset, cointegration, correlation -> Google.

I would strongly advise against Wikipedia on this subject - absolutely lamer articles. About pairs trading, instead of an article, it's just an advertisement for a useless site.

I strongly advise to use good textbooks, e.g. Carol Alexander 'Market models'.

 

I'm afraid I'm being intrusive. But one more question.

I am trying to make the possibility to test (in the tester) the Expert Advisor using the method stated in the branch. At least trades of the current symbol were opened, i.e. of the one on the chart of which the EA is installed.

The virtual imitation of trades of the second one.

However, I've found out that if the OCHL price of the second instrument in the tester is "thinly or mainly" returned, then even the current Bids and Asks of the second instrument are not returned - zeros are displayed!

Comment(Ask_Tiker2,"_",Bid_Tiker2);

Is it supposed to be like this? Or is it possible to find these prices somehow ?

 
Reshetov >>:

Запросто можно залезть в свойства зацикленного советника. Временно отключить кнопку "Советники" и подредактировать свойства. Самое главное, потом не забыть обратно включить кнопку.

Thanks :)

rid wrote(a) >>

I am trying to make it possible to test (in the tester) the EA using the method stated in the branch. If only to open deals of one, - the current instrument, i.e. the one on the chart of which the EA has been installed.

It has no effect.

However, I've found out that if OCHL price of the second instrument of the "hedge" in the tester is "thinly or mainly" returned, then even current Bids and Asks of the second instrument are not returned - zeros are displayed!

Check for history and error after the function.

 
TheXpert >>:


Проверьте наличие истории и ошибку после функции.


The history is present.

//Валютная версия
extern string  Symbol_1 = "USDJPY";
extern string  Symbol_2 = "EURJPY";
///----------------------
int start()
{
//--------Задаем текущие цены инструметов -- 
double Ask_Tiker1 = MarketInfo( Symbol_1,MODE_ASK);
double Bid_Tiker1 = MarketInfo( Symbol_1,MODE_BID); 
double Ask_Tiker2 = MarketInfo( Symbol_2,MODE_ASK);
double Bid_Tiker2 = MarketInfo( Symbol_2,MODE_BID);

Comment( Ask_Tiker1,"_", Bid_Tiker1, "\n",
        Ask_Tiker2,"_", Bid_Tiker2, "\n",
"Ошибка  = ",GetLastError());

Error 4059 is displayed

ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE 4059 Function not allowed in test mode

This is strange. After all, both the first and second tool are set via Marketinfo. The first instr. - is displayed normally (92_91.98 - USDJPY), but EURJPY is not.

And if I place the EA on the second instrument, i.e. on the EURJPY chart - on the contrary, the first symbol gives zeros in the comment, but the price of the second - EURJPY - is displayed normally
.


 

rid писал(а) >>

Error 4059 is displayed

I may have misled you. MarketInfo is "safe", i.e. it does not generate errors along the way.
 
TheXpert >>:


Бесполезно.


I think it's not completely useless. If the work of the Expert Advisor is realised by opening prices, - including closing positions, - for example on small timeframes (M1-M5). Then we may achieve an approximate testing.

After all, OHLC Marketinfo prices are normally returned by the tester. It means we can obtain (close) a real profit of one symbol at OPEN prices and calculate a "virtual profit" of the other one. And then it is vice versa.

Isn't it so?

And we will get quite correct opening and closing of positions of the current symbol during every every such run.

 

rid писал(а) >>

Isn't that right?

Nope. Don't forget bar skips. Even if you manage to implement an Expert Advisor for a tester, the entries for different symbols will not be synchronous due to missed bars.

And on missed bars you'll probably get bars instead of prices.

We cannot loop or work by timers in the tester. So it is

TheXpert wrote :>>

It's useless.

Reason: