BTC USD 80,882.6 Gold USD 4,382.83
Time now: Jun 1, 12:00 AM

Belajar Coding EA (mql) asas

pertama sye tk leh nk wt syarat berdasarkan magic number yg berbeza untuk buy..

jadi sye fkir membezakan lot lagi mudah kot...(rupanye tk mudah gk)hehe


ps: Hanya satu amaun lot (0.20) untuk satu masa...

kalau pakai lotsize, bila start lotsize berubah (maklum lah bila dah banyak masyuk), code nak kena ubah... Pakai magic number lagi mudah... Kalau tak pun, boleh compare dengan OrderOpenPrice.

Code:
   for(i=0; i<OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol())
      {
         if(OrderType()==OP_BUY)
         {
            if(Bid > r1 && Bid < r2 && OrderOpenPrice() > r1 && OrderOpenPrice() < r2)
            {
               SIGNAL = "DON'T SHORT";
            }
         }
      }   
   }

Kalau pakai magicnumber pun lebih kurang sama...

Code:
   for(i=0; i<OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==Symbol())
      {
         if(OrderType()==OP_BUY)
         {
            if(Bid > r1 && Bid < r2 && OrderMagicNumber()==100)
            {
               SIGNAL = "DON'T SHORT";
            }
         }
      }   
   }
 
Last edited:
berapa rege ipad2 kat sana sekarang ni?

kalau beli gitu je paling murah S$668,
kalau beli dengan contract 3G, kalau tak silap lebih kurang $S300-400
 
pertama sye tk leh nk wt syarat berdasarkan magic number yg berbeza untuk buy..

jadi sye fkir membezakan lot lagi mudah kot...(rupanye tk mudah gk)hehe


ps: Hanya satu amaun lot (0.20) untuk satu masa...

Scan lot atau magic number lebih kurang sama.
Tapi saya tak prefer scan lot sebab lot tu sepatutnya boleh berubah-ubah, kalau dah hard-coded, tak boleh ubah lagi lah.
 
ataupun kalau masih nak guna scan lot mungkin boleh buat macam ni

Code:
bool LotPost (int orderType, double volume)
{
   for(int i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderType()==orderType)
      {
         if (OrderLots()==volume) return(true);
      }
   }
   return(false);
}

Code:
if (!LotPost (OP_BUY, [COLOR="Red"]0.1[/COLOR]) && <lain2 filter>) OrderSend(....OP_BUY...[COLOR="red"]0.1[/COLOR]...
if (!LotPost (OP_BUY, [COLOR="red"]0.2[/COLOR]) && <lain2 filter>) OrderSend(....OP_BUY...[COLOR="red"]0.2[/COLOR]...
if (!LotPost (OP_SELL, [COLOR="red"]0.1[/COLOR]) && <lain2 filter>) OrderSend(....OP_SELL...[COLOR="red"]0.1[/COLOR]...
if (!LotPost (OP_SELL, [COLOR="red"]0.2[/COLOR]) && <lain2 filter>) OrderSend(....OP_SELL...[COLOR="red"]0.2[/COLOR]...

warna merah atas tu semua boleh jadi variable lah.
 
bro...tk leh gk..

Code:
   if(Status=="READY" && Signal=="LONG" && !LotPost(OP_BUY))
   {
      ticket=OrderSend(Symbol(),OP_BUY,LotSize(),Ask,slippage,Ask-SL*Point,Ask+TP*Point,LongComment,Magic(),0,Blue);
      if(ticket>-1)
      {
         Status="LONG ACTIVE";
      }
   }
   
   if(Status=="READY" && Signal=="SHORT" && !LotPost(OP_SELL))
   {
      ticket=OrderSend(Symbol(),OP_SELL,LotSize(),Bid,slippage,Bid+SL*Point,Bid-TP*Point,ShortComment,Magic(),0,Red);
      if(ticket>-1)
      {
         Status="SHORT ACTIVE";
      }
   }




ni fungsi dia:

Code:
bool LotPost (int orderType)
{

   for(int i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     
     if (OrderSymbol()!=Symbol()) continue;
      if (orderType==OP_BUY && OrderMagicNumber()==200 || OrderMagicNumber()==300 || OrderMagicNumber()==400 || OrderMagicNumber()==500)   return(true); 
      if (orderType==OP_SELL && OrderMagicNumber()==200 || OrderMagicNumber()==300 || OrderMagicNumber()==400 || OrderMagicNumber()==500)  return(true); 
   }
   return(false);
}
 
Bro punya code tak check sama ada post buy atau sell sebab takde OrderType() untuk compare dengan orderType
Cuba compare dengan code bawah ni

bro...tk leh gk..

Code:
bool LotPost (int orderType)
{

   for(int i = 0; i < OrdersTotal(); i++)
   {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
     
      if (OrderSymbol()!=Symbol() || OrderType()!=orderType) continue;
      if (OrderMagicNumber()==200 || OrderMagicNumber()==300 || OrderMagicNumber()==400 || OrderMagicNumber()==500)   return(true); 
   }
   return(false);
}
 
ada tak cth simple ea yg bukan byk post..kata biasa kita bukak 1lot, sekarang ni nak guna 0.2lotx5 serentak...
kalau masta ada contoh coding..mintak tempek kat sini...tq
 

Live Forex Chart

Currency
Rates
EUR / USD
1.14807
USD / JPY
156.795
GBP / USD
1.33897
USD / CHF
0.82278
USD / CAD
1.40007
EUR / JPY
179.878
AUD / USD
0.71244
Back
Top
Log in Register