Spread trading in Meta Trader - page 31

 
neoclassic >>:

Продавая USDCAD и покупая DX вы покупаете индекс канадца. На поведение индекса можно посмотреть с помощью того же СС - его динамика ничем не отличается от других индексов. Так что такая торговля на мой взгляд - будет 50/50.


It's possible! I'm not going to argue.

So we'll keep looking. Looking for other suitable tools.

By the way. Yesterday close to the end of trading on Fduch index I entered (BUY ZC + SELL ZW)

Now there is {+300 pips (corn) -175 pips (wheat) }

 
neoclassic >>:

Продавая USDCAD и покупая DX вы покупаете индекс канадца. На поведение индекса можно посмотреть с помощью того же СС - его динамика ничем не отличается от других индексов. Так что такая торговля на мой взгляд - будет 50/50.


Then please calculate the formula for the Canadian index formula. If it exists, of course ))) ... Actually rid, it is better to take of course the eur in "tandem". As it has more weight in the index. Just put a minus sign in the formula of the indy for its normal display. And can you share how you calculate the coefficient for the "tandem", i.e. the weight of the pairs in the deal?

 

I haven't really made any serious calculations yet. I.e. - so far by eye, - roughly.

For (Dax/Futsi) - the ratio of lots 1.2/3 and delta not less than 200 T, - I've deduced as a result of many weeks of observation.

EURIPY+USDJPY - I take the same lot sizes. For 2.5 weeks of working online (delta = 20-30 pips) this "hedge" hasn't spent more than 2-3 days.

I closed it with total profit from 5 to 20 pips.

 
"Multi-week surveillance"? Wouldn't it be easier to just collect data?
 

Unlikely to work out. "Crazy Dax(c) and "pretty Footsie"(c) in the "discussed version" are traded on different platforms.

Futsi starts an hour later than Dax on a daily basis. Moreover, there are quite a few days in history when the dax was trading and the futsi was "off", or vice versa. So, the history of these instruments is shifted many times relative to each other and, for that reason, has little credibility.

 
rid >>:

Вряд ли получится. "Бешеный Дакс"(с) и "красотка Футси"(с) в "обсуждаемом варианте" торгуются на разных площадках.

Ежедневно футси стартует на час позже дакса. Более того, на истории достаточно много дней, когда дакс торговался, а футси был(а) "на выходных", или наоборот. Так что, история этих инструментов многократно сдвинута относительно др-друга и, по этой причине, мало достоверна.

That's fine. We will never play better than the big uncles on their field. And on a field like this, the big uncles have no business.

This is our bread and butter.

 
Fduch >>:
По открытиям баров

I am making a "quasi-arbitrage" EA that can be run in the tester on both "hedge" instruments with simulated virtual trades on the 2nd symbol.

There is a question.

Please advise.

How do I change your function

//--------------------------------------------------------------------+
//ФУНКЦИЯ РАСЧЕТА СРЕДНЕСТАТ.СПРЕДА                    |
//--------------------------------------------------------------------+               
  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);
}

It would not return average spread of last NBars ?

But for the penultimate NBars.

I.e. for a period from(2*NBars)-th bar to the NBars?

Question to all who can answer.

Because I'm sitting here, I can't figure it out.

 
//--------------------------------------------------------------------+
//ФУНКЦИЯ РАСЧЕТА СРЕДНЕСТАТ.СПРЕДА                    |
//--------------------------------------------------------------------+               
  double CalculateAvarageSpread(string Symbol_1, string Symbol_2,
                              int Timeframe, int NBars)
{
   int k;   double N = 0;   double Sum = 0;
   for( k = NBars; 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);
}
 

Thank you, getch! I'll put it into action now.

It turned out to be easier to implement virtual trades of the second hedge instrument in the tester than I initially thought.

I built the work by opening prices because the tester doesn't return MarketInfo(Symbol_2,MODE_BID) Bids and Asks; but opening and closing prices are returned by the tester normally.

Now I test it with tf=m1 for better accuracy

For those who are interested and who need it, here are fragments of our (rid+leonid553) program solution.

Hedge opening of 1 type (i.e. sell1+by2) :

I would be happy to receive critical comments.

double POINT_1 = MarketInfo( Symbol_1,MODE_POINT); 
double POINT_2 = MarketInfo( Symbol_2,MODE_POINT); 

double  Close_Symbol_1 = iClose( Symbol_1,Period(),1); 
double  Close_Symbol_2 = iClose( Symbol_2,Period(),1);
//-----------------------------------------------------



if ( TradeUP==true && флаг1==0) {//если условия первого хеджа
//соответствуют заданным  
//продаем 1-й символ и покупаем второй символ 
//-------------------------------------
if(Symbol()!= Symbol_2 && IsTesting() == True) {//при тестировании 2-го
// инструмента команду  не выполняем !
if ( NumberOfPositions( Symbol_1,OP_SELL, Magic)<1  ){//нет поз селл по 1-му символу
 SL=0; TP=0;
if( StopLoss>0)   SL= Bid_1+ POINT_1* StopLoss;
if( TakeProfit>0) TP= Bid_1- POINT_1* TakeProfit; 
ti= OpenPosition( Symbol_1, OP_SELL, Lots_1,0 ,0, Magic);
if (OrderSelect( ti, SELECT_BY_TICKET))
 ModifyOrder(-1, SL, TP, clModifySell);  
    }
                   }//if (IsTesting() == True)
//--------------------------------------
if(Symbol()!= Symbol_1 && IsTesting() == True) {//при тестировании 1-го
// инструмента команду не выполняем !
 if ( NumberOfPositions( Symbol_2,OP_BUY, Magic)<1) { //нет  поз бай по 2-му символу 
   SL=0; TP=0;
if( StopLoss>0)   SL= Bid_2- POINT_2* StopLoss;
if( TakeProfit>0) TP= Ask_2+ POINT_2* TakeProfit;   
ti= OpenPosition( Symbol_2, OP_BUY, Lots_2,0,0, Magic);
if (OrderSelect( ti, SELECT_BY_TICKET))
  ModifyOrder(-1, SL, TP, clModifyBuy); 
          }
                         }//if (IsTesting() == True) {         
//--------------------------------------------------                                                    
                                 } //если условия соответствуют заданным

Next, actually - the virtual trades mechanism itself in the "hedge" closing block :

 

Next, the virtual transaction mechanism itself in the "hedge" closing block:

The closing and calculation of the total profit is probably of key importance here!

if ( Symbol()== Symbol_1 ){//если прогоняем  1-го инструмент
//--------------Закрываем первый хедж -----------------------------------
//задаем и вычисляем номер бара открытия реальной селл 1-го 
//инструмента - с магиком 1
int N_of_barOP_SELL_1 = NumberOfBarOpenLastPos( Symbol_1,0,OP_SELL, Magic);
//задаем цену открытия этого бара на 2-м инстр., равную  цене открытия 
//виртуальной поз.BUY на втором иструменте(магик)
double OpenBUY_Symbol_2=iOpen( Symbol_2,Period(), N_of_barOP_SELL_1);


if (    ( ( PriceOpenLastPos( Symbol_1,OP_SELL, Magic)- Close_Symbol_1) +
        ( Close_Symbol_2- OpenBUY_Symbol_2) )  >=  CloseProfit* POINT_1 ){
 //если суммарный профит реальной сделки селл 1-го
// инструмента и "виртуальный" профит сделки Бай 2-го
// инструмента (хеджа TradeUP) по факту больше заданного
//значения, то - закрываем реальную OP_SELL 1-го символа и
// виртуальную OP_BUY второго символа
        ClosePosFirstProfit( Symbol_1,OP_SELL, Magic);
        if (IsTesting() != True){// при тестировании команду не выполняем ! 
        ClosePosFirstProfit( Symbol_2, OP_BUY, Magic);
                                  }
                         }
//------------ Закрываем второй хедж -------------------------------------
      аналогично
//----------------------------------------------                          
                         }//if ( Symbol()== Symbol_1 ){

That's all there is to it...

In the same way we do closing of the second instrument in a tester run(if ( Symbol()== Symbol_2 )

Used f-and Igor Kim(hats off to him) :

OpenPosition(); - opening a pose.

ModifyOrder(); - modification of positions.

NumberOfPositions() - number of positions

PriceOpenLastPos() - open price of the last position

ClosePosFirstProfit() - closing of positions

NumberOfBarOpenLastPos() - returns the number of bar of the last position opened


Reason: