Topics
Replies
renerpz
09 Sep 2014, 07:28
RE:
This is the Mt4 EA Robot i did convert to calgo on an automatic covert please help if some one know how to do it better way here it is
//+------------------------------------------------------------------+
//| 1258-rere-open by candle.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.dhabitafx.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.dhabitafx.com"
//extern int Password = 0;
extern int Magic = 1258;
extern int MinuteToCloseCandle = 8;
extern double Lots = 0.01;
extern int TP = 5;
extern int SL = 0;
extern int Max_Trade = 2;
extern int Trailing_Stop = 20;
int TS_Start = 0;
int timb = 0;
int tims = 0;
bool CAB =0,CAS=0;
extern string _ = "Time Trad";
extern string Start_ = "00:00";
extern string End_ = "23:59";
extern double Max_Spread = 3;
extern bool Send_Mail = 1;
bool time(){
string a=TimeToStr(iTime(Symbol(),PERIOD_D1,0),TIME_DATE)+" "+Start_;
string b=TimeToStr(iTime(Symbol(),PERIOD_D1,0),TIME_DATE)+" "+End_;
string c=TimeToStr(iTime(Symbol(),PERIOD_D1,1),TIME_DATE)+" "+Start_;
return(TimeCurrent()>=StrToTime(a)&&TimeCurrent()<StrToTime(b));
}
double pt,tua,histori;
int init()
{ if (Digits==5 ||Digits==3 || Symbol()=="GOLD" || Symbol()=="GOLD." || Symbol()=="GOLDm") {pt=10*Point;
} else
{pt=Point; }
string aku=" "+WindowExpertName()+" & Waiting New Tik";
string ins=" INSTALING";
int d =1;
int d1=1;
double bid=Bid;
if(!IsExpertEnabled()&&!IsTesting())return;
for(int x=0;x<10000;x++){
if(!IsExpertEnabled())break;
RefreshRates();
d1++;
if(d1>10)d1=11;
if(d1>10){d++;}
if(d>StringLen(aku)){d=0;}
string a=StringSubstr(aku,0,d);
string a1=StringSubstr(ins,0,d1);
Comment(a1," " ,a );
Sleep(100);
if(bid!=Bid)break;
}
Comment("SUCSES");
PlaySound("Connect.wav");
start();
if(Send_Mail)SendMail("EA AKTIF "+DoubleToStr(AccountNumber(),0)+" "+AccountCompany() +" "+OrderSymbol(),"");
//----
return(0);
}
bool CUTLOS = 0;
int LC=0;
int start(){
if(IsTesting())Send_Mail=0;
if(TimeCurrent()>Time[0]+Period()*60-(MinuteToCloseCandle+2)*60&&!IsTesting()){
for(int x=0;x<MinuteToCloseCandle*70;x++){
start1();
Sleep(500);
if(!IsExpertEnabled())break;
}}
start1();
}
int start1()
{
RefreshRates();
//if(Password!=AccountNumber()*3-1258&&!IsTesting()){Comment("Salah Pasword");return;}
int M = Magic;
int T= 0;
string C="";
int LL = 2;
////////////////////////////////////////////////////////////////////////////////////////////
T= 0; M=Magic+1234; ts(M);
bool SBUY = 0;
bool SSELL = 0;
if(Period()*60<MinuteToCloseCandle*60){Alert("TIME FRAME MUST < MinuteToCloseCandle");return;}
if(TimeCurrent()>Time[0]+Period()*60-MinuteToCloseCandle*60){
if(Bid>Open[0])SSELL=1;
if(Bid<Open[0])SBUY=1;
}
double Lotsb = Lots;
double Lotss = Lots;
h(0,M,0);
if(g("b",M)+g("S",M)>5&&histori>g("pfb",M)+g("pfs",M)){CAB=1;CAS=1;}
if(g("b",M)<1)CAB=0;
if(g("s",M)<1)CAS=0;
if(CAB){close(0,M);return;} if(CAS){close(1,M);return;}
if(time()&&MarketInfo(Symbol(),MODE_SPREAD)/(pt/Point)<=Max_Spread){
if( SBUY &&timb!=Time[1]&&g("b",M)<Max_Trade&&g("bt",M)+h(0,M,0)<1){T= OrderSend(Symbol() ,0,MM(Lotsb),Ask,3,0,0,C,M,0,Blue);if(T>0)timb=Time[1];}
if( SSELL&&timb!=Time[1]&&g("s",M)<Max_Trade&&g("st",M)+h(1,M,0)<1){T= OrderSend(Symbol() ,1,MM(Lotss),Bid,3,0,0,C,M,0,Red); if(T>0)timb=Time[1];}
}
if(CAB){close(0,M);return;} if(CAS){close(1,M);return;}
tp(0,TP,M);
tp(1,TP,M);
sl(0,SL,M);
sl(1,SL,M);
LAB (LL, " PROFIT ", DoubleToStr(g("pfb",M)+g("pfs",M),2));LL++;
LAB (LL, " TOTAL OP ", " BUY "+DoubleToStr(g("b",M),0)+" SELL "+DoubleToStr(g("s",M),0)+" MAX "+DoubleToStr(Max_Trade,0));LL++;LL++;
LAB (LL, " Time OP ", TimeToStr(Time[0]+Period()*60-MinuteToCloseCandle*60,TIME_DATE|TIME_MINUTES|TIME_SECONDS));LL++;
LAB (LL, " Time CR ", TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS));LL++;
Comment(histori);
return(0);
}
//+------------------------------------------------------------------+
double MM(double x){
if(x<MarketInfo(Symbol(),MODE_MINLOT))return(MarketInfo(Symbol(),MODE_MINLOT));
if(x>MarketInfo(Symbol(),MODE_MAXLOT))return(MarketInfo(Symbol(),MODE_MAXLOT));
return(NormalizeDouble(x,2));
}
//KALKULATOR
double g(string c,int m){
double tb=0,ts=0,tul=0,pb=0,ps=0,lb=0,ls=0,tpb=0,tps=0,tlb=0,tls=0,ss=0,pfb=0,pfs=0,bs=0,bl=0,sl=0,lt=0,tip=4,lp=0,ll=0;
double pbr=99999,pst=0;
double tikb=0;double tiks=0;
double totalan=0,bt=0;
tua=999999999999;
for (int cnt = 0; cnt < OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if ((OrderSymbol() == Symbol()||c=="all") &&OrderMagicNumber()==m)
{ tua=MathMin(tua,OrderOpenTime());
if (OrderType() == OP_BUY)
{ tikb=OrderTicket();pbr=MathMin(pbr,OrderOpenPrice());if(OrderOpenTime()>=Time[0])bt++;
//if(Bid-OrderOpenPrice()>(TS+TS_Start)*pt)TSB=1;
tb++;pb=OrderOpenPrice();lb=OrderLots();tpb=OrderTakeProfit();tlb+=OrderLots();pfb+=OrderProfit();lt=OrderLots();tip=0;lp=OrderOpenPrice();ll=OrderLots();
}
if (OrderType() == OP_SELL)
{ tiks=OrderTicket();pst=MathMax(pst,OrderOpenPrice());if(OrderOpenTime()>=Time[0])bt++;
// if(OrderOpenPrice()-Ask>(TS+TS_Start)*pt)TSS=1;
ts++;ps=OrderOpenPrice();ls=OrderLots();tps=OrderTakeProfit();tls+=OrderLots();pfs+=OrderProfit();lt=OrderLots();tip=1;lp=OrderOpenPrice();ll=OrderLots();
}
if(OrderType()==OP_SELLSTOP){ss++;tps=OrderTakeProfit();}
if(OrderType()==OP_BUYSTOP) {bs++;tpb=OrderTakeProfit();}
if(OrderType()==OP_SELLLIMIT)sl++;
if(OrderType()==OP_BUYLIMIT )bl++;
}
}
if(c=="bt")tul=bt;
if(c=="all")tul=tb+ts;
if(c=="b")tul=tb;
if(c=="s")tul=ts;
if(c=="pbr")tul=pbr;
if(c=="pst")tul=pst;
if(c=="pb")tul=pb;
if(c=="ps")tul=ps;
if(c=="ls")tul=ls;
if(c=="lb")tul=lb;
if(c=="tps")tul=tps;
if(c=="tpb")tul=tpb;
if(c=="tls")tul=tls;
if(c=="tlb")tul=tlb;
if(c=="pfs")tul=pfs;
if(c=="pfb")tul=pfb;
if(c=="tikb")tul=tikb;
if(c=="tiks")tul=tiks;
if(c=="lt")tul=lt;
if(c=="ss")tul=ss;
if(c=="bs")tul=bs;
if(c=="sl")tul=sl;
if(c=="bl")tul=bl;
if(c=="lp")tul=lp;
if(c=="tip")tul=tip;
if(c=="ll")tul=ll;
return(tul);
}
double h(int a,int m,int t)
{
double ll=0,p=0;
double pf=0;
double lp=0;
double los=0;
double ter=0;
string tik="";
string prof="";
histori=0;
for (int cnt = OrdersHistoryTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == m )
{if(ter>OrderCloseTime()){ter=OrderCloseTime();tik=DoubleToStr(OrderTicket(),0)+" ";prof=DoubleToStr(OrderProfit(),2);}
if(OrderOpenTime()>=Time[0]&&OrderType()==a)ll++;
if(OrderOpenTime()>=tua)histori+=OrderProfit();
}
}
if(LC<ter){if(LC>0&&Send_Mail)SendMail("ORDER CLOSE "+DoubleToStr(AccountNumber(),0)+" "+AccountCompany(),tik+" "+OrderSymbol()+" "+prof);LC=ter;}
return(ll);
}
//TAKE PROFIT
void tp(int x,int TP,int m){
double spr=MarketInfo(Symbol(),MODE_SPREAD);
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == m )
{ if((OrderType()==0||OrderType()==4 )&&OrderTakeProfit()==0&&TP>0&&x==0 ) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), OrderOpenPrice()+TP*pt ,0,Yellow);}
if((OrderType()==1||OrderType()==5 )&&OrderTakeProfit()==0&&TP>0&&x==1 ) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(), OrderOpenPrice()-TP*pt ,0,Yellow);}
}
}
}
//STOP LOSS
void sl(int x,int SL,int m){
double stl=MarketInfo(Symbol(),MODE_STOPLEVEL)/(pt/Point);
if(SL<stl&&SL>0)SL=stl;
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() &&( OrderMagicNumber() == m ) )
{
if((OrderType()==0||OrderType()==2||OrderType()==4)&&OrderStopLoss()==0&&SL>0&&x==0) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-SL*pt,OrderTakeProfit(),0,Yellow); if(GetLastError()==130) OrderModify(OrderTicket(),OrderOpenPrice(),Bid-stl*pt,OrderTakeProfit(),0,Yellow);}
if((OrderType()==1||OrderType()==3||OrderType()==5)&&OrderStopLoss()==0&&SL>0&&x==1) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+SL*pt,OrderTakeProfit(),0,Yellow); if(GetLastError()==130) OrderModify(OrderTicket(),OrderOpenPrice(),Ask+stl*pt,OrderTakeProfit(),0,Yellow);}
}
}
}
void close(int x,int m)
{
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == m )
{
if(OrderType()==0&&x==0) OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
if(OrderType()==1&&x==1) OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
}
}
}
void LAB (int baris, string label2, string label1)
{
int x,y;y=15;
for(int t=0;t<100;t++){
if(baris==t){y=t*y;break;}
}
x=10;y=y+50;
LC("dhabitafx"+baris, label1, 8, x, y , Gold,1);
LC("dhabitafx-"+baris, label2, 8, x+130, y, Gold,1);
LC("dhabitafx_"+baris, ":", 8, x+120, y, Gold,1);
LC("eq", DoubleToStr(AccountEquity(),2), 20, 20, 40, Magenta,1);
}
void LC(string nama, string isi, int ukuran, int x, int y, color warna, int pojok)
{
if (ObjectFind(nama)<0) {ObjectCreate (nama,OBJ_LABEL,0,0,0,0,0);}
ObjectSet(nama,OBJPROP_CORNER,pojok);
ObjectSet(nama,OBJPROP_XDISTANCE,x);
ObjectSet(nama,OBJPROP_YDISTANCE,y);
ObjectSetText (nama,isi,ukuran,"Arial",warna);
}
void ts(int m){
int TS=Trailing_Stop;
for (int cnt = OrdersTotal()-1 ; cnt >= 0; cnt--)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol() == Symbol() && (OrderMagicNumber() == m) )
{
if((OrderType()==0 )&&TS>0&&OrderStopLoss() <=Bid-(TS+1)*pt &&OrderOpenPrice()+(TS_Start+TS)*pt <=Bid ) OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TS*pt,OrderTakeProfit(),0,Yellow);
if((OrderType()==1 )&&TS>0&&(OrderStopLoss()>=Ask+(TS+1)*pt||OrderStopLoss()==0) &&OrderOpenPrice()-(TS_Start+TS)*pt >=Ask ) OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TS*pt,OrderTakeProfit(),0,Yellow);
}
}
}
@renerpz
renerpz
18 Sep 2014, 23:06
RE: Please help!
hello friend can you send me the code already modify i ve been having problems with the errors ill appreciate the help
@renerpz