Spread trading in Meta Trader - page 32

 

Now I ran my Expert Advisor (lot=0.1) sequentially on some charts (dollaren+euroyen) from 29/12/2009 up to now. By eye, I set the following parameters: Delta=20 deviation and total close = +10 pips.

It is clear that in total we have good profit, more than 200 pips.

I do not understand why the number of deals is different. Probably, some bars are missing on one pair on the chart. Or there was a failure on gaps. The Expert Advisor mechanism "glitched". I will try to analyze it.

But it's clear that in general the virtual simulation 's work is correct. The charts are symmetric - as they should be when working with a hedge!

The deals 11 and 15 on the charts - well, exactly, they were closed at one gap.

EURRJPY



USDJPY


 
Respected gentlemen, who knows how cointegration is counted? Can anyone help?
 
al982 >>:
Уважаемые господа, кто знает как считается коинтеграция? Может кто помочь?

Here.

 
Sure thanks, but do you know any resources on rusk?
 
al982 >>:
Конечно спасиб, а на рсуском не знаешь ресурсов ?

Google is your guide.

Briefly, cointegration does not count, there is no numerical indicator for it. You can only try to estimate its presence/absence. The simplest variant for two Assets: regression of one row X on another row Y, we get slope B and intercept A. We build a spread process like Z = Y - X*B - A. Let's test the resulting process for stationarity. If Z is stationary then we can assume that X and Y are cointegrated and the Z process can be successfully traded.

A more advanced variant is to find an eigenvector corresponding to the minimum eigenvalue for the variant matrix. The process turns out prettier and can account for an unbounded number of assets.

The problem is with the definition of stationarity. The stationary process should be stationary on all length going to infinity, but we always have a finite series, i.e. it is very easy to be cheated.

 
rid >>:

Вот сейчас прогнал советник (лот=0.1) ......Только не пойму, почему число сделок разное. Видимо, на одной паре на графике пропущены бары.


Hi all. Indeed, the number of bars is different on the charts, although the testing history is the same.

Apparently we need to determine from which date (from which depth) the correct quotes history for both instruments starts.

In the :

/---------------------------------------------------------------------------+
//ФУНКЦИЯ РАСЧЕТА СРЕДНЕСТАТИСТИЧЕСКОГО СПРЕДА                               |
//---------------------------------------------------------------------------+               
  double CalculateAvarageSpread(string Symbol_1, string Symbol_2,
                              int Timeframe, int NBars)
{ int k;   double N = 0;   double Sum = 0;
   for( k = 0; k < iBars( Symbol_1, Timeframe); k++)  {
      if( N == NBars)         break;

      int symb2Shift = iBarShift( Symbol_2, Timeframe,iTime( Symbol_1, Timeframe, k),true);
      if( symb2Shift != -1)      {
         Sum += iClose( Symbol_1, Timeframe, k) - iClose( Symbol_2, Timeframe, symb2Shift);
         N++;
      }   }   double avarageSpread = Sum / N;   return( avarageSpread);}

is stated -

int symb2Shift = iBarShift( Symbol_2, Timeframe,iTime( Symbol_1, Timeframe,k),true);
if( symb2Shift !=-1) {

What does it mean? Am I interpreting the wording of this condition correctly? -

"If a bar is missing on one of the instruments, then on the second instrument - the same bar present is skipped (not taken into account)" ?

And how can we get here - the number of the nearest missed bar - on any of the instruments? It does not matter which one ?

Please, tell me...

.

 
rid >>:

Всем привет. Действительно, число баров разное на графиках, хотя история тестирования задана одинаковая.

Видимо нужно определить, с какой даты(с какой глубины) начинается корректная история котировок по обоим инструментам.

No need. This is a common occurrence for instruments that have periods of low liquidity. No tick just came in a minute, the bar is missed.

What does it mean ? Am I interpreting the wording of this condition correctly ? -

"If a bar is missed on one of the instruments, then on the second instrument - the same bar present is missed (not counted)" ?

Yes.

And how do I get here - the number of the nearest missed bar - on any of the instruments ? It does not matter which one ?

Please advise...

https://docs.mql4.com/ru/series/iBarShift

change true to false

 
wise >>:

Не нужно. Это -- частое явление для инструментов, у которых бывают периоды пониженной ликвидности. За минуту просто не пришел ни один тик, бар пропущен.

Да.

https://docs.mql4.com/ru/series/iBarShift

true поменять на false


Thank you. Yes indeed. Switched to tf=m5 and results are much more correct in most cases (tests). The trades on both instr. are pretty much the same in number.
 

By the way, why is the spread in the base spread calculating on the open prices? That's not right -- it's correctly based on closes.

Why:

1. Opening prices. A bar opened on the first instrument. A bar opens on the second instrument. During this time, there may be more ticks on the first instrument, and therefore the calculated spread may be incorrect.

2. For the closing prices. We can be sure that at the moment of bar closing we have the current quotes, therefore the calculated spread will be correct.

 

Perhaps the instruments (EURUSD+GOLD) might be a good tandem.

Today I manually tried to use the signals of inductors on tf=m5 - I experimented.

Here is the result:

//--------------------------------------------------

19934111 2010.01.11 09:53 sell 0.30eurusd 1.4516 0.0000 0.0000 2010.01.11 11:27 1.4508 + 24.00
19934099 2010.01.11 09:53 buy 0.30gcg0 1157.1 0.0 0.0 2010.01.11 11:27 1157.0 -3.00


19937919 2010.01.11 12:18 buy 0.30gcg0 1158.1 0.0 0.0 2010.01.11 12:34 1159.7 +48.00
19937915 2010.01.11 12:17 sell 0.30eurusd 1.4537 0.0000 0.0000 2010.01.11 12:34 1.4543 -18.00
//----------------------------------------------------------
And now the current "hedge" (c_euro+b_gold) is open

Reason: