Download MetaTrader 5
To add comments, please log in or register
Enable MQL5 Storage to store your source codes. It is free!
Ed
19
Ed 2007.03.12 19:06 
Hi All,

I am very new to MQL4 but have been wondering about the possibility of a trianngular arbitrage EA for a while.

Here is the code ,courtesy of Codersguru, for a fractional product oscillator.
I notice this uses MODE_CLOSE for each pair, could this be applied to live tick data?
As I am assuming close data will not be reliable for triangular arbitrage,could anyone confirm this?

#property link      "http://www.xpworx.com"
#property copyright "Coders' Guru" 
 
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_level1 0
 
 
 
double Main[] , EurUsd[] ,UsdJpy[] ,EurJpy[] ;
 
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(4); 
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Main);
   
   SetIndexBuffer(1,EurUsd);
   SetIndexBuffer(2,UsdJpy);
   SetIndexBuffer(3,EurJpy);
 
   ArrayInitialize(EurUsd,EMPTY_VALUE);
   ArrayInitialize(UsdJpy,EMPTY_VALUE);
   ArrayInitialize(EurJpy,EMPTY_VALUE);
   ArrayInitialize(Main,EMPTY_VALUE);
 
   return(0);
  }
 
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
 
//+------------------------------------------------------------------+
int start()
  {
 
   ArrayCopySeries(EurUsd,MODE_CLOSE,"EURUSD",Period());
   ArrayCopySeries(UsdJpy,MODE_CLOSE,"USDJPY",Period());
   ArrayCopySeries(EurJpy,MODE_CLOSE,"EURJPY",Period());
 
   int counted_bars=IndicatorCounted();
   int i = 0;
 
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   
   for(i=0; i<limit; i++)
   {
       Main[i] = EurUsd[i]* UsdJpy[i]* (1/EurJpy[i]);
   }
 
   return(0);
  }
//+------------------------------------------------------------------+

It would be great if somebody could make this open the hedge (i.e buy EURUSD, buy USDJPY, sell EURJPY simultaneously) when 1.0003 <FPI<0.9997,
and swap close or open when the opposite extreme is reached.
Granted the profits will be small and the above parameters may not be wide enough, but I would love to forward test this system anyway,
as it may be forexs' only "FREE LUNCH"
Bogdan Caramalac
1103
Bogdan Caramalac 2007.03.13 19:17  
There is still much to learn... Michal hid "the gold in some places, for the friends to look for it"... A crucial mistake that you do is using MODE_CLOSE. .. you lose what happens during the chosen period. Plus that only one ring is not enough.
Ed
19
Ed 2007.03.14 23:21  
Hello'

"A crucial mistake that you do is using MODE_CLOSE"

I had already realized this if you refer to the top of the original post. My question was how to correct the problem, please be aware that I know()0 about programming, see!
Also I have tried the same indicator with various trios, but cant capitalize till the aforementioned issue is resolved.
Bogdan Caramalac
1103
Bogdan Caramalac 2007.03.15 08:40  
Do not make an indicator. Instead, make a script that loops continuously and print when FPI gets out of regular range...
Jos Theelen
45
Jos Theelen 2007.03.16 17:07  
I advice against this system. I tested something like this some time ago and noticed the following:
When there are strong jumps in one of the currencies (like just after newsreports), then 2 of those pairs move very fast. That often means there is a chance on a hedge. However when you would automatically send orders, you will see that mostly only one of the orders is accepted for the price you wish, and the other is not accpeted. And the one that was accepted will be the losing one.
Bogdan Caramalac
1103
Bogdan Caramalac 2007.03.18 13:34  
I don't have anything better on this. It's true that they are accepted with slippage, however i'm confronting the problem when one of them is not accepted at all, even if i catch execution in a while loop:

for (i=0;i<NoOfContracts;i++)
{
//WriteLn("Sending order "+OrderType2Str(Ops[i])+" "+DoubleToStr(Lots[i], 2)+" "+Contracts[i]);
Gle=ERR_TRADE_CONTEXT_BUSY;
while (Gle==ERR_TRADE_CONTEXT_BUSY||Gle==ERR_REQUOTE)
{
if (Gle==ERR_REQUOTE)
{
RefreshRates();
if (Ops[i]==OP_BUY)
Prices[i]=MarketInfo(Contracts[i],MODE_ASK);
else
Prices[i]=MarketInfo(Contracts[i],MODE_BID);
}
OrderSend(Contracts[i],Ops[i],Lots[i],Prices[i],AdmittedSlippage,0,0,comm,AccountMagic, 0,CLR_NONE);
Gle=GetLastError();
if (Gle==ERR_NO_CONNECTION)
{
if (i!=0)
Gle=ERR_TRADE_CONTEXT_BUSY;
else
break;
}
}
if (Gle==ERR_NO_CONNECTION)
break;
if (Gle!=0)
error=True;
}

I have a similar problem closing them too...
Anyway, the broker plays even a more important role than the strategy itself.
Ahmed Soliman
11988
Ahmed Soliman 2010.10.14 20:37  

You can update the FPI indicator from here:

FPI Indicator

Last update: 11 Oct 2010

Ahmed Soliman
11988
Ahmed Soliman 2011.09.30 20:11  
Francois Rivard
8
Francois Rivard 2011.11.30 02:13  

I have looked at the Triangular Arbitrage Indicator. That is interesing. But can you give me a pointer as to how one would be able to use this indicator to trade? You have three pairs involved. One of the pair is probably lying (lagging / slightly off) but you don't know which one is right and wrong.

Boris Fesenko
25
Boris Fesenko 2012.01.12 03:58  
zzuegg
1491
zzuegg 2012.01.14 16:44  
DesertSkater:

I have looked at the Triangular Arbitrage Indicator. That is interesing. But can you give me a pointer as to how one would be able to use this indicator to trade? You have three pairs involved. One of the pair is probably lying (lagging / slightly off) but you don't know which one is right and wrong.

Yes, thats true. You trade all 3 pairs simultaneously. If you do the programming right, trade only when FPI > SumOfSpread+Commision the Triangular Arbitrage system works perfectly on demo accounts. However i never got the same results when trying it on a live account due to higher slippage, requotes, higher spread and higher commisions.

In theory a unbeatable system, which does not work well as an average trader

/ /12
To add comments, please log in or register