http://jumforex.blogspot.com/2012/10/belajar-membuat-ea-sederhana-15.html
Pada bagian ini kita akan memodifikasi EA pada part 14 dengan sedikit penambahan hedge average
Seperti pada part-part sebelumnya telah dibahas juga op hedge (buy dan sell) .
Supaya terjadi ordernya tidak satu arah tetapi order berdasarkan signal yang terjadi , maka bagian yang di rubah adalh pagian trigernya dengan menghilangkan filter jumlah order yang berlawanan , sebagai berikut:
if( jumlahorder(0)<Max_order && Trade_buy && signal==1 && wt!=Time[0] ){tiket = OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);
if(tiket>0) wt=Time[0];
}
if( jumlahorder(1)<Max_order && Trade_sell && signal==2 && wk!=Time[0]) {ticet = OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);
if(ticet>0) wk=Time[0];
}
Sehingga bila dimasukkan ke dalam EAnya :
//+------------------------------------------------------------------+
//| EA MA Cross AntiQ+ |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Cross AntiQ+";
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 = 2;
extern int TP = 100;
extern int SL = 100;
extern int Max_order = 10;
extern double Lots = 0.1;
extern bool TrailingStop_ = true;
extern int TrailingStop = 20;
extern int Magic = 69;
extern string Seting_MA = "Sesuka Hati";
extern int Pereode_1 = 4;
extern int Pereode_2 = 4;
double slb,tpb,sls,tps,pt;
int wt,wk,tiket,ticet;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point; else pt=Point;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if(TrailingStop_)dtrailing();
if(Tp_in_Money && TP_in_money<= money()) closeall();
//----
double MA_1O =iMA(Symbol(),0,Pereode_1,0,MODE_SMA,PRICE_OPEN ,1);
double MA_1C =iMA(Symbol(),0,Pereode_1,0,MODE_SMA,PRICE_CLOSE ,1);
double MA_2O =iMA(Symbol(),0,Pereode_2,0,MODE_SMA,PRICE_OPEN ,2);
double MA_2C =iMA(Symbol(),0,Pereode_2,0,MODE_SMA,PRICE_CLOSE ,2);
int signal;
if(MA_2O >MA_2C && MA_1O < MA_1C) signal=1;// aturan buy
if(MA_2O <MA_2C && MA_1O > MA_1C) signal=2;//aturan sell
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)<Max_order && Trade_buy && signal==1 && wt!=Time[0] ){tiket = OrderSend(Symbol(),OP_BUY,NR(Lots),Ask,3,slb, tpb,Nama_EA,Magic,0,Blue);
if(tiket>0) wt=Time[0];
}
if( jumlahorder(1)<Max_order && Trade_sell && signal==2 && wk!=Time[0]) {ticet = OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);
if(ticet>0) wk=Time[0];
}
}
//----
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()
{
for (int i = OrdersTotal() - 1; i >= 0; i--) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic ) 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);
}
Jadideh..........
Semoga sukses deh
Salam
Maaf master, mau tanya, kalau coding untuk biar OP mengikuti trend besar gimana ya? contohnya begini :
Jika Trend besar turun, EA hanya akan OP SELL meskipun ada sinyal buy, begitu sebaliknya.
jadi bisa otomatis, tidak usah mengubah settingan Trade_Buy = true/false & Trade_Sell = True/False
sekian master, mohon maaf sebelumnya.
wassalam
contoh pada ea di atas
if(MA_2O >MA_2C && MA_1O < MA_1C && tambah aturan trend besar buy) signal=1;// aturan buy
if(MA_2O MA_1C && tambah aturan trend besar sell) signal=2;//aturan sell