Hola, os dejo el codigo de un EA que he realizao que calcula la divergencia en anillos de pares de divisas. si quereis añadir alguna basta con poner un linea nueva en la tabla de variables donde se cumpla que el primer par por el segundo dividido por el tercero sea igual a 1.
"USDCAD","CADCHF","USDCHF",
en esta linea que os he pegado se cumple que el USDCAD multiplicado por CADCHF = USDCHF.
y si añaís algun par más enconces incrementar en uno la variable "int total_anillos = 7;" y añadir uno a la dimension de la tabla de anillos. "anillos[7,3]"
//+------------------------------------------------------------------+
//| anillos.mq4 |
//| Copyright © 2011, MetaQuotes Software Corp. |
//|
http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link "
http://www.metaquotes.net"
string anillos[7,3]={"EURGBP","GBPUSD","EURUSD",
"EURUSD","USDCHF","EURCHF",
"USDCAD","CADCHF","USDCHF",
"EURCAD","CADJPY","EURJPY",
"EURUSD","USDTRY","EURTRY",
"GBPAUD","AUDCAD","GBPCAD",
"GBPAUD","AUDUSD","GBPUSD"};
int total_anillos = 7;
string anillo1;
string anillo2;
string anillo3;
double comprar,vender;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int coord_y =330;
string objeto="ob";
color colorobc,colorobv;
double ask1,ask2,ask3,bid1,bid2,bid3;
for (int x=0;x<total_anillos;x++)
{
anillo1 = anillos[x,0];
anillo2 = anillos[x,1];
anillo3 = anillos[x,2];
ask1 = MarketInfo(anillo1,MODE_ASK);
bid1 = MarketInfo(anillo1,MODE_BID);
ask2 = MarketInfo(anillo2,MODE_ASK);
bid2 = MarketInfo(anillo2,MODE_BID);
ask3 = MarketInfo(anillo3,MODE_ASK);
bid3 = MarketInfo(anillo3,MODE_BID);
comprar = (ask1 * ask2) / bid3;
vender = (bid1 * bid2) / ask3;
if (comprar < 0.9990 || vender > 1.0009)
{
if (comprar < 0.9990)
{
colorobc = Green;
}
if (vender > 1.0009)
{
colorobv = Red;
}
}
else
{
colorobc = DeepSkyBlue;
colorobv = DeepSkyBlue;
}
objeto = objeto + DoubleToStr(x,0) ;
creaobjeto(objeto,200,coord_y,DeepSkyBlue,anillo1+"/"+anillo2+"/"+anillo3);
objeto = objeto + DoubleToStr(x,0) ;
creaobjeto(objeto,150,coord_y,colorobc,DoubleToStr(comprar,Digits));
objeto = objeto + DoubleToStr(x,0);
creaobjeto(objeto,100,coord_y,colorobv,DoubleToStr(vender,Digits));
coord_y = coord_y + 10;
}
return(0);
}
void creaobjeto(string name,int X,int Y,color Color,string text)
{
for ( int i=ObjectsTotal()-1; i>-1; i--)
{
if (StringFind(ObjectName(i),name) >= 0) ObjectDelete(ObjectName(i));
}
if(!ObjectCreate(name, OBJ_LABEL,0,0,0))
{
Print("error: can't create text_object! code #",GetLastError());
return(0);
}
ObjectSet(name,OBJPROP_XDISTANCE,X);
ObjectSet(name,OBJPROP_YDISTANCE,Y);
ObjectSet(name,OBJPROP_CORNER,1);
if(!ObjectSetText(name, text,8,"Courier New", Color))
{
Print("error: can't set text_object! code #",GetLastError());
return(0);
}
}