Spread trading in Meta Trader - page 48

 
Here is a script that immediately displays the required information on the tool for manual calculation of the coefficient, now it is a matter of five minutes to write the code for automatic calculation
Files:
dvcg.mq4  1 kb
 
forex-k >>:

спасибо!

я считаю так:

Стоимость пункта ( Инструмент1 ) = Размер минимального изменения цены инструмента в валюте депозита / ( Минимальный шаг изменения цены инструмента в валюте котировки /Размер пункта в валюте котировки)

Стоимость пункта ( Инструмент2 ) = Размер минимального изменения цены инструмента в валюте депозита / ( Минимальный шаг изменения цены инструмента в валюте котировки /Размер пункта в валюте котировки)


далее смотрим стоимость пункта какого инструмента больше, допустим Инструмент1


коф= Стоимость пункта Инструмент1/ Стоимость пункта Инструмент2


lot1( Инструмент1 )=lot базовый

lot2( Инструмент2 )=lot базовый*коф

Let's assume we have gold and silver


lot base=0.1;


Point value ( GCG0 ) =10/(0.1/0.1)=10;

point value ( SIH0 ) =25/(0.005/0.001)=5;


kof= 10/5=2;


lot1( GCG0 )=0.1;

lot2( SIH0 )=0.1*2=0.2;

 

OK. Thank you. We'll look into it.

Another question for everyone who can answer.

I am currently testing an EA following the declared methodology, which is able to work in the tester - with simulated virtual trades on the second instrument.

It works fine, but there is a problem with displaying the comment.

When activating the comment the problems start.


Sometimes it works fine.

But more often the log (when the comment is turned on) starts displaying division by zero - ZERO DIVIDE

After analysis, we have managed to find out that this appears due to division

to /POINT_1 and /POINT_2, in several places in the comment code where

double POINT_1 = MarketInfo( Symbol_1,MODE_POINT); 
double POINT_2 = MarketInfo( Symbol_2,MODE_POINT); 
I can't do without these actions as otherwise I can't get the current profit/loss of the virtual trades on the second instrument in pips.

Has anyone encountered this problem?

How can I eliminate theZERO DIVIDE here ?

 

I am interested in the topic, and before I get down to practical implementation of the idea, I'll allow myself a couple of theoretical considerations:


  • The correlation of instruments is not constant, you have to understand that. Even in a pair like pork and beef, an event may occur that will reverse the correlation to -1 (for example, in a swine flu outbreak, pork will go down in price and beef as a competitor will go up in price) and we can get unlimited losses, because we enter against the trend on the spread, in the hope that it will go down. This can be solved by making a portfolio of many uncorrelated pairs and thinking about loss control (not over sitting).
  • As timbo rightly pointed out, we should assess the stationarity of the spread. Roughly speaking, we should estimate the dynamics of MA and RMS from the spread. They should be constant (+/-) on the entire history. Or alternatively, we can plot the distribution of spread values - ideally we should obtain a Gaussian with the vertex at 0. It all should be done to automate/accelerate the selection of pairs into the portfolio.
  • I'm not quite sure that forex-k's approach is correct in terms of spread construction (subtracting the muving from the price). Sure it brings prices to a common denominator, but it doesn't take into account point weight. For example, a 5% change for one instrument would be 300 pips and for another it would be 600. In this case we will get a huge spread, but there will be no expected return to 0 (since the % change is the same). In my opinion, it is more interesting to draw the spread from Close[i]/Close[i+n], then we will be able to estimate the spread in relative (%) change.
  • As for lot calculation - not only point value should be taken into account, but also volatility of instruments to equalise movements that are the same in %.
Forgive me for saying too much, but I prefer to think a bit before rushing into battle with a sword :-)
 
neoclassic >>:

Я заинтересовался темой, и перед тем, как приступить к практической реализации идеи, позволю себе пару-тройку теоретических соображений:


  • Я не совсем уверен что подход forex-k верен в плане построения спреда (вычитание мувинга из цены). Конечно это позволяет привести цены к общему знаменателю, но не учитывает вес пункта. Например изменение на 5% для одного инструмента составит 300 пунктов, а для другого - 600. В этом случае мы получим здоровенный спред, но ожидаемого возврата к 0 не будет (т.к. в % изменились одинаково). На мой взгляд интереснее строить спред от Close[i]/Close[i+n], тогда мы сможем оценивать спред в относительных (%) изменениях.

I have taken this into account in the new versions of the indicator, and I also use equalising coefficients

 
neoclassic >>:

корреляция инструментов - штука не постоянная, это надо понимать. Даже в такой паре как свинина и говядина может наступить событие, которое обратит корреляцию до -1....

By the way, a curious situation is now taking place in the cereals market!

Wheat, maize, beans ... -

Sluggish downward trend. Interestingly, the lines of the traded instruments have converged almost at the same point!
What could it mean from a fundamental point of view?
ZC+ZW+ZS+ZM.
It doesn't happen that often on history.

 
rid писал(а) >>

I am now testing an EA according to the stated methodology, able to work in the tester - with simulated virtual trades on the second instrument.

It works fine, but there is a problem with displaying the comment.

Has anyone encountered this problem?

How do I fix ZERO DIVIDE?

In the Tester by someone else's symbol MarketInfo far not always displays what I need, only online works fine.

 

Found official comment:

Moderator
5084
stringo 25.03.2009 10:19

How many times can I repeat myself and write? MarketInfo in the tester does not work! Except for only a few queries.

 

I'm still assuming that this particular glitch has nothing to do with MarketInfo.

Here it is now - done - as described here:

"zero divide" error .......... who's the fool????

and it seems to be working so far (whew, whew, whew).

 

Yes, - see these MarketInfo functions

double Ask_1 = MarketInfo(Symbol_1,MODE_ASK);
double Bid_1 = MarketInfo(Symbol_1,MODE_BID);
double Ask_2 = MarketInfo(Symbol_2,MODE_ASK);
double Bid_2 = MarketInfo(Symbol_2,MODE_BID)
double POINT_1 = MarketInfo(Symbol_1,MODE_POINT);
double POINT_2 = MarketInfo(Symbol_2,MODE_POINT);
This is how my "arbitrator's" work is displayed now in the visual tester run:

(in work - open second hedge: buy BRN + sell CL, - and the current course of transactions - is displayed - both individually, - and collectively: -112 +101 = 11)

It remains to synchronize the work of the EA by bars. Since both of these instruments are often traded at different times.


Reason: