Spread trading in Meta Trader - page 163

 

When calculating the lot ratio, I do the following:

1. first, two external variables (let us call them "volatility coefficients" of two FI) are assigned values of 1

2. from the desired point in time (set in the external variables) - at the same time I look through both charts to detect "left" spikes: as a rule, on M5, M15 the last month is more or less normal - we plot the pair movements in ticks in a separate window:

extern datetime start = D'2011.01.19 03:00'; //время начала отрисовки тиковых графиков
extern double K1=1.0; //коэффициенты пропорциональности (для волатильности) устанавливаем визуально
extern double K2=1.0;
extern double Y_shift=0; //смещение по вертикали тикового графика второго инструмента

TickSize_1=MarketInfo(Symbol(),MODE_TICKSIZE); 
TickSize_2=MarketInfo(Symbol_2,MODE_TICKSIZE);

int bar2_1=iBarShift(Symbol_2,0,Time[i],false); //для синхронизации
int bar2_2=iBarShift(Symbol_2,0,Time[i+1],false);
double Close2_1=iClose(Symbol_2,0,bar2_1);
double Close2_2=iClose(Symbol_2,0,bar2_2);

StartBar=iBarShift(NULL,0,start,false);


    if(i==StartBar)
      {
      TM_1[i]=K1*(Close[i]-Close[i+1])/TickSize_1;
      TM_2[i]=(K2*(Close2_1-Close2_2)/TickSize_2)+Y_shift;
      }
    else
      {
      if(i<StartBar)
        {
        TM_1[i]=K1*((Close[i]-Close[i+1])/TickSize_1)+TM_1[i+1];
        TM_2[i]=K2*((Close2_1-Close2_2)/TickSize_2)+TM_2[i+1];
        }
      }


this is the start of the process:

preliminary value of lots is defined from (although this has to be checked - e.g. depo currency $ and FDAX tick = 12.5 EUR):

TV_Sym1=MarketInfo(Symbol(),MODE_TICKVALUE);
TV_Sym2=MarketInfo(Symbol_2,MODE_TICKVALUE);

then select 2 similar figures and measure the height of each in ticks:

for oil QM for oil BRN

as we see, in this part of the chart BRN has moved 88 ticks, QM - 56,5 (it is possible to find many similar figures /ten will be enough/ and get thus the ratio of the sum of moves of one instrument to the sum of moves of another) I will not do it in this example, I will just set K2 coefficient to 88/56,6=1,56

the result of this gesture (in parallel we measure the difference of the graphs in this place by height - 43,8 ticks):

now we set external variable Y_shift=43,8 and check:

in this case the calculation of lots is done automatically by this code:

//---- расчет соотношений объемов по паре (TICK_VALUE предварительно проверять!)
  double L1=1,L2=1; //предварительно для обоих инструментов установим объемы по 1 лоту
  
  if(K1>K2) L1=NormalizeDouble(K1/K2,2);
  else if(K1<K2) L2=NormalizeDouble(K2/K1,2);
  
  if(TV_Sym1>TV_Sym2) L2*=NormalizeDouble(TV_Sym1/TV_Sym2,2);
  else if(TV_Sym1<TV_Sym2) L1*=NormalizeDouble(TV_Sym2/TV_Sym1,2);
  
  if(L1>L2) {L1/=L2; L2=1;}
  else if(L1<L2) {L2/=L1; L1=1;}

as you can see, the result has changed: i.e. 1.25 / 1 (once again please note that 1 figure is not enough!)

I should note that I had no discrepancies with Leonid (I checked several pairs this way)

Z.I. don't mind that one of the tools is a glue - for the example it's insignificant

 
PPC:

The preliminary value of lots is defined from (although this has to be checked - e.g. the depo currency is $ and the FDAX tick = 12.5 EUR):

A similar problem has been solved as follows:

double TrueTickValue( string Symb )
{
  double TickValue = MarketInfo(Symb, MODE_TICKVALUE);
  double Tmp = MarketInfo(Symb, MODE_MARGININIT);
 
  if ((MarketInfo(Symb, MODE_MARGINCALCMODE) > 0) && (Tmp > 0))
    TickValue *=  MarketInfo(Symb, MODE_MARGINREQUIRED) / Tmp;
 
  return(TickValue);
}
My method of finding the spread is based on solving an optimization problem and is fully automated for any number of FI.
 
hrenfx:

A similar problem was solved this way:

Absolutely agree. 100% will work. A very simple and logical construction. (with your permission, I'll add it to my piggy bank)

 
hrenfx:
My method of finding the spread is based on solving an optimization problem and is fully automated for any number of FI.
Well, no comments here, because I am not honoured to be acquainted with your idea :)
 
PPC:
Well, no comments here, because I am not honoured to be acquainted with your idea :)

Here is the problem statement and here is the solution.
 
hrenfx:

Here is the problem statement and here is the solution.
thanks for the information - there is a lot of material to study.
 

By the way, for oil, it is more reasonable to arbitrage the CL (or WTI) - BRN spread

The dimensions are the same. And analysts' comments are all made for the dimension of the BRN - CL spread

By the way - an interesting comment this morning. http://top.rbc.ru/finances/07/02/2011/539457.shtml

In general, many "commodity" analysts assume that now this spread(BRN - CL) has reached 11 figures, it won't grow further and there is a reason to get into a long term contraction.

 

Current situation BRNH1-CLH1=1^1, H1

 
leonid553:

By the way, on oil it is more reasonable to arbitrage the CL (or WTI) - BRN spread

I was just giving an example of the calculation technique itself...
 

Well, here's a little treat for those in attendance.

The HEJ1-HEK1 calendar pork spread (April-May).

Perennial seasonal trends . No comment!

However, there will be a comment. Positions to open on this spread - better in the midst of American session trading after 18:30 Moscow timeframe. At this time the Ask Bid of these pork instruments is significantly and meaningfully smaller - dozens of times!

Reason: