BTC USD 76,639.3 Gold USD 4,369.89
Time now: Jun 1, 12:00 AM

Belajar Coding EA (mql) asas

cadangan yg baik dari tuan. tapi amber masih pening lalat. ambik masa la bagi nubi cam amber nak paham
 
cadangan yg baik dari tuan. tapi amber masih pening lalat. ambik masa la bagi nubi cam amber nak paham

kayuh pelan-pelan bro... nak belajar apa apa pun kena ada minat, ketekunan dan kesabaran...

Aku ada jumpa gak orang ada degree jadi pensyarah programming kat kolej, tapi tak reti gak MQL... Mengajar ikut silibus, tak tentu boleh apply lagi...

Ada gak orang aku kenal tak da basic programming langsung... sebab minat, ketekunan dan kesabaran dia, sekarang dah jadi superb EA coder...

Dan ada gak orang dah dekat 60 tahun umur, tapi pasal minat dah boleh buat EA sendiri sekarang...
 
Code:
 if (iOpen(0,0,0)>s5 && Bid<=s5) lotMM = 0.9; //-- candle cross s5 ataupun
	  if (iOpen(0,0,0)>s4 && Bid<=s4) lotMM = 0.8;//-- candle cross s4 ataupun
	  if (iOpen(0,0,0)>s3 && Bid<=s3) lotMM = 0.7;//-- candle cross s3 ataupun
	  if (iOpen(0,0,0)>s2 && Bid<=s2) lotMM = 0.6;//-- candle cross s2 ataupun
	  if (iOpen(0,0,0)>s1 && Bid<=s1) lotMM = 0.5;  //-- candle cross s1
	
     //if(lotMM >= MaxLotSize) lotMM = MaxLotSize;
     if (iOpen(0,0,0)<r5 && Ask>=r5) lotMM = 0.9;//-- candle cross r5 ataupun
	  if (iOpen(0,0,0)<r4 && Ask>=r4) lotMM = 0.8; //-- candle cross r4 ataupun
	  if (iOpen(0,0,0)<r3 && Ask>=r3) lotMM = 0.7; //-- candle cross r3 ataupun
	  if (iOpen(0,0,0)<r2 && Ask>=r2) lotMM = 0.6;//-- candle cross r2 ataupun
	  if (iOpen(0,0,0)<r1 && Ask>=r1) lotMM = 0.5;


sye tk pakai stoct pn dalam EA sye ni...D

sye pakai garisan fibo ni je.. semua profit...takde lose langsung..tapi apa yg sye nk majukan lagi ialah:

Bila..

Katakan harga semasa dh cross kt S1..pastu robot ni buat buy..tapi hrga turun lagi ke S2..pastu lagi robot buat buy...kemudian harga turun lagi.. robot pn buat buy kt S3..

semua ada 3 buy...

macam mana nk buat bila OP yg pada S3 tdi dh profit 50 pips.. semua OP S2,S3 ni nk close (exit)...

kirannya S3 ni bukak lot besar dan cover kerugian S1 dan S2..:)
 
Code:
 if (iOpen(0,0,0)>s5 && Bid<=s5) lotMM = 0.9; //-- candle cross s5 ataupun
	  if (iOpen(0,0,0)>s4 && Bid<=s4) lotMM = 0.8;//-- candle cross s4 ataupun
	  if (iOpen(0,0,0)>s3 && Bid<=s3) lotMM = 0.7;//-- candle cross s3 ataupun
	  if (iOpen(0,0,0)>s2 && Bid<=s2) lotMM = 0.6;//-- candle cross s2 ataupun
	  if (iOpen(0,0,0)>s1 && Bid<=s1) lotMM = 0.5;  //-- candle cross s1
	
     //if(lotMM >= MaxLotSize) lotMM = MaxLotSize;
     if (iOpen(0,0,0)<r5 && Ask>=r5) lotMM = 0.9;//-- candle cross r5 ataupun
	  if (iOpen(0,0,0)<r4 && Ask>=r4) lotMM = 0.8; //-- candle cross r4 ataupun
	  if (iOpen(0,0,0)<r3 && Ask>=r3) lotMM = 0.7; //-- candle cross r3 ataupun
	  if (iOpen(0,0,0)<r2 && Ask>=r2) lotMM = 0.6;//-- candle cross r2 ataupun
	  if (iOpen(0,0,0)<r1 && Ask>=r1) lotMM = 0.5;


sye tk pakai stoct pn dalam EA sye ni...D

sye pakai garisan fibo ni je.. semua profit...takde lose langsung..tapi apa yg sye nk majukan lagi ialah:

Bila..

Katakan harga semasa dh cross kt S1..pastu robot ni buat buy..tapi hrga turun lagi ke S2..pastu lagi robot buat buy...kemudian harga turun lagi.. robot pn buat buy kt S3..

semua ada 3 buy...

macam mana nk buat bila OP yg pada S3 tdi dh profit 50 pips.. semua OP S2,S3 ni nk close (exit)...

kirannya S3 ni bukak lot besar dan cover kerugian S1 dan S2..:)

Saya hanya kasi contoh dan idea. Tak semestinya tuan akan ikut 100% contoh yang saya beri.

Kalau tenguk sequence lot tuan ialah 0.5,0.6,0.7,0.8 dan 0.9
Bermakna penambahan 0.1 lot setiap next open pos, jadi tuan boleh buat custom function macam ni

Code:
double KiraLots (int orderType)
{
   double lots = 0; 
   
   for (int i=0; i<OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()!=Symbol() || OrderType()!=orderType || OrderMagicNumber()!=magicNumber) continue;
      lots = MathMax (lots, OrderLots());
   }
    if (lots ==0)  return (0.5);
   return (NormalizeDouble(lots+0.1,2));
}

Letakkan di dalam OrderSend

Code:
OrderSend(Symbol(),OP_BUY,[COLOR="Navy"]KiraLots(OP_BUY)[/COLOR],Ask,3,0,0,"komen saya",magicNumber,0,Green);

OrderSend(Symbol(),OP_SELL,[COLOR="navy"]KiraLots(OP_SELL)[/COLOR],Bid,3,0,0,"komen saya",magicNumber,0,Red);


function di atas akan buka lot bermula 0.5 lot, Setiap pos berikutnya akan ditambah 0.1 lot
Saya juga assume EA tuan juga ada menggunakan magic number. magicNumber tu pandai2 la tuan edit


Custom function di bawah ni pula untuk mengira jumlah pips tertinggi untuk setiap pos

Code:
double KiraPips (int orderType)
{
   double pips=0;
   for (int i=0; i<OrdersTotal(); i++)
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=magicNumber || OrderType()!=orderType) continue;
      if (orderType==OP_BUY)  pips = MathMax(Bid-OrderOpenPrice())/Point, pips);
      if (orderType==OP_SELL) pips = MathMax(OrderOpenPrice()-Ask)/Point, pips);
   }
   return (NormalizeDouble(pips, 0));
}

boleh letak macam ni dalam start ()

Code:
if ([COLOR="navy"]KiraPips(OP_BUY)[/COLOR]>=50) 
{
	[COLOR="DimGray"]//-- letakkan close all buy function di sini[/COLOR]
}

if ([COLOR="navy"]KiraPips(OP_SELL)[/COLOR]>=50) 
{
	[COLOR="DimGray"]//-- letakkan close all sell function di sini[/COLOR]
}

Kalau ikutkan style trading tuan, pos yang paling tinggi nilai lot akan mempunyai paling tinggi pips. Jadi EA akan check setiap pos. Mana-mana pos yang mencecah 50 pips, ea akan call function untuk close all.
 
Last edited:
kalau strategy tester tu...

ada tulis close at stop apa maksudnye..?

slalu last date ada cam tu..
 
close semua open pos bila strategy tester stop
 
salam .. sy newbi. nak minta bro tempe atau aiman leh tak tulung wat kan ea camni :

scan ada post tak { kalo takde masuk 10 post serentak }
post sell atau buy set di variable. tp 10 sl takde

gak2 camne kod dia?
tq
 
salam .. sy newbi. nak minta bro tempe atau aiman leh tak tulung wat kan ea camni :

scan ada post tak { kalo takde masuk 10 post serentak }
post sell atau buy set di variable. tp 10 sl takde

gak2 camne kod dia?
tq

jumlah semua pos guna OrdersTotal(). tapi dia akan beri jumlah semua pos termasuk lain2 pair dan pending order
kalau nak kira current chart aje kena iterate guna for dan filter yang mana tak nak

contoh ea boleh jadi macam ni

Code:
int start ()
{
   [COLOR="Gray"]// kira total pos untuk current chart[/COLOR]
   int totalPos = 0; [COLOR="gray"]// declare variable untuk total pos[/COLOR]
   for (int i=0; i<OrdersTotal(); i++) [COLOR="gray"]// loop 1 per 1 [/COLOR]
   {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES); [COLOR="Gray"]// select pos ikut turutan ticket #[/COLOR]
      if (OrderSymbol()!=Symbol) continue;  [COLOR="Gray"]// sekiranya pair bukan current chart.... skip[/COLOR]
      if (OrderType()!=OP_BUY || OrderType()!=OP_SELL) continue; [COLOR="gray"]// kalau bukan BUY atau SELL.... skip[/COLOR]
      totalPos++; [COLOR="gray"]// totalPos tambah 1[/COLOR]
   }


   if (totalPos==0) [COLOR="gray"]// sekiranya totalpos = 0 [/COLOR]
   {
      for (int i=0; i<10; i++) [COLOR="Gray"]// repeat 10 kali[/COLOR]
      {
         OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+10*Point,"My order buy",0,0,Green); [COLOR="gray"]// buy 1 lot tp 10[/COLOR]
         Sleep (1000); [COLOR="gray"]// delay 1 saat[/COLOR]
         OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-10*Point,"My order sell",0,0,Red); [COLOR="gray"]// sell 1 lot tp 10[/COLOR]
         Sleep (1000); [COLOR="gray"]// delay 1 saat[/COLOR]
      }
   }
   
   return (0);
}

Untuk open pos, guna function OrderSend. OrderSend boleh diguna banyak cara, boleh jugak untuk PO. Sila refer ke help library dalam metaeditor untuk syntax OrderSend

Kalau nak set variable, contoh nilai lot dan tp jadi variable

Code:
extern double [COLOR="Red"]lot [/COLOR]= 1.0;
extern int [COLOR="red"]takeProfit [/COLOR]= 10.0;

lepas tu dalam OrderSend jadi

Code:
[COLOR="Red"]double tpBuy=0;
double tpSell=0;
if (takeprofit>0)
{
  tpBuy = Ask+takeProfit*Point;
  tpSell = Bid-takeProfit*Point;
}[/COLOR]
OrderSend(Symbol(),OP_BUY,[COLOR="Red"]lot[/COLOR],Ask,3,0,[COLOR="Red"]tpBuy[/COLOR],"My order buy",0,0,Green);
OrderSend(Symbol(),OP_SELL,[COLOR="Red"]lot[/COLOR],Bid,3,0,[COLOR="Red"]tpSell[/COLOR],"My order sell",0,0,Red);
 
Last edited:

Live Forex Chart

Currency
Rates
EUR / USD
1.14785
USD / JPY
155.854
GBP / USD
1.33457
USD / CHF
0.82448
USD / CAD
1.39924
EUR / JPY
178.896
AUD / USD
0.71128
Back
Top
Log in Register