Spread trading in Meta Trader - page 187

 
khorosh:
...

I'm posting the script I just wrote today to discuss possible errors or misinterpretation of some concepts, as I'm new to the topic. The script outputs the results on the chart using Comment(). It calculates the average value of the maximum daily price divergence for the two instruments, as well as the current (momentary) divergence. I ask connoisseurs to review and comment.

Warning!!! The script is only good for pairs with direct correlation.



Adjusted the script: Previously DivAver was subtracted from CurrentDiv and DivAverMax, but now the latter two values are divided by DivAver . However, there are doubts about the general methodology of the calculation. Therefore, I am waiting for some reasoned criticism.
 
sayfuji, what kind of advisor is this?
 
leonid553:

EURGBP-DXZ1 =2:3 (EUR GBP RP - USD index DX, - both instruments here simultaneously sell or simultaneously buy when paired entry on the divergence - I entered Friday night to buy both)

At the request (personal) of the branch visitor I am pasting the final result of Friday's pair entry.

I entered at timeframe 15.BUY EURGBP - BUY DXZ1 = 0.05^0.09

I have now closed the spread positions on a convergence of price lines. I closed it with tiny profit, almost breakeven. I was hoping for more ...

 
khorosh, you are welcome to trade. Just choose your words periodically, and don't be a schoolboy. And you'll be fine.
 
leonid553:

khorosh, - I looked at the code.

The dimensionality of both instruments seems to be taken into account. Coefficients p1 and p2. I don't know, - but if instruments have reverse correlation (example below), - does this script display data correctly?

EURGBP-DXZ1 =2:3 (EUR GBP RP - USD index DX, - both instruments here simultaneously sell or simultaneously buy on a divergence pair entry - I entered into a buy both on Friday evening)

Leonid, why doesn't the indicator Spread_I_env take into account the forward or reverse correlation of traded instruments, as it is done in the indicator Ind_2 Line+1? If it were taken into account, the chart of this indicator for the instruments with reverse correlation would be absolutely different. In particular, for sure there would not be such trends on the spread chart. It would be good if it were bound to the zero level like the Ind_2 Line+1 indicator. I do not know much about indicators, I just deal with Expert Advisors, otherwise I would have done it myself.

 

This indicator - just has the ability to take into account the inverse correlation! In the above chart for the EURGBP-DXZ1 spread and in the chart below for the same spread - just for the drawing of the spread line with inverse correlation! I.e. for the case where we sell both spread instruments at the same time or buy at the same time!

Here is my yesterday's entry to sell instruments of this spread on divergence of price lines:

SELL RPZ1 - SELL DXZ1 = 0.04^0.07 - At the point of convergence of price lines I closed my position today with small profit...

To set drawing of a spread line of pair of instruments with an inverse correlation - it is necessary in Properties of the indicator to set the size of a position of the second (any) instrument with a "minus" sign! See picture -

How to tie the scale to zero - I did not think. And whether it is necessary? The scale in dollars shows the change in total equity (by default, EquityScale = true; // Show equity scale), i.e. the spread lines - in accordance with the specified position sizes.

And if you want to display an entry point, you can simply set an additional horizontal level in the Properties/Levels of the indenture - at the level of the paired entry!

 
leonid553:

This indicator - just has the ability to take into account the inverse correlation! In the above chart for the EURGBP-DXZ1 spread and in the chart below for the same spread - just for the drawing of the spread line with inverse correlation! I.e. for the case where we sell both spread instruments at the same time or buy at the same time!

Here is my yesterday's entry to sell instruments of this spread on divergence of price lines:

SELL RPZ1 - SELL DXZ1 = 0.04^0.07 - At the point of convergence of price lines I closed my position today with small profit...

To set drawing of a spread line of pair of instruments with an inverse correlation - it is necessary in Properties of the indicator to set the size of a position of the second (any) instrument with a "minus" sign! See picture -

How to bind the scale to zero - I did not think. And whether it is necessary? The scale in dollars shows the change in total equity (by default, EquityScale = true; // Show equity scale), i.e. the spread lines - in accordance with the specified position sizes.

And if you want to display an entry point, you can simply set an additional horizontal level in the Properties/Levels of the indenture - at the level of the paired entry!

Thank you! - I didn't know.
 
vis_inet:
sayfuji, what kind of advisor is this?
Trade-Arbitrage.
 
leonid553:

Leonid, what should be the correlation coefficient for the pairs you have chosen to trade? Apparently, there has to be a golden mean. If the ratio is too high, the drawdown is small, but the spread is also small and therefore the profit is small. And vice versa, low correlation results in large spread, but large drawdowns. I wonder if anyone has solved this optimization problem.
 

I did not use the correlation coefficient. I have visually selected several pairs for arbitrage entries on tf=m15 and work in the following way:

I wait for divergence of price lines and simultaneous deflection of the spread indicator line beyond the specified boundary (upper or lower) of the channel. At the beginning of the subsequent convergence of price lines, and a simultaneous reversal of the spread line from its local extremum (minimum or maximum), I implement a paired entry (see fig. - a typical example).

It is already mentioned above "tandems" EURGBP-DX=1^2, EURGBP-USDCHF=1^1. (both tandems with inverse correlation), sometimes single EURCHF (along the lines of eurusd-usdchf, etc.).

Silver-gold, futures SIZ1-GCZ1=1:2 (sometimes 2:5), direct correlation, - on tf=m30 (less often m15)

(On spot precious metals too exorbitant asc-bid in MT4)

As for the profit. I always try to work so as to minimize drawdown. I'd rather have higher correlation and lower profit! But trading will be more comfortable and reliable! I would rather trade more comfortably and securely than scratch my head in case of large loss jumps!

Possible losses on small TFs can in most cases be minimizedif the following rule is strictly observed:

After a paired entry, with any current result, always close positions at the subsequent convergence of price lines (i.e., at their intersection). Or - when the signal (two-color) line crosses the mid-zero level! It is mandatory to close! This rule has been developed during almost a year of trading on the tf=m15-m30!

It is also allowed to close positions when the spread indicator line reaches the opposite channel boundary!

If price lines are diverging (not crossing) long and boring (see the upper chart for the last days), it is better to abstain from entering. And wait a few days.

=================

Good luck to all!