Pastikan sudah mengikuti part 21 disini
Pada posting kali ini saya akan mengedit EA pada part 21 untuk ditambahi martingel .
Martingel yang di maksud juga mengacu pada jarak (range) order dan pergantian candel untuk mencegah terjadinya beberapa order ketika terjadi lonjakan harga dan candel panjang , seperti pada part 18
Penambahan coding martingelnya :
1. Fungsi untuk perintah order martingelnya
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {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 ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
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);
}
3. Fungsi untuk perhitungan Lots setiap pengulangan ordernya
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);
}
Nah setelah di rakit begini deh hasinya:
//+------------------------------------------------------------------+
//| EA Jum+Profit |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+Profit";
extern bool Trade_buystop = true;
extern bool Trade_sellstop = true;
extern string Jam_server = "Set sesuai selera";
extern int Jam = 0;
extern int Menit = 30;
extern bool Tp_in_Money = false;
extern double TP_in_money = 5;
extern int Jarak_order = 35;
extern int Max_order = 10;
extern double DiMarti = 1.3;
extern int TP = 100;
extern int SL = 20;
extern double Lots = 0.1;
extern int Jarak_stop = 25;
extern bool TrailingStop_ = true;
extern int TrailingStop = 12;
extern int Magic = 69;
double slb,tpb,sls,tps,pt,lslb,ltpb;
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()
{
label();
if(TrailingStop_)dtrailing();
if(Tp_in_Money ){
if(TP_in_money<= money(0)){
closeall(0);
closeall(2);
}
if(TP_in_money<= money(1)){
closeall(1);
closeall(3);
}
}
if(jumlahorder(0)==1 && jumlahorder(1)==0){
closeall(5);
}
if(jumlahorder(0)==0 && jumlahorder(1)==1){
closeall(4);
}
if(Hour()==23){
closeall(4);
closeall(5);
}
//----
double as = Ask + Jarak_stop*pt;
double bi = Bid - Jarak_stop*pt;
if(SL==0)slb=0;else slb=as-SL*pt;
if(SL==0)sls=0;else sls=bi+SL*pt;
if(TP==0)tpb=0;else tpb=as+TP*pt;
if(TP==0)tps=0;else tps=bi-TP*pt;
if(DayOfWeek()!=1 && Hour()==Jam && Minute()==Menit && jumlahorder(0)==0 && jumlahorder(1)==0){
if(jumlahorder(4)==0 && Trade_buystop ) {OrderSend(Symbol(),OP_BUYSTOP,NR(Lots),as,3,slb, tpb,Nama_EA,Magic,0,Blue);}
if(jumlahorder(5)==0 && Trade_sellstop ) {OrderSend(Symbol(),OP_SELLSTOP,NR(Lots),bi,3,sls, tps,Nama_EA,Magic,0,Red);}
}
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {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 ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
return(0);
}
//+------------------------------------------------------------------+
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() == m) OrderDelete(OrderTicket());
if (OrderType() == m) OrderDelete(OrderTicket());
if (OrderType() == m) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
if (OrderType() == m)OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
}
}
double money(int m)
{
double dp = 0;
int i;
for (i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic || m!=OrderType()) continue;
dp += OrderProfit();
}
return(dp);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: =>+Jum+Profit<=",
"\n :: =>JumForex.blogspot.com<=",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Jam Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------",
"\n :: Floting buy : ",money(0),
"\n :: Floting sell : ",money(1),
"\n ------------------------------------------------",
"\n :: >>By: Jum69<<",
"\n ------------------------------------------------");
}
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);
}
Pada posting kali ini saya akan mengedit EA pada part 21 untuk ditambahi martingel .
Martingel yang di maksud juga mengacu pada jarak (range) order dan pergantian candel untuk mencegah terjadinya beberapa order ketika terjadi lonjakan harga dan candel panjang , seperti pada part 18
Penambahan coding martingelnya :
1. Fungsi untuk perintah order martingelnya
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {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 ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
2. Fungsi untuk perhitungan jarak order dan perintah ketika jarak terpenuhi
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);
}
3. Fungsi untuk perhitungan Lots setiap pengulangan ordernya
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);
}
Nah setelah di rakit begini deh hasinya:
//+------------------------------------------------------------------+
//| EA Jum+Profit |
//| gifaesa@yahoo.com |
//| http://JumForex.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "JumForex.blogspot.com"
#property link "Gifaesa@yahoo.com"
extern string Nama_EA = "Jum+Profit";
extern bool Trade_buystop = true;
extern bool Trade_sellstop = true;
extern string Jam_server = "Set sesuai selera";
extern int Jam = 0;
extern int Menit = 30;
extern bool Tp_in_Money = false;
extern double TP_in_money = 5;
extern int Jarak_order = 35;
extern int Max_order = 10;
extern double DiMarti = 1.3;
extern int TP = 100;
extern int SL = 20;
extern double Lots = 0.1;
extern int Jarak_stop = 25;
extern bool TrailingStop_ = true;
extern int TrailingStop = 12;
extern int Magic = 69;
double slb,tpb,sls,tps,pt,lslb,ltpb;
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()
{
label();
if(TrailingStop_)dtrailing();
if(Tp_in_Money ){
if(TP_in_money<= money(0)){
closeall(0);
closeall(2);
}
if(TP_in_money<= money(1)){
closeall(1);
closeall(3);
}
}
if(jumlahorder(0)==1 && jumlahorder(1)==0){
closeall(5);
}
if(jumlahorder(0)==0 && jumlahorder(1)==1){
closeall(4);
}
if(Hour()==23){
closeall(4);
closeall(5);
}
//----
double as = Ask + Jarak_stop*pt;
double bi = Bid - Jarak_stop*pt;
if(SL==0)slb=0;else slb=as-SL*pt;
if(SL==0)sls=0;else sls=bi+SL*pt;
if(TP==0)tpb=0;else tpb=as+TP*pt;
if(TP==0)tps=0;else tps=bi-TP*pt;
if(DayOfWeek()!=1 && Hour()==Jam && Minute()==Menit && jumlahorder(0)==0 && jumlahorder(1)==0){
if(jumlahorder(4)==0 && Trade_buystop ) {OrderSend(Symbol(),OP_BUYSTOP,NR(Lots),as,3,slb, tpb,Nama_EA,Magic,0,Blue);}
if(jumlahorder(5)==0 && Trade_sellstop ) {OrderSend(Symbol(),OP_SELLSTOP,NR(Lots),bi,3,sls, tps,Nama_EA,Magic,0,Red);}
}
if(trad()==1 && wt!=Time[0] && jumlahorder(1)==0 && jumlahorder(0)<Max_order ) {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 ) {OrderSend(Symbol(),OP_SELL,xlot(1),Bid,3,sls, tps,Nama_EA,Magic,0,Red); wk=Time[0]; }
return(0);
}
//+------------------------------------------------------------------+
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() == m) OrderDelete(OrderTicket());
if (OrderType() == m) OrderDelete(OrderTicket());
if (OrderType() == m) OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
if (OrderType() == m)OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
}
}
double money(int m)
{
double dp = 0;
int i;
for (i = 0; i < OrdersTotal(); i++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber()!=Magic || m!=OrderType()) continue;
dp += OrderProfit();
}
return(dp);
}
void label()
{
Comment("\n ",
"\n ",
"\n ------------------------------------------------",
"\n :: =>+Jum+Profit<=",
"\n :: =>JumForex.blogspot.com<=",
"\n ------------------------------------------------",
"\n :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD),
"\n :: Leverage : 1 : ", AccountLeverage(),
"\n :: Equity : ", AccountEquity(),
"\n :: Jam Server :", Hour(), ":", Minute(),
"\n ------------------------------------------------",
"\n :: Floting buy : ",money(0),
"\n :: Floting sell : ",money(1),
"\n ------------------------------------------------",
"\n :: >>By: Jum69<<",
"\n ------------------------------------------------");
}
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);
}
Ini hasil BTnya:
Okey seilahkan de coba ya...
Bila mana ada yang kurang jelas dan ada ide positif silahkan comment ya!