Hi Funyoo,

I found interesting codes to trade spot gold as follows. Please kindly make an EA to trade Spot gold based on them:

+ Please make it: 4-digit and 5-digit broker compatible, ECN/STP and Non-ECN broker compatible, trailing stop, breakeven, breakeven gain, Hedging, Martingale with Mutiplier options. Thanks a lot.

Here are the codes:

SVM EA for Gold
//+------------------------------------------------------------------+
//| GOLD_v01.mq4 |
//| Copyright 2008, MetaQuotes Software Corp. |
//| MetaTrader 4 Trading Platform / MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#include <stdlib.mqh>
//#include <OrdersSuite.mqh>
#import "Shell32.dll"
int ShellExecuteA(int Handle, string Operation, string filename, string parametr, string dir, int ShowCmd);
#import
/*
#import "runapp4.dll"
bool Exec2(string exename,string params);
bool Exec2a(string exename,string params);
bool Exec2b(string exename,string params);
#import
*/
/*
signal8 Best -->C=512.0 g=0.0078125 CV rate 2.8
signal8 Best -->C=32768.0 g=0.0001220703125 CV rate 2.6
C=512 g=0.125
.................................................. ......
signal9 Best -->C=32768.0 g=0.0001220703125 CV rate 3.2
C=32.0 g=0.03125
.................................................. ......
signal10 Best -->C=8.0 g=0.0078125 CV rate 0.6
C=32.0 g=0.5
*/
#define NR_BARS_1 500
#define NR_BARS_2 500
#define MAXBS 10
//////////////////////////////
string Symb0 ="";
string signal ="8";
int Signal=8;
string C = "8.0";
string gamma = "2.0";
string nrb1 ="338";
////////////////////////////////
extern int BasePeriod =PERIOD_M30;
extern double Lots =0.1;
extern int TradeStopLoss =80; //30-50pips
extern int TradeTakeProfit =40;
extern bool ReverseSignal=false;
extern bool TradeEnabled =true;
extern int LimitOrderLiveTime=10; //min
int MagicNumber1 = 1001;
int MaxOrdersTotal1=1;
/////////////////////////////////
double level_buy_m30=0.3;
double level_sell_m30=-0.3;
//...............................
double level_buy_h4=0.3;
double level_sell_h4=-0.3;
//...............................
double level_buy_d1=0.3;
double level_sell_d1=-0.3;
/////////////////////////////////
double bb[MAXBS];
double cc[MAXBS];
double dd[MAXBS];
int counter;
int DiffBid=0;
int DiffAsk=0;

string cotdate_end;
//string dosdir1_run="C:\\PROGRA~1\\BROCOT~1\\EXPERTS";
//linux
string dosdir1_run="/home/barnix/.wine/drive_c/Program Files/Broco Trader/experts";
int FutureWindow =1;
string nameData1,nameData2,nameData3;

int NR_BARS1,NR_BARS2;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void find_buysell3(double &buy, double &sell, double &notrade)//nr=120
{

buy= 0;
sell= 0;
notrade= 0;
double b=iCustom(Symbol(),PERIOD_M30,"GOLD_v01",0,0);
double c=iCustom(Symbol(),PERIOD_H4,"GOLD_v02",0,0);
double d=iCustom(Symbol(),PERIOD_D1,"GOLD_v03",0,0);
/*
for (int ii=0;ii<MAXBS;ii++)
{
if(ii<=counter+1)
{

}
else
{
bb[ii]=bb[ii-1];
cc[ii]=cc[ii-1];
dd[ii]=dd[ii-1];
}
}
bb[0]=b;
cc[0]=c;
dd[0]=d;
*/
Print("Level M30=",level_buy_m30," Level H4=",level_buy_h4," Level D1=",level_buy_d1);
Print(" M30=",b," H4=",c," D1=",d);
//Print(" M30=",bb[0]," H4=",cc[0]," D1=",dd[0]);
//Print(" M30=",bb[1]," H4=",cc[1]," D1=",dd[1]);
//Print(" M30=",bb[2]," H4=",cc[2]," D1=",dd[2]);
//Print(" M30=",bb[3]," H4=",cc[3]," D1=",dd[3]);

if(TradeEnabled)
{
if(
b>level_buy_m30 && b<100 &&
c>level_buy_h4 && c<100 &&
d>level_buy_d1 && d<100
)
buy=b;

if(
b<level_sell_m30 && b>-100 &&
c<level_sell_h4 && c>-100 &&
d<level_sell_d1 && d>-100
)
sell=-b;
}
//else
// Print("Trade disabled Perid H1");
}


//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Symb0=="")Symb0=Symbol();
counter=0;
for (int ii=0;ii<MAXBS;ii++)
{
bb[ii]=0.0;
cc[ii]=0.0;
dd[ii]=0.0;
}

//main();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
int o=UninitializeReason();
switch(o)
{
case REASON_CHARTCHANGE:
main(1);
break;
case REASON_PARAMETERS:
main(1);
break;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
main(0);
//----
return(0);
}

/////////////////////////
int PipsAvg2(string Symb, int Per)
{

int d=1;
int i=0;
double sum1=0;

double p=MarketInfo(Symb,MODE_POINT);
if(p!=0)
for(i=0;i<40;i++)
{
sum1=sum1+(iHigh(Symb,Per,i)-iLow(Symb,Per,i))/p;
d++;
}

return(sum1/d);
}

//+------------------------------------------------------------------+
void main(int iii)
{

double res1=0;
double res2=0;
double res3=0;
string comm;
MagicNumber1=CalcMagic();
if (Period() !=BasePeriod)
{
Comment("WARNING: Invalid timeframe! Valid timeframe = "+BasePeriod);
return(0);
}

if ((Symbol() != Symb0) )
{
Comment("WARNING: Invalid symbol! Valid symbol = "+Symb0);
return(0);
}
NR_BARS1=NR_BARS_1;
NR_BARS2=NR_BARS_2;

nameData1 = "B4\\DD\\train"+Signal+"\\"+Symb0+".libsvm"; // name of the data file to be sent
nameData2 = "B4\\DD\\test"+Signal+"\\"+Symb0+".libsvm";
nameData3 = "B4\\DD\\s"+Signal+"\\"+Symb0+".txt";

if(NrOrders(MagicNumber1 )>=MaxOrdersTotal1)
{
if((OrderType1(MagicNumber1)==2) || (OrderType1(MagicNumber1)==-2))
{//if(60*GondolkodasiIdo<(TimeCurrent()-last_order_time))

if(60*LimitOrderLiveTime<(TimeCurrent()-OrderTime1(MagicNumber1)))
OrderDelete(OrderTicket1(MagicNumber1));
}
}

if(isNewBarM1())
{


SaveData();
//ShellExecuteA(0, "", dosdir1_run+"\\FILES\\SVMLIB8\\B4_DD_4.BAT", dosdir1_run+" "+Symb0, "", iii);
//Exec2b(dosdir1_run+"\\FILES\\SVMLIB8\\B4_DD_4.BAT" ,dosdir1_run+" "+Symb0);

string p0="\""+dosdir1_run+"/files/run.sh\"";
string p1="\""+dosdir1_run+"\"";
string p2="\""+Symb0+"\"";
string p3="\""+signal+"\"";
string p4="\""+C+"\"";
string p5="\""+gamma+"\"";
string p6="\""+nrb1+"\"";
string p7="\"/usr/bin\"";
ShellExecuteA(0, "", "start /Unix "+p0, p1+" "+p2+" "+p3+" "+p4+" "+p5+" "+p6+" "+p7, "", 0);

TradeStopLoss=PipsAvg2(Symbol(), PERIOD_D1);
TradeTakeProfit=TradeStopLoss/2;

res1=0;
res2=0;
res3=0;
find_buysell3(res1,res2,res3);
comm=StringConcatenate("Buy1=",DoubleToStr(res1,Di gits)," Sell1=",DoubleToStr(res2,Digits)," NoTrade1=",DoubleToStr(res3,Digits));
Print(comm);


if(NrOrders(MagicNumber1 )<MaxOrdersTotal1)
{
if (res1<(res2))
Sell(MagicNumber1,Lots,TradeTakeProfit,TradeStopLo ss,comm);
else if (res1>(res2))
Buy(MagicNumber1,Lots,TradeTakeProfit,TradeStopLos s,comm);
}
else
{
if ( res1<(res2) )
{
if(OrderType1(MagicNumber1)>0)
{
CloseBuy(MagicNumber1);
Sell(MagicNumber1,Lots,TradeTakeProfit,TradeStopLo ss,comm);
}
}
else if ( res1>(res2) )
{
if(OrderType1(MagicNumber1)<0)
{
CloseSell(MagicNumber1);
Buy(MagicNumber1,Lots,TradeTakeProfit,TradeStopLos s,comm);
}
}
}
}

}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
void SaveData()
{
int handle3;
string s1,s2;

handle3 = FileOpen(nameData3,FILE_CSV|FILE_WRITE,' ');
if(handle3 < 1)
{
Comment("Creation of "+nameData3+" failed. Error #", GetLastError());
return(0);
}
FileWrite(handle3,"stop");
FileClose(handle3);
/////////////////////////
s1=write_data_train_2(); // write the data file
s2=write_data_test_2();
//////////////////////////
handle3 = FileOpen(nameData3,FILE_CSV|FILE_WRITE,' ');
if(handle3 < 1)
{
Comment("Creation of "+nameData3+" failed. Error #", GetLastError());
return(0);
}
FileWrite(handle3,"start");
FileClose(handle3);

}

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+

string write_data_train_2()
{
int handle;
handle = FileOpen(nameData1,FILE_CSV|FILE_WRITE,' ');
if(handle < 1)
{
Comment("Creation of "+nameData1+" failed. Error #", GetLastError());
Print("Creation of "+nameData1+" failed. Error #", GetLastError());
return(0);
}

string ss1;
int i;
/*
<- Bars=Bars1+FutureWindow ->
<- Bars2+FutureWindow ->
+---+---+---+---+---+---+---+---+
Bars-1 0
+---+---+---+---+---+---+---+-----+---+ ... +---+---+---+---+---+---+---+
<- Bars1 ->
+---+---+---+---+-----+---+ ... +---+---+---+---+---+---+---+
FutureWindow FutureWindow
*/
int nb1;
nb1=NR_BARS1+FutureWindow+100;
for (i=(NR_BARS1+FutureWindow)-1; i>FutureWindow-1; i--)
{
ss1= Line1(
nb1,
Symb0,
PRICE_CLOSE,
i,
true
);
// Print(ss1);

FileWrite(handle,ss1);

}
FileClose(handle);

string s1="File "+nameData1+" has been created. "+TimeToStr(TimeCurrent(), TIME_SECONDS);
return(s1);
}

//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+

string write_data_test_2()
{
int handle,handle2,handle3,handle4;
//.................................................. .............................
handle = FileOpen(nameData2,FILE_CSV|FILE_WRITE,' ');
if(handle < 1)
{
Comment("Creation of "+nameData2+" failed. Error #", GetLastError());
return(0);
}
handle2 = FileOpen(nameData2+".t",FILE_CSV|FILE_WRITE,' ');
if(handle2 < 1)
{
Comment("Creation of "+nameData2+".t"+" failed. Error #", GetLastError());
return(0);
}
//.................................................. .............................
handle3 = FileOpen(nameData2+".fw",FILE_CSV|FILE_WRITE,' ');
if(handle3 < 1)
{
Comment("Creation of "+nameData2+".fw"+" failed. Error #", GetLastError());
return(0);
}
//.................................................. .............................
handle4 = FileOpen(nameData2+".cl",FILE_CSV|FILE_WRITE,' ');
if(handle4 < 1)
{
Comment("Creation of "+nameData2+".cl"+" failed. Error #", GetLastError());
return(0);
}
//.................................................. .............................
int i;
string ss1,sig;
int nb2;
nb2=(NR_BARS2+FutureWindow)-1+100;
for (i=(NR_BARS2+FutureWindow)-1; i>=0; i--)
{
ss1= Line1(
nb2,
Symb0,
PRICE_CLOSE,
i,
false
);
FileWrite(handle,ss1);
FileWrite(handle2,DoubleToStr(Time[i],0));
FileWrite(handle4,StringConcatenate(DoubleToStr(Ti me[i],0),",",DoubleToStr(Close[i],Digits)));
}
FileClose(handle);
FileClose(handle2);
FileClose(handle4);
//gFileWrite(file3,DoubleToStr(FutureWindow,0)+","+D oubleToStr(StopLoss,0)+","+DoubleToStr(TakeProfit, 0));
FileWrite(handle3,DoubleToStr(FutureWindow,0));
FileClose(handle3);


string s1="File "+nameData2+" has been created. "+TimeToStr(TimeCurrent(), TIME_SECONDS);
return(s1);
return(s1);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+

double PipsAvg(string Symb, int Per,int m, int b)
{
int d=1;
double p=MarketInfo(Symb,MODE_POINT);
double sum1=0;
if(p!=0)
for(int i=b;i<b+m;i++)
{
sum1=sum1+(iHigh(Symb,Per,i)-iLow(Symb,Per,i))/p;
d++;
}
return(sum1/d);
}

string Line1(
int nb1,
string Symb,
int Price1,
int i,
bool train

)
{
double y1,yy1;
int sh0=0;
int sh1=1;
int sh2=2;
int Per1=5;
int Per2=10;
int Per3=15;
// string ind_name="Better_MA2c_D1_W1_MN";
// string ind_name="Better_MA2c_H4_D1_W1";

/*
//////////////////////////////////////////////
extern string Symbol1 = "";
extern int ClosePeriod = 8;
extern int NrBars = 500;
extern int Shift1=0;
extern int price=PRICE_CLOSE; //PRICE_HIGH,PRICE_LOW,PRICE_OPEN
extern int Period1=PERIOD_H4;
//.............................
extern string Symbol1 = "";
extern int VolumePeriod = 8;
extern int NrBars = 500;
extern int Shift1=0;
extern int price=-1; //PRICE_HIGH,PRICE_LOW,PRICE_OPEN
extern int Period1=PERIOD_H4;
//////////////////////////////////////////////
*/
string ind_name1="MTF_NormalizedClose";
string ind_name2="MTF_NormalizedVol";

string x1=DoubleToStr(TimeDay(iTime(Symbol(),0,i)),0);
string x2=DoubleToStr(TimeDayOfWeek(iTime(Symbol(),0,i)), 0);
string x3=DoubleToStr(TimeHour(iTime(Symbol(),0,i)),0);

string x4=iCustom(Symbol(),0,ind_name1,"XAU",8,nb1,0,PRIC E_CLOSE,PERIOD_M30,0,i);
string x5=iCustom(Symbol(),0,ind_name1,"YM",8,nb1,0,PRICE _CLOSE,PERIOD_M30,0,i);
string x6=iCustom(Symbol(),0,ind_name1,"ZB",8,nb1,0,PRICE _CLOSE,PERIOD_M30,0,i);
string x7=iCustom(Symbol(),0,ind_name1,"CL",8,nb1,0,PRICE _CLOSE,PERIOD_M30,0,i);
string x8=iCustom(Symbol(),0,ind_name1,"FGBL",8,nb1,0,PRI CE_CLOSE,PERIOD_M30,0,i);
string x9=iCustom(Symbol(),0,ind_name1,"FDAX",8,nb1,0,PRI CE_CLOSE,PERIOD_M30,0,i);

string y4=iCustom(Symbol(),0,ind_name2,"XAU",8,nb1,0,-1,PERIOD_M30,0,i);
string y5=iCustom(Symbol(),0,ind_name2,"YM",8,nb1,0,-1,PERIOD_M30,0,i);
string y6=iCustom(Symbol(),0,ind_name2,"ZB",8,nb1,0,-1,PERIOD_M30,0,i);
string y7=iCustom(Symbol(),0,ind_name2,"CL",8,nb1,0,-1,PERIOD_M30,0,i);
string y8=iCustom(Symbol(),0,ind_name2,"FGBL",8,nb1,0,-1,PERIOD_M30,0,i);
string y9=iCustom(Symbol(),0,ind_name2,"FDAX",8,nb1,0,-1,PERIOD_M30,0,i);



string ssig0="";

if(train==true)
{
//train
double sig=(iClose(Symbol(),0,i)-iOpen(Symbol(),0,i));
int si=1;
if(sig<0)
si=-1;
//double pipsa=PipsAvg(Symbol(),0,40,i);
double pips=(iHigh(Symbol(),0,i)-iLow(Symbol(),0,i))/Point;
int cc=1;
if(Symb0=="ZB")
cc=1000;
else
cc=10;
ssig0=DoubleToStr(NormalizeDouble(si*pips/cc,3),3);
}
else
{
//test
ssig0=0;
}
//-1.500
//1:27
//2:3
//3:11

//4:0.02274480
//5:-0.11235955
//6:0.05681818
//7:0.06821705
//8:0.04262295

//9:0.02205376
//10:-0.08435852
//11:-0.05248092
//12:0.04663706
//13:-0.01601067

string ss0=StringConcatenate(ssig0,
" 1:"+x1,
" 2:"+x2,
" 3:"+x3,

" 4:"+x4,
" 5:"+x5,
" 6:"+x6,
" 7:"+x7,
" 8:"+x8,
" 9:"+x9,

" 10:"+y4,
" 11:"+y5,
" 12:"+y6,
" 13:"+y7,
" 14:"+y8,
" 15:"+y9

//" 14"+z4,
// " 15"+z5,
// " 16"+z6,
// " 17"+z7,
// " 18"+z8

//" 19:"+x19,
//" 20:"+x20,
//" 21:"+x21,
// " 16:"+x22,
// " 17:"+x23,
// " 18:"+x24,
// " 19:"+x25,
// " 20:"+x26,
// " 21:"+x27
);
return(ss0);


}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

int NrOrders(int Magic )
{
int total = OrdersTotal();
int nrLongs = 0;
int nrShorts = 0;
for(int cnt=0; cnt<total; cnt++) {
OrderSelect(cnt, SELECT_BY_POS);
if( OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic )
continue;
if (OrderType()==OP_BUY) nrLongs++;
if (OrderType()==OP_BUYSTOP) nrLongs++;
if (OrderType()==OP_SELL) nrShorts++;
if (OrderType()==OP_SELLSTOP) nrShorts++;
}
return(nrLongs+nrShorts);
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

int OrderType1(int Magic)
{
int result=0;
for (int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderType()==OP_BUYSTOP) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=2;
}
if ((OrderType()==OP_SELLSTOP) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=-2;
}
if ((OrderType()==OP_BUY) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=1;
}
if ((OrderType()==OP_SELL) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=-1;
}

}
return(result); // 0 means we have no trades
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

datetime OrderTime1(int Magic)
{
datetime result;
for (int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=OrderOpenTime();
}
}
return(result); // 0 means we have no trades
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

int OrderTicket1(int Magic)
{
int result;
for (int i=0;i<OrdersTotal();i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic))
{
result=OrderTicket();
}
}
return(result); // 0 means we have no trades
}


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

void Buy(int Magic,double Lots,double TakeProfit, double StopLoss, string comment )
{
RefreshRates();
double Ask1=NormalizeDouble(Ask+(DiffAsk*Point),Digits);
double SL =NormalizeDouble(Ask1-StopLoss*Point,Digits);
double TP =NormalizeDouble(Ask1+TakeProfit*Point,Digits);

//double Ask1=Ask+DiffAsk*Point;
//double SL=Ask1-StopLoss*Point;
//double TP=Ask1+TakeProfit*Point;

int ticket=OrdSend(Symbol(),OP_BUYSTOP,Lots,Ask1,3,SL, TP,comment,Magic,0,Green);
//(_symbol,_cmd,_volume,_price,_slippage,_stoploss,_ takeprofit,_comment="",_magic=0,_expiration=0,_arr ow_color=CLR_NONE)
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("BUY order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening BUY order : ",GetLastError());
Print("SL=",SL);
}


}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

void Sell(int Magic,double Lots,double TakeProfit, double StopLoss, string comment )
{
RefreshRates();
double Bid1=NormalizeDouble(Bid-(DiffBid*Point),Digits);
double SL=NormalizeDouble(Bid1+StopLoss*Point,Digits);
double TP=NormalizeDouble(Bid1-TakeProfit*Point,Digits);

//double SL=Bid1+StopLoss*Point;
//double TP=Bid1-TakeProfit*Point;

int ticket=OrdSend(Symbol(),OP_SELLSTOP,Lots,Bid1,3,SL ,TP,comment,Magic,0,Red);
//(_symbol,_cmd,_volume,_price,_slippage,_stoploss,_ takeprofit,_comment="",_magic=0,_expiration=0,_arr ow_color=CLR_NONE)
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES )) Print("SELL order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening SELL order : ",GetLastError());
Print("SL=",SL);
}


}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

void CloseBuy(int Magic)
{
for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))
{
if((OrderType()==OP_BUY))
OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
if((OrderType()==OP_BUYSTOP))
OrderDelete(OrderTicket(),Red);

}

}
}

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+

void CloseSell(int Magic)
{
for (int i = 0; i < OrdersTotal(); i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))
{
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
if(OrderType()==OP_SELLSTOP)
OrderDelete(OrderTicket(),Red);

}

}
}


int CalcMagic()
{
int ref0=Signal*10000;

int Reference =0;
if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") Reference = 101;
if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") Reference = 102;
if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") Reference = 103;
if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") Reference = 104;
if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") Reference = 105;
if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") Reference = 106;
if (Symbol() == "EURCADm" || Symbol() == "EURCAD") Reference = 107;
if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") Reference = 108;
if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") Reference = 109;
if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") Reference = 110;
if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") Reference = 111;
if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") Reference = 112;
if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") Reference = 113;
if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") Reference = 114;
if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") Reference = 115;
if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") Reference = 116;
if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") Reference = 117;
if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") Reference = 118;
if (Symbol() == "USDCADm" || Symbol() == "USDCAD") Reference = 119;
if (Symbol() == "USDZARm" || Symbol() == "USDZAR") Reference = 120;
if (Symbol() == "USDNOKm" || Symbol() == "USDNOK") Reference = 121;
if (Symbol() == "NZDCHFm" || Symbol() == "NZDCHF") Reference = 122;
if (Symbol() == "CADJPYm" || Symbol() == "CADJPY") Reference = 123;
if (Symbol() == "EURTRYm" || Symbol() == "EURTRY") Reference = 124;
if (Symbol() == "USDTRYm" || Symbol() == "USDTRY") Reference = 125;
if (Symbol() == "TRYJPYm" || Symbol() == "TRYJPY") Reference = 126;

Reference=Reference+ref0;

if (Reference == 0) Reference = 999999;

return(Reference);
}



int Write(string str)
{
//Write log file
string filename="GOLD_EA.log";
int handle;
handle = FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV,"/t");
FileSeek(handle, 0, SEEK_END);
FileWrite(handle," Time " + TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS) + ": " + str);
FileClose(handle);
Print(str);
}


int OrdSend(string _symbol, int _cmd, double _volume, double _price, int _slippage, double _stoploss, double _takeprofit, string _comment="", int _magic=0, datetime _expiration=0, color _arrow_color=CLR_NONE)
{
int NumberOfTries=10;
int RetryTime=2;
//Send order with retry capabilities and log
int _stoplevel=MarketInfo(_symbol,MODE_STOPLEVEL);
double _priceop=0;
int ticket,err,tries;
tries = 0;
switch (_cmd) {
case OP_BUY:
if (!IsTradeContextBusy() && IsTradeAllowed()) {
while (tries < NumberOfTries) {
RefreshRates();
ticket = OrderSend(_symbol,OP_BUY,_volume,Ask,_slippage,Nor malizeDouble(_stoploss,Digits),NormalizeDouble(_ta keprofit,Digits),_comment,_magic,_expiration,_arro w_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Buy @ "+Ask+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Buy @ "+Ask+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
}
err=ticket;
break;

case OP_SELL:
if (!IsTradeContextBusy() && IsTradeAllowed()) {
while (tries < NumberOfTries) {
RefreshRates();
ticket = OrderSend(_symbol,OP_SELL,_volume,Bid,_slippage,No rmalizeDouble(_stoploss,Digits),NormalizeDouble(_t akeprofit,Digits),_comment,_magic,_expiration,_arr ow_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Sell @ "+Bid+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Sell @ "+Bid+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
}
err=ticket;
break;

case OP_BUYSTOP:
while (tries < NumberOfTries) {
RefreshRates();
if ((_price-Ask)<_stoplevel*Point) _priceop=Ask+_stoplevel*Point; else _priceop=_price;
ticket = OrderSend(_symbol,OP_BUYSTOP,_volume,NormalizeDoub le(_priceop,Digits),_slippage,NormalizeDouble(_sto ploss,Digits),NormalizeDouble(_takeprofit,Digits), _comment,_magic,_expiration,_arrow_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Buy Stop @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Buy Stop@ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
err=ticket;
break;


case OP_SELLSTOP:
if (!IsTradeContextBusy() && IsTradeAllowed()) {
while (tries < NumberOfTries) {
RefreshRates();
if ((Bid-_price)<_stoplevel*Point) _priceop=Bid-_stoplevel*Point; else _priceop=_price;
ticket = OrderSend(_symbol,OP_SELLSTOP,_volume,NormalizeDou ble(_priceop,Digits),_slippage,NormalizeDouble(_st oploss,Digits),NormalizeDouble(_takeprofit,Digits) ,_comment,_magic,_expiration,_arrow_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Sell Stop @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Sell Stop @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
}
err=ticket;
break;


case OP_BUYLIMIT:
if (!IsTradeContextBusy() && IsTradeAllowed()) {
while (tries < NumberOfTries) {
RefreshRates();
if ((Ask-_price)<_stoplevel*Point) _priceop=Ask-_stoplevel*Point; else _priceop=_price;
ticket = OrderSend(_symbol,OP_BUYLIMIT,_volume,NormalizeDou ble(_priceop,Digits),_slippage,NormalizeDouble(_st oploss,Digits),NormalizeDouble(_takeprofit,Digits) ,_comment,_magic,_expiration,_arrow_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Buy Limit @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Buy Limit @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
}
err=ticket;
break;

case OP_SELLLIMIT:
if (!IsTradeContextBusy() && IsTradeAllowed()) {
while (tries < NumberOfTries) {
RefreshRates();
if ((_price-Bid)<_stoplevel*Point) _priceop=Bid+_stoplevel*Point; else _priceop=_price;
ticket = OrderSend(_symbol,OP_BUYLIMIT,_volume,NormalizeDou ble(_priceop,Digits),_slippage,NormalizeDouble(_st oploss,Digits),NormalizeDouble(_takeprofit,Digits) ,_comment,_magic,_expiration,_arrow_color);
if(ticket<=0) {
Write("Error Occured : "+ErrorDescription(GetLastError()));
Write(Symbol()+" Sell Limit @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
tries++;
} else {
tries = NumberOfTries;
Write("Order opened : "+Symbol()+" Sell Limit @ "+_priceop+" SL @ "+_stoploss+" TP @"+_takeprofit+" ticket ="+ticket);
}
Sleep(RetryTime*1000);
}
err=ticket;
}
break;

default:
Write("No valid type of order found");
err=-1;
break;
}
return(err);
}


//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+

bool isNewBarM1()
{
static datetime BarTimeM1;
bool res=false;
if (BarTimeM1!=iTime(NULL,PERIOD_M1,0))
{
BarTimeM1=iTime(NULL,PERIOD_M1,0);
res=true;
}
return(res);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+

bool isNewBarM5()
{
static datetime BarTimeM5;
bool res=false;
if (BarTimeM5!=iTime(NULL,PERIOD_M5,0))
{
BarTimeM5=iTime(NULL,PERIOD_M5,0);
res=true;
}
return(res);
}


Attachments (11)

* 0_gold_1m.tpl - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
2k Download
* GOLDH_v01.mq4 - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
5k Download
* GOLDH_v02.mq4 - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
5k Download
* GOLDH_v03.mq4 - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
5k Download
* GOLD_EA_TRADE_lx_v19_1a.mq4 - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
33k Download
* GOLD_EA_TRADE_lx_v19_1b.mq4 - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
33k Download
* MTF_Normalize.mq4 - on Mar 12, 2010 9:22 PM by Barna Otvos (version 1)
5k Download
* MTF_NormalizedClose.mq4 - on Mar 12, 2010 9:22 PM by Barna Otvos (version 1)
4k Download
* b4_.rar - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
638k Download
* experts.rar - on Mar 12, 2010 9:21 PM by Barna Otvos (version 1)
17k Download
* indicators.rar - on Mar 12, 2010 9:22 PM by Barna Otvos (version 1)
7k Download

I found above codes from following website:

SVM EA - Better EA Clone

= = Unquote = =

Thanks a lot

James Phuc