网址:http://www.forexmt4.com/mt_yahoo/swb_GRID%203.mq4
逆向加单型EA. 不建议实盘,赚再多,一次爆完
#property copyright "Copyright ? 2009, Totom Sukopratomo"
#property link "forexengine@gmail.com"
#define Magic 1234
#define buy -15
#define sell 15
extern double StartLot=0.1;
extern int Range=20;
extern int Level=15;
extern double TPInMoney=10.0; //in money
extern int StartHour=0;
extern int EndHour=24;
extern bool TradeInMonday=true;
extern double MoneyTargetInMonday=100;
extern double CutLossInMonday=0;
extern bool TradeInTuesday=true;
extern double MoneyTargetInTuesday=100;
extern double CutLossInTuesday=0;
extern bool TradeInWednesday=true;
extern double MoneyTargetInWednesday=100;
extern double CutLossInWednesday=0;
extern bool TradeInThursday=true;
extern double MoneyTargetInThursday=100;
extern double CutLossInThursday=0;
extern bool TradeInFriday=true;
extern double MoneyTargetInFriday=100;
extern double CutLossInFriday=0;
extern bool UseMultiplier=true;
extern string note="true,maka besar nextlot dikali multiplier";
extern double Multiplier=2.0;
extern bool UseIncreament=false;
extern string note1="true,maka besar nextlot ditambah increament";
extern double Increament=1.0;
extern int MySWBStyle=2;
extern string note2="0=swb GRID, 1=swb GRID 2, 2=swb GRID 3";
extern int MyTradeStyle=1;
extern string note3="0=Follow Trend, 1=CounterTrend";
extern string TradeStyle_0="Follow Trend";
extern int FastMAPeriod=5;
extern int SlowMAPeriod=20;
extern string TradeStyle_1="Counter Trend";
extern bool UseBB=true;
extern int BBPeriod=20;
extern int BBDeviation=2;
extern bool UseStoch=true;
extern int StochKPeriod=5;
extern int StochDPeriod=3;
extern int StochSlowing=3;
extern int UseRSI=true;
extern int RSIPeriod=9;
extern int HighLevel=70;
extern int LowLevel=30;
int total,histotal,i,jumlah,prec,type,ticket,ordercounter=0;
double pt,minlot,maxlot,stoplevel,lot,openprice,profit,profitX,profitY;
int totalorder()
{
total=OrdersTotal(); jumlah=0;
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
jumlah++;
}
return(jumlah);
}
int sendorder(int cmd,double lot,double prc,color warna)
{
return(OrderSend(Symbol(),cmd,lot,prc,3,0,0,"",Magic,0,warna));
}
int closeorder()
{
total=OrdersTotal();
for(i=total-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
switch(OrderType())
{
case 0:
{
OrderClose(OrderTicket(),OrderLots(),Bid,1,CLR_NONE);
break;
}
case 1:
{
OrderClose(OrderTicket(),OrderLots(),Ask,1,CLR_NONE);
break;
}
case 2:
{
OrderDelete(OrderTicket());
break;
}
case 3:
{
OrderDelete(OrderTicket());
break;
}
}
}
return(0);
}
double lastlot()
{
total=OrdersTotal(); lot=0;
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
lot=OrderLots();
}
return(lot);
}
double profit()
{
total=OrdersTotal();
profit=0;
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
profit+=OrderProfit();
}
return(profit);
}
double profitoftheday(int curday)
{
histotal=OrdersHistoryTotal();
for(i=0; i<histotal; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if(TimeDayOfWeek(OrderOpenTime())!=curday) continue;
if(TimeDay(OrderOpenTime())!=TimeDay(TimeCurrent())) continue;
if(TimeMonth(OrderOpenTime())!=TimeMonth(TimeCurrent())) continue;
if(TimeYear(OrderOpenTime())!=TimeYear(TimeCurrent())) continue;
profit+=OrderProfit();
}
return(profit);
}
int signal()
{
if(MyTradeStyle==0)
{
double fastma0=iMA(Symbol(),0,FastMAPeriod,0,0,0,0);
double fastma1=iMA(Symbol(),0,FastMAPeriod,0,0,0,1);
double slowma1=iMA(Symbol(),0,SlowMAPeriod,0,0,0,1);
if(fastma0>fastma1 && fastma1>slowma1) return(buy);
if(fastma0<fastma1 && fastma1<slowma1) return(sell);
return(0);
}
if(MyTradeStyle==1)
{
double upperbb=iBands(Symbol(),0,BBPeriod,BBDeviation,0,0,MODE_UPPER,0);
double lowerbb=iBands(Symbol(),0,BBPeriod,BBDeviation,0,0,MODE_LOWER,0);
double stoch=iStochastic(Symbol(),0,StochKPeriod,StochDPeriod,StochSlowing,0,0,MODE_SIGNAL,0);
double rsi=iRSI(Symbol(),0,RSIPeriod,0,0);
if(UseBB && !UseStoch && !UseRSI)
{
if(Close[0]>upperbb) return(sell);
if(Close[0]<lowerbb) return(buy);
return(0);
}
if(!UseBB && UseStoch && !UseRSI)
{
if(stoch>HighLevel) return(sell);
if(stoch<LowLevel) return(buy);
return(0);
}
if(!UseBB && !UseStoch && UseRSI)
{
if(rsi>HighLevel) return(sell);
if(rsi<LowLevel) return(buy);
return(0);
}
if(UseBB && UseStoch && !UseRSI)
{
if(Close[0]>upperbb && stoch>HighLevel) return(sell);
if(Close[0]<lowerbb && stoch<LowLevel) return(buy);
return(0);
}
if(UseBB && !UseStoch && UseRSI)
{
if(Close[0]>upperbb && rsi>HighLevel) return(sell);
if(Close[0]<lowerbb && rsi<LowLevel) return(buy);
return(0);
}
if(!UseBB && UseStoch && UseRSI)
{
if(stoch>HighLevel && rsi>HighLevel) return(sell);
if(stoch<LowLevel && rsi<LowLevel) return(buy);
return(0);
}
if(UseBB && UseStoch && UseRSI)
{
if(Close[0]>upperbb && stoch>HighLevel && rsi>HighLevel) return(sell);
if(Close[0]<lowerbb && stoch<LowLevel && rsi<LowLevel) return(buy);
return(0);
}
}
}
int manageorder0()
{
if(profit()>=TPInMoney)
{
closeorder();
}
if(totalorder()==0 && lastlot()==0)
{
if(signal()==buy)
{
if(sendorder(0,StartLot,Ask,Blue)>0) return(0);
}
if(signal()==sell)
{
if(sendorder(1,StartLot,Bid,Red)>0) return(0);
}
}
if(totalorder()>0 && totalorder()<Level)
{
type=-1; openprice=0; total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
type=OrderType();
openprice=OrderOpenPrice();
}
if(type==0)
{
if(Ask>openprice-Range*pt) return(0);
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,totalorder()),prec)>maxlot) return(0);
if(sendorder(0,NormalizeDouble(StartLot*MathPow(Multiplier,totalorder()),prec),Ask,Blue)>0) return(0);
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(lastlot()+Increament),prec)>maxlot) return(0);
ticket=sendorder(0,NormalizeDouble(lastlot()+Increament,prec),Ask,Blue);
}
}
if(type==1)
{
if(Bid<openprice+Range*pt) return(0);
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,totalorder()),prec)>maxlot) return(0);
if(sendorder(1,NormalizeDouble(StartLot*MathPow(Multiplier,totalorder()),prec),Bid,Red)>0) return(0);
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(lastlot()+Increament),prec)>maxlot) return(0);
if(sendorder(1,NormalizeDouble(StartLot+(Increament*i),prec),Bid,Blue)>0) return(0);
}
}
}
return(0);
}
int manageorder1()
{
if(totalorder()==0) ordercounter=0;
histotal=OrdersHistoryTotal();
total=OrdersTotal();
profit=0;
for(i=histotal-ordercounter; i<histotal; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
profit+=OrderProfit();
}
profitY=0;
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
profitY+=OrderProfit();
}
profitX=profit+profitY;
if(profitX>=TPInMoney)
{
closeorder();
}
if(totalorder()==0 && lastlot()==0 && ordercounter==0)
{
if(signal()==buy)
{
ticket=sendorder(0,StartLot,Ask,Blue);
if(ticket>0) { ordercounter++; return(0);}
}
if(signal()==sell)
{
ticket=sendorder(1,StartLot,Bid,Red);
if(ticket>0) { ordercounter++; return(0);}
}
}
if(totalorder()>0 && totalorder()<Level)
{
type=-1; openprice=0; total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
type=OrderType();
openprice=OrderOpenPrice();
}
if(type==0)
{
if(Ask>openprice-Range*pt) return(0);
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,ordercounter),prec)>maxlot) return(0);
ticket=sendorder(0,NormalizeDouble(StartLot*MathPow(Multiplier,ordercounter),prec),Ask,Blue);
if(ticket>0)
{
ordercounter++;
total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if(OrderTicket()!=ticket)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
}
}
}
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(lastlot()+Increament),prec)>maxlot) return(0);
ticket=sendorder(0,NormalizeDouble(lastlot()+Increament,prec),Ask,Blue);
if(ticket>0)
{
ordercounter++;
total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if(OrderTicket()!=ticket)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,CLR_NONE);
}
}
}
}
}
if(type==1)
{
if(Bid<openprice+Range*pt) return(0);
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,ordercounter),prec)>maxlot) return(0);
ticket=sendorder(1,NormalizeDouble(StartLot*MathPow(Multiplier,ordercounter),prec),Bid,Red);
if(ticket>0)
{
ordercounter++;
total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if(OrderTicket()!=ticket)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(lastlot()+Increament),prec)>maxlot) return(0);
ticket=sendorder(1,NormalizeDouble(StartLot+(Increament*ordercounter),prec),Bid,Blue);
if(ticket>0)
{
ordercounter++;
total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
if(OrderTicket()!=ticket)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,CLR_NONE);
}
}
}
}
}
}
return(0);
}
int manageorder2()
{
if(profit()>=TPInMoney)
{
closeorder();
}
if(totalorder()==0 && lastlot()==0)
{
if(signal()==buy)
{
if(sendorder(0,StartLot,Ask,Blue)>0) return(0);
}
if(signal()==sell)
{
if(sendorder(1,StartLot,Bid,Red)>0) return(0);
}
}
if(totalorder()==1 && lastlot()==StartLot)
{
type=-1; openprice=0; total=OrdersTotal();
for(i=0; i<total; i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
type=OrderType();
openprice=OrderOpenPrice();
}
if(type==0)
{
for(i=1; i<=Level; i++)
{
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,i),prec)>maxlot) return(0);
sendorder(2,NormalizeDouble(StartLot*MathPow(Multiplier,i),prec),Ask-((Range*i)*pt),Blue);
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(Increament*i),prec)>maxlot) return(0);
sendorder(2,NormalizeDouble(StartLot+(Increament*i),prec),Ask-((Range*i)*pt),Blue);
}
}
}
if(type==1)
{
for(i=1; i<=Level; i++)
{
if(UseMultiplier)
{
if(NormalizeDouble(StartLot*MathPow(Multiplier,i),prec)>maxlot) return(0);
sendorder(3,NormalizeDouble(StartLot*MathPow(Multiplier,i),prec),Bid+((Range*i)*pt),Red);
}
if(UseIncreament)
{
if(NormalizeDouble(StartLot+(Increament*i),prec)>maxlot) return(0);
sendorder(3,NormalizeDouble(StartLot+(Increament*i),prec),Bid+((Range*i)*pt),Blue);
}
}
}
}
return(0);
}
int init()
{
if(Digits==3 || Digits==5) pt=10*Point;
else pt=Point;
minlot=MarketInfo(Symbol(),MODE_MINLOT);
if(minlot==0.01) prec=2;
else
if(minlot==0.1) prec=1;
else prec=0;
if(StartLot<=minlot) StartLot=minlot;
stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(Range<=stoplevel) Range=stoplevel;
maxlot=MarketInfo(Symbol(),MODE_MAXLOT);
return(0);
}
int deinit()
{
Comment("");
return(0);
}
int start()
{
if((TimeHour(TimeCurrent())<StartHour || TimeHour(TimeCurrent())>=EndHour) && totalorder()==0)
{
Comment("\nBELUM JAMNYA TRADING........");
return(0);
}
if(DayOfWeek()==1 && !TradeInMonday)
{
Comment("\nTIDAK TRADING DI HARI SENIN.....");
return(0);
}
if(DayOfWeek()==2 && !TradeInTuesday && totalorder()==0)
{
Comment("\nTIDAK TRADING DI HARI SELASA....");
return(0);
}
if(DayOfWeek()==3 && !TradeInWednesday && totalorder()==0)
{
Comment("\nTIDAK TRADING DI HARI RABU....");
return(0);
}
if(DayOfWeek()==4 && !TradeInThursday && totalorder()==0)
{
Comment("\nTIDAK TRADING DI HARI KAMIS....");
return(0);
}
if(DayOfWeek()==5 && !TradeInFriday && totalorder()==0)
{
Comment("\nTIDAK TRADING DI HARI JUMAT.....");
return(0);
}
if(DayOfWeek()==1)
{
if(profitoftheday(1)>=MoneyTargetInMonday && totalorder()==0)
{
Comment("\nTARGET HARI INI TERCAPAI");
return(0);
}
if(AccountEquity()<=CutLossInMonday)
{
Comment("\nHARI INI CUTLOSS");
closeorder();
return(0);
}
}
if(DayOfWeek()==2)
{
if(profitoftheday(2)>=MoneyTargetInTuesday && totalorder()==0)
{
Comment("\nTARGET HARI INI TERCAPAI");
return(0);
}
if(AccountEquity()<=CutLossInTuesday)
{
Comment("\nHARI INI CUTLOSS");
closeorder();
return(0);
}
}
if(DayOfWeek()==3)
{
if(profitoftheday(3)>=MoneyTargetInWednesday && totalorder()==0)
{
Comment("\nTARGET HARI INI TERCAPAI");
return(0);
}
if(AccountEquity()<=CutLossInWednesday)
{
Comment("\nHARI INI CUTLOSS");
closeorder();
return(0);
}
}
if(DayOfWeek()==4)
{
if(profitoftheday(4)>=MoneyTargetInThursday && totalorder()==0)
{
Comment("\nTARGET HARI INI TERCAPAI");
return(0);
}
if(AccountEquity()<=CutLossInThursday)
{
Comment("\nHARI INI CUTLOSS");
closeorder();
return(0);
}
}
if(DayOfWeek()==5)
{
if(profitoftheday(5)>=MoneyTargetInFriday && totalorder()==0)
{
Comment("\nTARGET HARI INI TERCAPAI");
return(0);
}
if(AccountEquity()<=CutLossInFriday)
{
Comment("\nHARI INI CUTLOSS");
closeorder();
return(0);
}
}
Comment("");
switch(MySWBStyle)
{
case 0: { manageorder0(); break;}
case 1: { manageorder1(); break;}
case 2: { manageorder2(); break;}
}
return(0);
}
|