BTC USD 76,485.3 Gold USD 4,341.83
Time now: Jun 1, 12:00 AM

Belajar Coding EA (mql) asas

contoh sekiranya saya target 10% gain from balance

code saya lebih kurang macam ni

Code:

if (AccountEquity() >= AccountBalance() * 1.1)
{
//-- function close all di sini
}

target macam ne tu?guna 10% margin ke?



if (AccountEquity() >= AccountBalance() * 0.1)

nak mudah gunakan OrderProfit();

int Profit;
for (int ix2=0;ix2<=OrdersTotal(); ix2++){
if (OrderSelect(ix2, SELECT_BY_POS)==true) {
if(OrderSymbol()==Symbol()){
if(OrderType()==OP_BUY){
LastBuyPrice = OrderOpenPrice();
Profit+=(OrderProfit()+OrderSwap()+OrderCommission());

}
if(OrderType()==OP_SELL){
LastSellPrice = OrderOpenPrice();
Profit+=(OrderProfit()+OrderSwap()+OrderCommission());

}
}
}
}

if(Profit>=AccountBalance()*0.1){
for (int ix2a=OrdersTotal();ix2a>=0; ix2a--){
if (OrderSelect(ix2a, SELECT_BY_POS)==true) {
if (OrderSymbol()==Symbol()) {
if(OrderType()==OP_BUY){OrderClose(OrderTicket(),OrderLots(),Bid,5,Blue);}
if(OrderType()==OP_SELL){OrderClose(OrderTicket(),OrderLots(),Ask,5,Red);}
if (OrderType()==OP_BUYLIMIT){OrderDelete(OrderTicket(),CLR_NONE);}
if( OrderType()==OP_SELLLIMIT){OrderDelete(OrderTicket(),CLR_NONE);}
if( OrderType()==OP_BUYSTOP){OrderDelete(OrderTicket(),CLR_NONE);}
if( OrderType()==OP_SELLSTOP){OrderDelete(OrderTicket(),CLR_NONE);}
Comment("Force to Close All Posts......");
}
}
}
}
}

Harap Membantu
 
Last edited:
Maksud code tu;

Sebagai contoh, Balance ada $100
sekiranya Equity meningkat ke $110 atau lebih
EA akan execute close all function

logic tu bro boleh create sendiri, yang itu hanya contoh bagaimana nak guna conditional logic untuk execute command.

Kalau terus letak close all command takpa guna if, EA akan terus menerus close all. Bila open pos aje, EA akan close balik pos tersebut. Sebab bro tak letak rule bila EA sepatutnya close all.

sangat jelas penerangan bro aiman :)

terima kasih bro

tumpang belajar :)cgrock
 
sangat jelas penerangan bro aiman :)

terima kasih bro

tumpang belajar :)cgrock

Yang penting kita sendiri kena faham macammana nak guna keyword if itu sendiri, masta tempe dah terang sangat detail macammana nak guna if. :">
 
Yang penting kita sendiri kena faham macammana nak guna keyword if itu sendiri, masta tempe dah terang sangat detail macammana nak guna if. :">

tempe cuma bagi nasik tambah aje...
 
Code:
//+------------------------------------------------------------------+
//|                                                     myCandle.mq4 |
//|                                          Copyright © 2011, Aiman |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Aiman"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DarkViolet
#property indicator_color2 DarkSlateBlue
#property indicator_color3 DarkViolet
#property indicator_color4 DarkSlateBlue

double low[],high[],open[],close[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexBuffer(0, low);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 2);
   SetIndexBuffer(1, high);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexBuffer(2, open);
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexBuffer(3, close);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int newBar=Bars-counted_bars;  
   
   double O,C,H,L;
//----
   for (int i=newBar; i>-1; i--) 
   {
      O = iOpen(0,0,i);
      C = iClose(0,0,i);
      H = iHigh(0,0,i);
      L = iLow(0,0,i);
      
      //--- hammer pattern
      if(((H-L)>3*(O-C))&&((C-L)/(0.001+H-L)>0.6)&&((O-L)/(0.001+H-L)>0.6))
      {
         open[i] = O;
         close[i] = C;
         high[i] = H;
         low[i] = L;
         
         if (O>C)
         {
            high[i] = L;
            low[i] = H;
         }         
      }
      //--- 
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

tq sifu. tambahan data utk ngetest. nak tambah beberapa setup lagi, tengok jd camner :D
 
kalau guna indicator buffer ni ada limit, tak boleh lebih 8 buffers.
Kalau bro nak set banyak2 kaler kat candle tu mungkin tak boleh sebab tak cukup buffer. Saya tak tau kalau ada cara lain boleh buat macam tu. Mungkin ada forumer lain yang tau :-?

Saya rasa kalau bro letak je arrow kat atas atau bawah candle lebih senang tenguk indi tu. Contoh macam kat indi onaji san.

Just my 1 pip.
 
Salam menyambut ramadhan...

masta...nk tnye ckit..

Katakan sya ingin membuat EA yg berkonsep Stochastic sebagai rule untuk OP..

S1M=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_MAIN,0);
S1S=iStochastic(NULL,PERIOD_M5,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);

S2M=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_MAIN,0);
S2S=iStochastic(NULL,PERIOD_M30,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);

S3M=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_MAIN,0);
S3S=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);

S4M=iStochastic(NULL,PERIOD_W1,14,3,3,MODE_SMA,0,MODE_MAIN,0);
S4S=iStochastic(NULL,PERIOD_W1,14,3,3,MODE_SMA,0,MODE_SIGNAL,0);


Kemudian ingin menambah kepastian dengan Pivot..

Adakah cara ini boleh digunakan?

int week = 1;

double lastweek_high = iHigh(NULL,PERIOD_W1,week);
double lastweek_low = iLow(NULL,PERIOD_W1,week);
double lastweek_close = iClose(NULL,PERIOD_W1,week);

double R = lastweek_high - lastweek_low; //range
double p = (lastweek_high + lastweek_low + lastweek_close)/3; // Standard Pivot

double r5 = p + (R * 1.618);
double r4 = p + (R * 1.382);
double r3 = p + (R * 1.000);
double r2 = p + (R * 0.618);
double r1 = p + (R * 0.382);

double s1 = p - (R * 0.382);
double s2 = p - (R * 0.618);
double s3 = p - (R * 1.000);
double s4 = p - (R * 1.382);
double s5 = p - (R * 1.618);

if (ScanOpenTrades() == 0) Status = "READY";

Signal="NONE";
if(S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && s5
|| S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && s4
|| S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && s3
|| S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && s2
|| S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S && s1)
{
Signal="LONG";
}
if(S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && r1
|| S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && r2
|| S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && r3
|| S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && r4
|| S1M<S1S && S2M<S2S && S3M<S3S && S4M<S4S && r5)

{
Signal="SHORT";
}

Harap2 masta2 dan tuan2 skalian dapat bantu...nk tambah kepastian dengan pivot.

ps: Pivot sye ni konsep fibo pivot untuk weekly..
 
ea boleh buat berdasarkan semua indi ke ? cth rsi, ma, bb
 
EA boleh baca standard indi mahupun custom indi.

Untuk code vasta vista kalau saya nak signal bila candle cross ke atas line support. Saya akan buat begini
Code:
if(S1M>S1S && S2M>S2S && S3M>S3S && S4M>S4S) [COLOR="DimGray"]//-- semua indi stoch bersilang ke atas[/COLOR]
{
	if (iOpen(0,0,0)<s5 && Bid>=s5 || [COLOR="DimGray"]//-- candle cross s5 ataupun[/COLOR]
	    iOpen(0,0,0)<s4 && Bid>=s4 || [COLOR="DimGray"]//-- candle cross s4 ataupun[/COLOR]
	    iOpen(0,0,0)<s3 && Bid>=s3 || [COLOR="DimGray"]//-- candle cross s3 ataupun[/COLOR]
	    iOpen(0,0,0)<s2 && Bid>=s2 || [COLOR="DimGray"]//-- candle cross s2 ataupun[/COLOR]
	    iOpen(0,0,0)<s1 && Bid>=s1)   [COLOR="DimGray"]//-- candle cross s1[/COLOR]
	Signal="LONG";
}

Makna nya open candle kat bawah support line dan close candle ataupun current bid price kat atas support line.

EA bro baca multi TF, kalau guna strategy tester memang tak accurate sebab strategy tester hanya boleh baca current TF
 

Live Forex Chart

Currency
Rates
EUR / USD
1.14761
USD / JPY
155.974
GBP / USD
1.33558
USD / CHF
0.82459
USD / CAD
1.39911
EUR / JPY
178.997
AUD / USD
0.71092
Back
Top
Log in Register