BTC USD 77,443.9 Gold USD 4,366.84
Time now: Jun 1, 12:00 AM

Belajar Coding EA (mql) asas

Tuan bagaimana caranya agar EA ini
1. pasang buy stop dan sell stop sebanyak yang kita inginkan + TP dan SL ditentukan kita
2. Setelah TP hit, ingin memasang kembali PO di tempat yang sama

Terima kasih tuan

Seeloknya code yang diletakkan di sini adalah code original, supaya mudah faham.
Kalau boleh jangan tanya soalan yang terlalu umum. Saya di sini Cuba membantu anda belajar coding dan bukannya membantu buatkan ea. Harap anda faham.
 
Seeloknya code yang diletakkan di sini adalah code original, supaya mudah faham.
Kalau boleh jangan tanya soalan yang terlalu umum. Saya di sini Cuba membantu anda belajar coding dan bukannya membantu buatkan ea. Harap anda faham.


Ia maaf Tuan... saya khilap...

Oya, tuan. Bagaimana cara memberikan nama pada garis!
Contohnya, pada indikator i-reg...
SetIndexBuffer(0, fx);
SetIndexBuffer(1, sqh);
SetIndexBuffer(2, sql);

SetIndexStyle(0, DRAW_LINE); //bagaimana caranya agar garis ini ada namanya?
SetIndexStyle(1, DRAW_LINE); //bagaimana caranya agar garis ini ada namanya?
SetIndexStyle(2, DRAW_LINE); //bagaimana caranya agar garis ini ada namanya?

SetIndexEmptyValue(0, 0.0);
SetIndexEmptyValue(1, 0.0);
SetIndexEmptyValue(2, 0.0);

SetIndexShift(0, shift);
SetIndexShift(1, shift);
SetIndexShift(2, shift);
 
SetIndexLabel(0,"Line 1");
SetIndexLabel(1,"Line 2");
SetIndexLabel(2,"Line 3");
 
Nak minta tolong masta kat sini.
Code:
//+------------------------------------------------------------------+
//|                                              Buy  with SL and TP |
//|                               Copyright © 2008, smjones          |
//|                                               sjcoinc            |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, smjones"
#property link      "[email protected]"


//#property show_inputs

extern double Lots = 1;
extern bool   UseMoneyMgmt = true;
extern double RiskPercent = 2;
extern bool   UseStop = true;
extern bool   UseTakeProfit = true;
extern double StopLoss = 200;
extern double TakeProfit = 400;
extern string Note="0 in Entry field means Market Order Buy";
extern double Entry = 0.0000;

string Input = " Buy Price ";



//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  { 
  double Risk = RiskPercent / 100;
  if (UseMoneyMgmt)  
   Lots = NormalizeDouble( AccountBalance()*Risk/StopLoss/(MarketInfo(Symbol(), MODE_TICKVALUE)),2); 
  int Mode = OP_BUYSTOP;
  if (Ask > Entry && Entry > 0) Mode = OP_BUYLIMIT; 
  if (Entry == 0)  {Entry = Ask; Mode = OP_BUY;}
  double SLB = Entry - StopLoss*Point, TPB = Entry + TakeProfit*Point;
  if (UseStop == false) SLB = 0;
  if (UseTakeProfit == false) TPB = 0;
  if(Lots > 0)
   OrderSend(Symbol(),Mode, Lots, Entry, 2,SLB , TPB, "Buy Script", 0, NULL, LimeGreen);


           
   return(0);
  }
//+------------------------------------------------------------------+

Script ni ade open buy 0.03 cent. So macam mana nak ekjas dia supaya dia buka lot 0.1? Minta masta tengokkkan.
 
Lepas godek jumpe gak. RiskPercent tu letak 7. Dia akan open buy/sell 0.10 cent.
 
Lepas godek jumpe gak. RiskPercent tu letak 7. Dia akan open buy/sell 0.10 cent.

Lots = 0.1
UseMoneyMgmt = FALSE

Kalau UseMoneyMgmt=true, lots akan auto calculate
 
Mari kita bincang.. ape beza kod ni..?

Code:
(OrderSelect(tiket_bas, SELECT_BY_POS))
(OrderSelect(tiket_bas, SELECT_BY_POS, MODE_TRADES))
(OrderSelect(tiket_bas, SELECT_BY_POS, MODE_TRADES) == TRUE)



(OrderSelect(tiket_bas, SELECT_BY_TICKET) == TRUE)
 
OrderSelect(tiket_bas, SELECT_BY_POS)
OrderSelect(tiket_bas, SELECT_BY_POS, MODE_TRADES)

2 code kat atas tu sama, by default adalah MODE_TRADES melainkan ditukar MODE_HISTORY
OrderSelect(tiket_bas, SELECT_BY_POS, MODE_HISTORY) <-- select post kat history tab


OrderSelect(tiket_bas, SELECT_BY_POS, MODE_TRADES) == TRUE
ini untuk check sama ada tiket_bas itu exist, biasanya ada "if" kat depan

Code:
if(OrderSelect(tiket_bas, SELECT_BY_POS, MODE_TRADES) == TRUE)
{
  Print("Ada tiket");
}
else
{
  Print("Tak ada tiket");
}


Bezanya SELECT_BY_POS dan SELECT_BY_TICKET
SELECT_BY_POS = tiket_bas merupakan index
SELECT_BY_TICKET= tiket_bas merupakan tiket number

Code:
for (int i=0; i<OrdersTotal(); i++)
{
  OrderSelect([COLOR="Red"]i[/COLOR], [COLOR="Blue"]SELECT_BY_POS[/COLOR], MODE_TRADES);
  Print("Tiket bas: ", OrderTicket());
}
"i" adalah index

Code:
if (OrderSelect([COLOR="red"]12345[/COLOR], [COLOR="blue"]SELECT_BY_TICKET[/COLOR], MODE_TRADES)==true)
{
  Print("Tiket no 12345 wujud");
}
else
{
  Print("Tiket no 12345 tidak wujud");
}
"12345" adalah tiket number
 
bro camne nak adjust ea stealth kepada ea yg boleh buat PO ye?
 
//+------------------------------------------------------------------+
//| Martingale 2012.mq4 |
//| Copyright © 2011, NubieFX Software Corp. |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, NubieFX Software Corp."
#property link "[email protected]"
#define buy -2
#define sell 2
extern string Hak_Milik ="[email protected]";
extern string Nama_EA = "Martingale 2012";
extern string Please_Enter_Password = "0";
extern int magic =333;
extern bool Gunakan_Daily_Profit=true;
extern double Daily_TargetProfit=50;
extern double multiplier =2.0;
extern double start_lot =0.01;
extern double jarak_OP =20;
extern double layer =6;
extern double Money =2.0;
double tp =30;
double sl =60;
extern string stoch_tf_setting ="1=1M, 5=5M, 15=15M, 30=30M, 60=1H, 240=4H, 1440=D1, 10080=W1, 43200=MN1";
extern int Stoch_Timeframe_B =240;
extern int Stoch_Timeframe_T =30;
extern int Stoch_Timeframe_K =5;
extern string Seting_Stoch ="Seting Utk Semua Stoch";
extern int kperiod =14;
extern int dperiod =3;
extern int slowing =3;
extern string MA_method ="0=Simple, 1=Exponential, 2=Smoothed, 3=Linear weighted";
extern int method =3;
extern string Price_Field ="0=Low/High, 1=Cloce/Close";
extern int price_field =1;
int stoch_shift =0;
extern int sell_at_OB =80;
extern int buy_at_OS =20;
double pt;
double minlot;
double stoplevel;
int prec=0;
int a=0;
int i=0;
int ticket=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
if(Digits==3 || Digits==5) pt=10*Point;
else pt=Point;
minlot = MarketInfo(Symbol(),MODE_MINLOT);
stoplevel=MarketInfo(Symbol(),MODE_STOPLEVEL);
if(start_lot<minlot) Print("lotsize is to small.");
if(sl<stoplevel) Print("stoploss is to tight.");
if(tp<stoplevel) Print("takeprofit is to tight.");
if(minlot==0.01) prec=2;
if(minlot==0.1) prec=1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
string AccNo = "20903561";
string Real_Acc = AccountNumber();
//----
if (Please_Enter_Password != "Old Stoch Martingale") //change to the password you give the user!
{
Alert ("Wrong Password!");
return (0);
}
if (IsDemo() == FALSE)
{
if (Real_Acc != AccNo)
{
Alert("Sila gunakan akaun yang telah diberi Hak Milik.");
return;
}
}
if(Gunakan_Daily_Profit && dailyprofit()>=Daily_TargetProfit)
{
Comment("\ndaily target achieved.");
return(0);
}
if(dailyprofit()<=Daily_TargetProfit && total()==0 && a==0)
{
if(signal()==buy)
{
ticket=OrderSend(Symbol(),OP_BUY,start_lot,Ask,3,0,0,"Martingale 2012",magic,0,Blue);
}
if(signal()==sell)
{
ticket=OrderSend(Symbol(),OP_SELL,start_lot,Bid,3,0,0,"Martingale 2012",magic,0,Red);
}
}
if(total()>0 && total()<layer)
{
int type; double op, lastlot;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
type=OrderType();
op=OrderOpenPrice();
lastlot=OrderLots();
}
if(type==0 && Ask<=op-jarak_OP*pt)
{
ticket=OrderSend(Symbol(),0,NormalizeDouble(lastlot*multiplier,prec),Ask,3,0,0,"Martingale 2012",magic,0,Blue);
}
if(type==1 && Bid>=op+jarak_OP*pt)
{
ticket=OrderSend(Symbol(),1,NormalizeDouble(lastlot*multiplier,prec),Bid,3,0,0,"Martingale 2012",magic,0,Red);
}
}
//+------------------------------------------------------------------------------------------------------+
double profit=0;
for(i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic || OrderType()>1) continue;
profit+=OrderProfit();
}
if(profit>=Money || a>0)
{
closeall();
closeall();
closeall();
a++;
if(total()==0) a=0;
}
Comment("\n", " Martingale 2012 Copyright © 2012 - [email protected]",
"\n", " ========================================",
"\n", " HakMilik : [email protected]",
"\n", " Company : ",AccountCompany(),
"\n", " No Account : ",AccountNumber(),
"\n", " Pair : ",Symbol(),
"\n", " Daily Target : ",Daily_TargetProfit,
"\n", " Total Daily Profit : ",dailyprofit(),
"\n", " Total Open Post : ",total(),
"\n", " Profit Target : ",Money,
"\n", " Total Profit/Loss : ",AccountProfit(),
"\n", " Acc Equity : ",AccountEquity(),
"\n",

"\n");
//----
return(0);
}
//+------------------------------------------------------------------+
int total()
{
int total=0;
for(int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
total++;
}
return(total);
}
//+------------------------------------------------------------------+
int signal()
{
double stochMB=iStochastic(Symbol(),Stoch_Timeframe_B,kperiod,dperiod,slowing,method,price_field,MODE_MAIN,stoch_shift);
double stochSB=iStochastic(Symbol(),Stoch_Timeframe_B,kperiod,dperiod,slowing,method,price_field,MODE_SIGNAL,stoch_shift);

double stochMT=iStochastic(Symbol(),Stoch_Timeframe_T,kperiod,dperiod,slowing,method,price_field,MODE_MAIN,stoch_shift);
double stochST=iStochastic(Symbol(),Stoch_Timeframe_T,kperiod,dperiod,slowing,method,price_field,MODE_SIGNAL,stoch_shift);

double stochMK=iStochastic(Symbol(),Stoch_Timeframe_K,kperiod,dperiod,slowing,method,price_field,MODE_MAIN,stoch_shift);
double stochSK=iStochastic(Symbol(),Stoch_Timeframe_K,kperiod,dperiod,slowing,method,price_field,MODE_SIGNAL,stoch_shift);

double weeclose=iClose(Symbol(),PERIOD_W1,1);
double fibo=iCustom(Symbol(),PERIOD_W1,"FiboPiv_v2",0,0);
{
if(Bid>weeclose && stochMB<stochSB && stochMT<stochST && stochMK<stochSK && stochSB>sell_at_OB && stochST>sell_at_OB && stochSK>sell_at_OB) return(sell);
if(Ask<weeclose && stochMB>stochSB && stochMT>stochST && stochMK>stochSK && stochSB<buy_at_OS && stochST<buy_at_OS && stochSK<buy_at_OS) return(buy);
}
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 dailyprofit()
{
int day=Day(); double res=0;
for(int i=0; i<OrdersHistoryTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
if(TimeDay(OrderOpenTime())==day) res+=OrderProfit();
}
return(res);
}
//+-----------------------------------------------------------------+
 

Latest Posts

Live Forex Chart

Currency
Rates
EUR / USD
1.14869
USD / JPY
157.191
GBP / USD
1.33624
USD / CHF
0.82434
USD / CAD
1.39928
EUR / JPY
180.500
AUD / USD
0.71233
Back
Top
Log in Register