//+-----------------------------------------------------------------------+
//| ~~ tes trigger op stoch ~~.mq4 |
//| @tes trigger op stoch |
//| |
//+-----------------------------------------------------------------------+
#property copyright "@tes trigger op stoch"
/*-- Parameter ini ditampilkan di EA dan bisa diubah --*/
extern int TakeProfit = 10; // Nilai TP setiap OP di EA Martingale ini
extern int PipStep = 10; // Jarak pip dimana akan buka OP baru
extern int Slippage = 3; // Apa itu slippage ? Googling sendiri ya..
extern double Lots = 0.05; // Nilai lots awal, nantinya akan digandakan setiap step
extern double Multiply = 3.0; // Nilai pengali setiap step OP baru
extern int MaxTrade = 7; // Banyak OP maksimal yang boleh dijalankan
extern bool UseTime = TRUE; // Pilihan apakah memakai waktu bekerjanya EA ?
extern int HourStart = 24; // Waktu mulai EA bekerja
extern int HourEnd = 13; // Waktu akhir EA bekerja
/*-- Parameter ini tidak ditampilkan di EA --*/
string EAName = "~~tes trigger op stoch~~"; // Nama EA, untuk ditampilkan di layar
string EAComment = "~~tes trigger op stoch~~"; // Variabel ini akan kita masukkan di setiap OP sebagai Comment
int EAMagicNumber = 8095; // Magic Number
double SetPoint = 0; // Variabel SetPoint untuk kode digit broker 4 atau 5
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
SetBroker();
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int iTrade=0;
Comment(EAName); // Tampilkan Nama EA di layar
/* -- Jika tidak ada OP sama sekali, maka jalankan fungsi berikut --*/
/* -- Disinilah tempat anda memasukkan koding indikator untuk memicu OP --*/
if(OrdersTotal()==0)
{
if ((iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) > iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
{
/*-- Order Buy --*/
OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);
}
else if ((iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_MAIN,0) < iStochastic(NULL, NULL,4,14,1,MODE_SMA,0,MODE_SIGNAL,0)))
{
/*-- Order Sell --*/
OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
}
}
/* -- Inilah Fungsi Martingale. Jika ada OP yang salah, maka lakukan martingale --*/
if(OrdersTotal()>=1)
{
GoMartingale();
}
//----
return(0);
}
//+------------------------------------------------------------------+
/*--agar EA bisa running di Broker 4 Digit atau 5 Digit--*/
void SetBroker()
{
if (Digits==3 || Digits==5) // Perintah untuk broker 5 Digits
{SetPoint=Point*10;}
else // Perintah untuk broker 4 Digits
{SetPoint=Point;}
}void GoMartingale()
{
int iCount = 0;
double LastOP = 0;
double LastLots = 0;
bool LastIsBuy = FALSE;
int iTotalBuy = 0;
int iTotalSell = 0;
int Spread=0;
Spread= MarketInfo(Symbol(), MODE_SPREAD);
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP>OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=TRUE;
iTotalBuy++;
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
if(iTotalBuy==MaxTrade) {return(0);}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(LastOP==0) {LastOP=OrderOpenPrice();}
if(LastOP<OrderOpenPrice()) {LastOP=OrderOpenPrice();}
if(LastLots<OrderLots()) {LastLots=OrderLots();}
LastIsBuy=FALSE;
iTotalSell++;
/* Bila mencapai batas OP maksimal, jangan tambah OP lagi */
if(iTotalBuy==MaxTrade) {return(0);}
}
}
/* Jika arah Price adalah DOWNTREND...., Periksa nilai Bid (*/
if(LastIsBuy)
{
if(Bid<=LastOP-(Spread*SetPoint)-(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_BUY, Multiply*LastLots, Ask, Slippage, 0, Ask+TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
LastIsBuy=FALSE;
return(0);
}
}
/* Jika arah Price adalah Sell...., Periksa nilai Ask (*/
else if(!LastIsBuy)
{
if(Ask>=LastOP+(Spread*SetPoint)+(PipStep*SetPoint))
{
OrderSend(Symbol(), OP_SELL, Multiply*LastLots, Bid, Slippage, 0, Bid-TakeProfit*SetPoint, EAComment, EAMagicNumber);
ModifyTP();
return(0);
}
}
}
/*-- Fungsi ModifyTP ini untuk mengubah semua OP agar TP di titik yang sama --*/
void ModifyTP()
{
int iCount=0;
double NewTP=0;
/*- Ambil nilai Take Profit dari Order terakhir -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
/*-- Kalau OP-nya adalah BUY, ambil nilai TP yang paling kecil. Jadikan TP bersama --*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP>OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}
/*-- Kalau OP-nya adalah SELL, ambil nilai TP yang paling besar. Jadikan TP bersama --*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
if(NewTP==0) {NewTP=OrderTakeProfit();}
if(NewTP<OrderTakeProfit()) {NewTP=OrderTakeProfit();}
}
}
/*- Ubah semua nilai OP TakeProfit dengan yang baru (2x lipat) -*/
for(iCount=0;iCount<OrdersTotal();iCount++)
{
OrderSelect(iCount,SELECT_BY_POS,MODE_TRADES);
/*- Kalau semua OP adalah BUY, maka ubahlah TP mereka -*/
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
/*- Kalau semua OP adalah SELL, maka ubahlah TP mereka -*/
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderComment()==EAComment && OrderMagicNumber()==EAMagicNumber)
{
OrderModify(OrderTicket(), OrderLots(), 0, NewTP, 0);
}
}
}
February 23rd, 2009 at 7:10 pm This is some Enhancement:
// ===============================================
Print(“MODE_LOTSIZE = “, MarketInfo(Symbol(),MODE_LOTSIZE), “, Symbol = “, Symbol());
Print(“MODE_MINLOT = “, MarketInfo(Symbol(),MODE_MINLOT), “, Symbol = “, Symbol());
Print(“MODE_LOTSTEP = “, MarketInfo(Symbol(),MODE_LOTSTEP), “, Symbol = “, Symbol());
Print(“MODE_MAXLOT = “, MarketInfo(Symbol(),MODE_MAXLOT), “, Symbol = “, Symbol());
// ===============================================
August 27th, 2012 at 3:14 pm
Thanks for your help.But ı have used this code and i learned max lot size is 30.
How can i increase max lot size.
Yours sincerely.
August 27th, 2012 at 4:09 pm
Only your broker can increase your allowed max lot size. You may try contacting their support service about that but I am not sure that they will increase it. Do you really have to open such big positions?
November 21st, 2009 at 10:29 pm “You can incorporate the MarketInfo() function at a more complex level into your EA, so it could automatically check the allowed values and correct its settings”
Please what is the code. I need it but I am not a coder. Grateful. Chad
November 21st, 2009 at 10:43 pm Chad, If you aren’t coder it’d be better for you to use the solution proposed in this post. Integration of MarketInfo() into code for automatic adjustments is different in each case and I won’t be able to help you here. More than that, you don’t really need it if you aren’t a professional coder.