Spread trading in Meta Trader - page 14

 
timbo >>:

PS Кстати, корреляция между элементами пары не обязательна.

I don't get it.

 
rid >>:

Немного сегодня побаловался советником с валютными "хеджами".


Sorry, I may have missed it, but what is the advisor...? Is it posted somewhere?

 

No. This particular EA has not been posted. It's still raw.

However, its functionality is described in the last post on p. 4, the first one on p. 5 and the post from rid on 29.12.2009 16:28 on p. 9.

And also in related posts from rid you can find some code snippets

 

That's where the problem surfaced. Where I wasn't expecting it to come from.

//----- Вывод информации на экран -----------------------------------------
string info="";
string on_off="---------------------------------------------------"+  "\r\n";
on_off=StringConcatenate  (
 "Среднестат.Спред = ", CalculateAvarageSpread( Symbol_1, Symbol_2,0, NBars)/ POINT_Tiker1);

//если 1-й продан а второй куплен
if ( NumberOfPositions( Symbol_1,OP_SELL, Magic)>=1  )
string on_off2=StringConcatenate ( on_off2,
"Текущая прибыль Sell-UP = ",( PriceOpenLastPos( Symbol_1,OP_SELL, Magic)- Ask_Tiker1)/ POINT_Tiker1,"\n");
else         on_off2=StringConcatenate ( on_off2,"Нет OP_SELL-сделок UP","\r\n");

if ( NumberOfPositions(Symbol_2,OP_BUY, Magic)>=1  )
string on_off3=StringConcatenate ( on_off3,
"Текущая прибыль BUY-UP = ",( Bid_Tiker2- PriceOpenLastPos( Symbol_2,OP_BUY, Magic))/ POINT_Tiker2,"\n");
else         on_off3=StringConcatenate ( on_off3,"Нет BUY-сделок UP","\r\n");

With this display of the current "hedge" profit in the comment - the profit of the second character (the second trade) is not displayed quite correctly!

Here's why. The Expert Advisor "stands" on the first symbol chart and all the information changes with the arrival of a new tick for this symbol.

But it may happen that during this time, there are several ticks on the second instrument! But this information is not coming to the comment ("The current profit of the 2nd symbol BUY-UP =") because a new tick has not come to the chart (where the EA is) of the first symbol yet!

How do I do it ? How to avoid a mismatch ?

Please advise.

 

I had to change the format slightly - now it's not an EA that trades, but a script. A script with such int start():

int start()
{
    while(IsStopped()==false)
    {
       // весь код эксперта

       // пауза перед следующим проходом
       Sleep(100);
    }
    return(0);
}

Theoretically, we can use such a construct in the Expert Advisor as well, but I haven't tried it. Perhaps there is some specificity like limitation of execution time in main EA, although I doubt it.

 

There was an attempt to apply this technique. Interestingly, when trying to insert
while(IsStopped()==false)
{...... Sleep(100);}

into the EA - the EA itself works. But the entire comment above, for some reason, stops displaying altogether.

However, I'll try it again.

 
getch >>:

Не понял.

The phrase about trading the spread between correlated Assets is constantly heard. But correlation is not a necessary condition. More often than not it will be present in good pairs, but it is more of a consequence than a cause. You can have great pairs to trade without correlation.

 
timbo >>:

Постоянно звучит фраза про торговлю спреда между коррелированными ассетами. Но корреляция не является необходимым условием. Чаще всего она будет присутствовать в хороших парах, но это скорее следствие, чем причина. Можно поиметь отличные пары для торговли и без корреляции.

Spread trading is statistical arbitrage. Using statistical correlations between different synthetic trading instruments.

If there is no correlation, it is classical trading with several trading instruments at once.

 

Но бывает так, что за это время, - на втором инструменте проходят несколько тиков! Но эта информация не поступает в коммент ("Текущая прибыль 2-го символа BUY-UP ="), т.к. на график (где стоит советник) первого инструмента всё еще не поступил новый тик!

Как тут можно поступить ? Чтобы устранить несоответствие ?

Can't you make the initiation happen every second, rather than with the arrival of a new tick? (sorry for the naive question, if anything... I'm just not a programmer myself, so please don't kick me... ))))))

 
rid >>:

Нет. Конкретно этот советник не выложен. Сырой он ещё.

Но суть его работы изложена в посл. посте на стр.4, первый пост на стр.5 и пост. от rid 29.12.2009 16:28 на стр. 9

А также в сопутствующих постах от Рида выложены отдельные фрагменты кода

Thank you, I get the gist of it... I'm trying to use this "theme" myself. I don't know a thing about code, so I'm using all kinds of handy gadgets. I'm looking for something suitable to me.

Are you planning to make your Expert Advisor available to the public or...? It would be interesting to try...

Reason: