BTC USD 80,864.6 Gold USD 4,382.33
Time now: Jun 1, 12:00 AM

Belajar Coding EA (mql) asas

for (int i=0; i<OrdersTotal(); i++) <---order total ni utk apa ye
bro aiman?
 
Contohnya kalau kita ada 2 buy, 2 sell, 2 po buy stop, 3 po sell limit (tak kira apa pair pun)
total semua open pos dan pending orders = OrdersTotal() = 9

Untuk cycle through semua pos yang ada kena guna OrderSelect
daripada situ kita tahu jenis pos, saiz lot dan lain-lain

Code:
OrderSelect(0, SELECT_BY_POS, MODE_TRADES); [COLOR="Gray"]// select pos pertama[/COLOR]
OrderSelect(1, SELECT_BY_POS, MODE_TRADES); [COLOR="gray"]// select pos ke 2[/COLOR]
OrderSelect(2, SELECT_BY_POS, MODE_TRADES); [COLOR="gray"]// select pos ke 3[/COLOR]
OrderSelect(.... [COLOR="gray"]// sampai 9 kali[/COLOR]

ataupun boleh buat macam ni

Code:
for (int i=0; i<OrdersTotal(); i++)
{
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES); [COLOR="gray"]// variable i di guna semula untuk select pos satu per satu ikut turutan[/COLOR]

selepas pos tersebut di select, kita boleh dapatkan info daripada pos tersebut dengan menggunakan OrderType(), OrderSymbol(), OrderTakeProfit(), OrderStopLoss() dan beberapa lagi


Code:
for (int i=0; i<OrdersTotal(); i++)
{
   OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
   string pairName = OrderSymbol();
   double lotSize = OrderLots();
   double takeProfit = OrderTakeProfit();
   .......
 
oo camtu.. dan kenapa return tu kena ada (total)

}
return (total);
}


total ni mean total oder ke?
 
oo camtu.. dan kenapa return tu kena ada (total)

}
return (total);
}


total ni mean total oder ke?

Code:
int TotalPos (int orderType) [COLOR="Gray"]// integer function[/COLOR]
{
   int [COLOR="blue"]total[/COLOR]; [COLOR="gray"]// int variable[/COLOR]
   ....

   return ([COLOR="blue"]total[/COLOR]); [COLOR="gray"]// mesti return integer[/COLOR]
}

Rules untuk int function mesti ada return(int);
Dalam function TotalPos kat atas, saya declare total sebagai integer dan saya boleh letakkan variable total di dalam return

Tujuan custom function TotalPos() ialah untuk kira jumlah pos.
Contoh penggunaan

TotalPos(OP_BUY) = jumlah pos buy
TotalPos(OP_SELL) = jumlah pos sell
TotalPos(OP_BUYSTOP) = jumlah pos po buy stop
TotalPos(OP_SELLSTOP) = jumlah pos po sell stop
TotalPos(OP_BUYLIMIT) = jumlah pos po buy limit
TotalPos(OP_SELLIMIT) = jumlah pos po sell limit

Dalam EA tu saya nak kira jumlah pos buy, jadi saya buat macam ni

if (TotalPos(OP_BUY)==0) <--- sekiranya pos buy 0
 
bro aiman, tanyer sikit..

macamana yerk nak coding..buat Take Profit macam ni,
(beza post pertama dengan post terakhir)/2

dan semua TP tu di modify jadi sama jer..
dah cuba buat tapi dop jadi ah..

Thanks
 
tuan buat macammna? Boleh tenguk code tuan tu?
 
Code:
int TotalPos (int orderType) [COLOR="Gray"]// integer function[/COLOR]
{
   int [COLOR="blue"]total[/COLOR]; [COLOR="gray"]// int variable[/COLOR]
   ....

   return ([COLOR="blue"]total[/COLOR]); [COLOR="gray"]// mesti return integer[/COLOR]
}


ooo ok paham dah tq.. tak perasan aritu int total
 
salam bro aiman.. katakan saya ada 3 order dan tiga-tiga dah close.. ea boleh identify ke oder mana yg dah close? .
 
salam bro aiman.. katakan saya ada 3 order dan tiga-tiga dah close.. ea boleh identify ke oder mana yg dah close? .

Check kat history tab guba OrderSelect()
OrderSelect boleh di guna untuk select pos yang masih active (Trade tab) dan juga yang dah close (Account History Tab)

Kalau nak check yang masih active

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

untuk yang dah close

OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);

Iterate 1 per 1 pos dalam history tab, kena tahu pos yang macammana nak cari, jenis pos? saiz lot pos tersebut? magic number?
 
OrdersTotal() ni adalah antara keyword terpenting dalam MT4. Dia adalah pembolehubah bagi jumlah open position termasuk pending order. Untuk faham apakah OrdersTotal() ni, cuba create satu script atau indi.

Code:
int start()
{
   Comment("Jumlah position = "+OrdersTotal());
}

Tarik script atau indi ni pada chart akaun yang sedang aktif (ada open position). Anda akan nampak apa itu OrdersTotal(). Akan tertera di kiri atas chart anda.
 

Live Forex Chart

Currency
Rates
EUR / USD
1.14867
USD / JPY
156.682
GBP / USD
1.33940
USD / CHF
0.82211
USD / CAD
1.39924
EUR / JPY
180.031
AUD / USD
0.71261
Back
Top
Log in Register