http://jumforex.blogspot.com/2012/10/belajar-membuat-ea-sederhana-17.html
Pastikan telah mengikuti di part 16 disini
Nah setelah kita pelajari cara membuat custom indikator Donchian pada part sebelumnya , maka kita akan coba bikin EAnya dengan indikator tersebut
Yandg belum punya indikator silahkan download dulu di part 15
Rulenya sbb:
mode trend
Buy : Pada saat harga di atas garis merah atas
Sell : Pada saat harga di bawah garis merah bawah
mode reversal
dan rule di atas di balik
Sehingga di tambahkan
if(Mode_trend){
if(da<Ask) signal=1;// aturan buy
if(db>Bid) signal=2;//aturan sell
}
if(!Mode_trend){
if(da<Ask) signal=2;// aturan sell
if(db>Bid) signal=1;//aturan buy
}
Ini untu mengatur sesuai selera signal mana yang mau digunakan
Untuk EA yang dibikin mengacu pada EA yang telah dibikin sebelumnya
//+------------------------------------------------------------------+
//| EA Jum+Donchian+ |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+Donchian+";
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 = false;
extern double TP_in_money = 2;
extern bool Mode_trend = true;
extern int TP = 100;
extern int SL = 500;
extern double Lots = 0.1;
extern bool TrailingStop_ = true;
extern int TrailingStop = 25;
extern int Magic = 69;
extern string Seting_Donchian = "Sesuka Hati";
extern int IPeriod = 20;
double slb,tpb,sls,tps,pt;
//+------------------------------------------------------------------+
//| 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 da = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 0,0 ) ;// garis atas modenya 0
double db = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 1,0 ) ;// garis bawah modenya 1
double dt = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 2,0 ) ;// garis tengah modenya 2
int signal;
if(Mode_trend){
if(da<Ask) signal=1;// aturan buy
if(db>Bid) signal=2;//aturan sell
}
if(!Mode_trend){
if(da<Ask) signal=2;// aturan sell
if(db>Bid) signal=1;//aturan buy
}
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==1) {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==2) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);}
}
//----
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);
}
Jadi deh
Mudah2 an dengan gambaran EA di atas akan membuka wawasan bagi trader semuanya
Salam Sukses
Nah setelah kita pelajari cara membuat custom indikator Donchian pada part sebelumnya , maka kita akan coba bikin EAnya dengan indikator tersebut
Yandg belum punya indikator silahkan download dulu di part 15
Rulenya sbb:
mode trend
Buy : Pada saat harga di atas garis merah atas
Sell : Pada saat harga di bawah garis merah bawah
mode reversal
dan rule di atas di balik
Sehingga di tambahkan
if(Mode_trend){
if(da<Ask) signal=1;// aturan buy
if(db>Bid) signal=2;//aturan sell
}
if(!Mode_trend){
if(da<Ask) signal=2;// aturan sell
if(db>Bid) signal=1;//aturan buy
}
Ini untu mengatur sesuai selera signal mana yang mau digunakan
Untuk EA yang dibikin mengacu pada EA yang telah dibikin sebelumnya
//+------------------------------------------------------------------+
//| EA Jum+Donchian+ |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+Donchian+";
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 = false;
extern double TP_in_money = 2;
extern bool Mode_trend = true;
extern int TP = 100;
extern int SL = 500;
extern double Lots = 0.1;
extern bool TrailingStop_ = true;
extern int TrailingStop = 25;
extern int Magic = 69;
extern string Seting_Donchian = "Sesuka Hati";
extern int IPeriod = 20;
double slb,tpb,sls,tps,pt;
//+------------------------------------------------------------------+
//| 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 da = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 0,0 ) ;// garis atas modenya 0
double db = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 1,0 ) ;// garis bawah modenya 1
double dt = iCustom(Symbol(), 0,"Donchian Bands",IPeriod, 2,0 ) ;// garis tengah modenya 2
int signal;
if(Mode_trend){
if(da<Ask) signal=1;// aturan buy
if(db>Bid) signal=2;//aturan sell
}
if(!Mode_trend){
if(da<Ask) signal=2;// aturan sell
if(db>Bid) signal=1;//aturan buy
}
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==1) {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==2) {OrderSend(Symbol(),OP_SELL,NR(Lots),Bid,3,sls, tps,Nama_EA,Magic,0,Red);}
}
//----
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);
}
Jadi deh
Mudah2 an dengan gambaran EA di atas akan membuka wawasan bagi trader semuanya
Salam Sukses
Tidak ada komentar:
Posting Komentar