http://jumforex.blogspot.com/2013/01/belajar-membuat-ea-sederhana-23-average.html
//+------------------------------------------------------------------+
//| Jum+AvZigzag+.mq4 |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+AvZigzag+";
extern string Target_Equety_ = "Harus lebih besar dari Equety+";
extern double Target_Equety = 1000;
extern bool Trade_buy = true;
extern bool Trade_sell = true;
extern int Mulai_Jam = 6;
extern int Akhir_Jam = 20;
extern bool Tp_in_Money = true;
extern double TP_in_money = 10;
extern int TP = 100;
extern int SL = 0;
extern double Lots = 0.1;
extern int Jarak_order = 35;
extern int Max_order = 10;
extern double DiMarti = 1;
extern bool TrailingStop_ = false;
extern int TrailingStop = 20;
extern int Magic = 69;
extern string Seting_ZigzAG = "Sesuka Hati";
extern int ExtDepth = 33;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern string Seting_Ma = "Sesuka Hati";
extern int Pereode = 33;
double slb,tpb,sls,tps,pt,bal;
int wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
bal= AccountBalance();
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("j");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("j",OBJ_LABEL,0,0,0);
ObjectSet("j",OBJPROP_CORNER,4);
ObjectSet("j",OBJPROP_XDISTANCE,10);
ObjectSet("j",OBJPROP_YDISTANCE,10);
ObjectSetText("j","Jum+ZigZag+ from : JumForex.blogspot.com ,Donasi LR U7360459",19,"Mistral",Aqua);
//----
if(Target_Equety<AccountEquity()) {
closeall(0);
closeall(1);
Alert("Cek Target_Equetynya salah ");
return(0);
}
label();
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<= money()){
closeall(0);
closeall(1);
}
//----
double ma = iMA(Symbol(), 0, Pereode , 0, MODE_LWMA, PRICE_CLOSE, 0 ) ;
for(int d=0; d< Bars ; d++){
double up=iCustom(Symbol(),0,"ZigZag", ExtDepth , ExtDeviation, ExtBackstep, MODE_UPPER, d);
double lo=iCustom(Symbol(),0,"ZigZag", ExtDepth , ExtDeviation, ExtBackstep, MODE_LOWER,d);
if(up!=0 || lo!=0) break;}
int sigz, sigc,signal;
if(up>0 ) sigz= 1;
if(lo>0) sigz= 5;
double OP=iOpen(Symbol(),PERIOD_W1,0);
if(Ask>OP) sigc=1;
if(Bid<OP) sigc=5;
if(sigz+sigc==2) signal=1;
if(sigz+sigc==10)signal=2;
if(Jam_trade()==1){
if(SL==0)slb=0;else slb=Ask-SL*pt;
if(SL==0)sls=0;else sls=Bid+SL*pt;
if(TP==0)tpb=0;else tpb=Ask+TP*pt;
if(TP==0)tps=0;else tps=Bid-TP*pt;
if(jumlahorder(0)==0 && jumlahorder(1)==0 && Trade_buy && signal==2) {OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);}
if(jumlahorder(0)==0 && jumlahorder(1)==0 && Trade_sell && signal==1) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);}
}
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)< Max_order && Trade_buy && signal==2) {OrderSend(Symbol(),OP_BUY,xlot(0),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue); wt=Time[0]; }
if(trad()==2 && wk!=Time[0] && jumlahorder(0)==0 && jumlahorder(1)<Max_order && Trade_sell && signal==1) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
if(money()>0){
if(Bid>ma) closeall(0);
if(Ask<ma) closeall(1);
}
return(0);
}
//+------------------------------------------------------------------+
int Jam_trade()
{
bool trade = false;
if(Mulai_Jam > Akhir_Jam){
if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
} else
if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;
return (trade);
}
int jumlahorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void dtrailing()
{
for(int i=0; i<OrdersTotal(); i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic ) continue;
if(OrderType()==OP_BUY) {
if(Bid-OrderOpenPrice()>pt*TrailingStop) {
if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
if(OrderType()==OP_SELL) {
if((OrderOpenPrice()-Ask)>(pt*TrailingStop)){
if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)){
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
void closeall(int m)
{
for (int i = OrdersTotal() - 1; i >= 0; i--) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic || m!= OrderType()) continue;
if (OrderType() > 1) OrderDelete(OrderTicket());
else {
if (OrderType() == 0) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
else OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
}
}
}
double money()
{
double dp = 0;
int i;
for (i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic) continue;
dp += OrderProfit();
}
return(dp);
}
int trad()
{
int type,dp; double opb,ops,lastlotb,lastlots;
for (int i = 0; i < OrdersTotal(); i++) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
type=OrderType();
if(type==0)opb = OrderOpenPrice();
if(type==1)ops = OrderOpenPrice();
}
double as = opb - Jarak_order * pt;
double bi = ops + Jarak_order * pt;
if ( Ask <= as && jumlahorder(0)> 0 ) dp=1;
if ( Bid >= bi && jumlahorder(1)> 0 ) dp=2;
return(dp);
}
double xlot(int m)
{
double ylot,dlot;
for (int i = 0; i < OrdersTotal(); i++) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic ||OrderType()!=m) continue;
dlot=OrderLots();
}
if(OrderType()==m)ylot=NR(Lots*MathPow(DiMarti,jumlahorder(m)));
return(ylot);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: =>+Jum+AvZigzag+<=",
"\n :: =>JumForex.blogspot.com<=",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Jam Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------",
"\n :: Equity sekarang : ", AccountEquity()," $",
"\n :: Target_Equety : ", Target_Equety ," $",
"\n ------------------------------------------------",
"\n :: Posisi floting :",money()," $",
"\n :: Jumlah level :",jumlahorder(0)+jumlahorder(1),
"\n ------------------------------------------------",
"\n :: >>By: Jum69<<",
"\n ------------------------------------------------");
//+------------------------------------------------------------------+
}
//+------------------------------------------------------------------+
//| Jum+AvZigzag+.mq4 |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+AvZigzag+";
extern string Target_Equety_ = "Harus lebih besar dari Equety+";
extern double Target_Equety = 1000;
extern bool Trade_buy = true;
extern bool Trade_sell = true;
extern int Mulai_Jam = 6;
extern int Akhir_Jam = 20;
extern bool Tp_in_Money = true;
extern double TP_in_money = 10;
extern int TP = 100;
extern int SL = 0;
extern double Lots = 0.1;
extern int Jarak_order = 35;
extern int Max_order = 10;
extern double DiMarti = 1;
extern bool TrailingStop_ = false;
extern int TrailingStop = 20;
extern int Magic = 69;
extern string Seting_ZigzAG = "Sesuka Hati";
extern int ExtDepth = 33;
extern int ExtDeviation = 5;
extern int ExtBackstep = 3;
extern string Seting_Ma = "Sesuka Hati";
extern int Pereode = 33;
double slb,tpb,sls,tps,pt,bal;
int wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
bal= AccountBalance();
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("j");
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
ObjectCreate("j",OBJ_LABEL,0,0,0);
ObjectSet("j",OBJPROP_CORNER,4);
ObjectSet("j",OBJPROP_XDISTANCE,10);
ObjectSet("j",OBJPROP_YDISTANCE,10);
ObjectSetText("j","Jum+ZigZag+ from : JumForex.blogspot.com ,Donasi LR U7360459",19,"Mistral",Aqua);
//----
if(Target_Equety<AccountEquity()) {
closeall(0);
closeall(1);
Alert("Cek Target_Equetynya salah ");
return(0);
}
label();
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<= money()){
closeall(0);
closeall(1);
}
//----
double ma = iMA(Symbol(), 0, Pereode , 0, MODE_LWMA, PRICE_CLOSE, 0 ) ;
for(int d=0; d< Bars ; d++){
double up=iCustom(Symbol(),0,"ZigZag", ExtDepth , ExtDeviation, ExtBackstep, MODE_UPPER, d);
double lo=iCustom(Symbol(),0,"ZigZag", ExtDepth , ExtDeviation, ExtBackstep, MODE_LOWER,d);
if(up!=0 || lo!=0) break;}
int sigz, sigc,signal;
if(up>0 ) sigz= 1;
if(lo>0) sigz= 5;
double OP=iOpen(Symbol(),PERIOD_W1,0);
if(Ask>OP) sigc=1;
if(Bid<OP) sigc=5;
if(sigz+sigc==2) signal=1;
if(sigz+sigc==10)signal=2;
if(Jam_trade()==1){
if(SL==0)slb=0;else slb=Ask-SL*pt;
if(SL==0)sls=0;else sls=Bid+SL*pt;
if(TP==0)tpb=0;else tpb=Ask+TP*pt;
if(TP==0)tps=0;else tps=Bid-TP*pt;
if(jumlahorder(0)==0 && jumlahorder(1)==0 && Trade_buy && signal==2) {OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);}
if(jumlahorder(0)==0 && jumlahorder(1)==0 && Trade_sell && signal==1) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);}
}
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)< Max_order && Trade_buy && signal==2) {OrderSend(Symbol(),OP_BUY,xlot(0),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue); wt=Time[0]; }
if(trad()==2 && wk!=Time[0] && jumlahorder(0)==0 && jumlahorder(1)<Max_order && Trade_sell && signal==1) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
if(money()>0){
if(Bid>ma) closeall(0);
if(Ask<ma) closeall(1);
}
return(0);
}
//+------------------------------------------------------------------+
int Jam_trade()
{
bool trade = false;
if(Mulai_Jam > Akhir_Jam){
if (Hour() >= Mulai_Jam || Hour() < Akhir_Jam) trade = true;
} else
if (Hour() >= Mulai_Jam && Hour() < Akhir_Jam) trade = true;
return (trade);
}
int jumlahorder( int tipe)
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue;
total++;
}
return(total);
}
double NR(double thelot)
{
double maxlots = MarketInfo(Symbol(), MODE_MAXLOT),
minilot = MarketInfo(Symbol(), MODE_MINLOT),
lstep = MarketInfo(Symbol(), MODE_LOTSTEP);
double lots = lstep * NormalizeDouble(thelot / lstep, 0);
lots = MathMax(MathMin(maxlots, lots), minilot);
return (lots);
}
void dtrailing()
{
for(int i=0; i<OrdersTotal(); i++){
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic ) continue;
if(OrderType()==OP_BUY) {
if(Bid-OrderOpenPrice()>pt*TrailingStop) {
if((OrderStopLoss()<Bid-pt*TrailingStop) || (OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-pt*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
if(OrderType()==OP_SELL) {
if((OrderOpenPrice()-Ask)>(pt*TrailingStop)){
if(OrderStopLoss()>(Ask+pt*TrailingStop) || (OrderStopLoss()==0)){
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+pt*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
void closeall(int m)
{
for (int i = OrdersTotal() - 1; i >= 0; i--) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic || m!= OrderType()) continue;
if (OrderType() > 1) OrderDelete(OrderTicket());
else {
if (OrderType() == 0) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
else OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
}
}
}
double money()
{
double dp = 0;
int i;
for (i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic) continue;
dp += OrderProfit();
}
return(dp);
}
int trad()
{
int type,dp; double opb,ops,lastlotb,lastlots;
for (int i = 0; i < OrdersTotal(); i++) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
type=OrderType();
if(type==0)opb = OrderOpenPrice();
if(type==1)ops = OrderOpenPrice();
}
double as = opb - Jarak_order * pt;
double bi = ops + Jarak_order * pt;
if ( Ask <= as && jumlahorder(0)> 0 ) dp=1;
if ( Bid >= bi && jumlahorder(1)> 0 ) dp=2;
return(dp);
}
double xlot(int m)
{
double ylot,dlot;
for (int i = 0; i < OrdersTotal(); i++) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic ||OrderType()!=m) continue;
dlot=OrderLots();
}
if(OrderType()==m)ylot=NR(Lots*MathPow(DiMarti,jumlahorder(m)));
return(ylot);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: =>+Jum+AvZigzag+<=",
"\n :: =>JumForex.blogspot.com<=",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Jam Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------",
"\n :: Equity sekarang : ", AccountEquity()," $",
"\n :: Target_Equety : ", Target_Equety ," $",
"\n ------------------------------------------------",
"\n :: Posisi floting :",money()," $",
"\n :: Jumlah level :",jumlahorder(0)+jumlahorder(1),
"\n ------------------------------------------------",
"\n :: >>By: Jum69<<",
"\n ------------------------------------------------");
//+------------------------------------------------------------------+
}