hi, saya pelajar baru membuat expert advisor sendiri, tetapi hadapi masalah masa nak bina expert advisor berkaitan grid.
Sepatutnya:
1) EA ini membuka 4 posisi SAHAJA, TETAPI, setiap tick, EA membuka posisi tak berhenti-henti.
2) Apabila TP terkena (take profit), EA akan membuka posisi baru (dengan nilai sama dengan posisi sebelumnya), TETAPI, EA ini TIDAK membuka apa-apa posisi apabila TP terkena.
Harap kawan boleh memberi bantuan menyelesaikan masalah yang dihadapi di atas.. (kalau boleh, bagi juga full source code yang berjaya).
Terima kasih banyak-banyak.
==================================================================================================
//+------------------------------------------------------------------+
//| Order triggered order EA.mq4 |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "[email protected]"
#property link "http://"
#property show_inputs
extern double Lot = 0.1;
extern int Take_Profit = 10;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SECTION 1:
// (1) When EA activated, 4 orders will be opened ONCE only,
// that is 1 instant OP_BUY, 1 instant OP_SELL, 1 pending OP_BUYLIMIT and 1 pending OP_SELLLIMIT.
// (2) Problem at SECION 1: After EA activated, these 4 orders are opened MANY MANY times (everytime new tick, 4 new orders are opened AGAIN)
// (3) Your opinion : How to write the code in SECTION 1 so that once EA runs, it ONLY opens 4 orders?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, 0, Bid+1*Take_Profit*Point, "Long at 1.3400", 1000, NULL, Lime);
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-1*Take_Profit*Point, 3, 0, Bid, "Long at 1.3390", 1001, NULL, CLR_NONE);
OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, 0, Ask-1*Take_Profit*Point, "Short at 1.3400", 9000, NULL, Red);
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+1*Take_Profit*Point, 3, 0, Ask, "Short at 1.3410", 9001, NULL, CLR_NONE);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SECTION 2:
// (1) At SECTION 2, when ANY ONE of above 4 orders is closed (due to take profit), EA will triggered to:
// (a) RE-OPEN SAME with previous order properties.
// (b) The process at (a) will repeat UNLIMITED times (Hit_TP_&_closed -> Reopen_same_order... Hit_TP_&_closed -> Reopen_same_order...)
// (Example: Say EURUSD market price is at 1.3400, then price move down to 1.3390 and hit the OP_BUYLIMIT.
// After a while, market price retraced to 1.3400, so take profit is achived, so earlier OP_BUYLIMIT is closed now.
// At this moment, EA is triggered to send a NEW same with previous order:
// OP_BUYLIMIT 0.1Lot at order price 1.3390, TP at 1.3400 and magic number 1001 =>same properties with earlier order.
// The EA will repeat the same, as long as TP is hit)
//
// (2) Problem at SECION 2: When one of the order TP is hit, there is NO new same properties order is Re-opened.
// (3) Your opinion : How to write the code in SECTION 2 so that the TP hit can trigger to send a new same properties order?
// That is when market price hit one TP, EA will be triggered to Re-open one new same properties order.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=3;i>=0;i--) // Check the last 3 closed orders in history
{OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderMagicNumber()==1000) //previous OP_BUY order
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-Take_Profit*Point, 3, 0, Bid, "Repeating-Long at 1.3400", 1000, NULL, CLR_NONE);
if (OrderMagicNumber()== 1001) //previous OP_BUYLIMIT order
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-Take_Profit*Point, 3, 0, Bid, "Repeating-Long at 1.3390", 1001, NULL, CLR_NONE);
if(OrderMagicNumber()==9000) //previous OP_SELL order
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+Take_Profit*Point, 3, 0, Ask, "Repeating-Short at 1.3400", 9000, NULL, CLR_NONE);
if (OrderMagicNumber()== 9001) //previous OP_SELLLIMIT order
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+Take_Profit*Point, 3, 0, Ask, "Repeating-Short at 1.3410", 9001, NULL, CLR_NONE);
return(0);
}}
//+------------------------------------------------------------------+
Sepatutnya:
1) EA ini membuka 4 posisi SAHAJA, TETAPI, setiap tick, EA membuka posisi tak berhenti-henti.
2) Apabila TP terkena (take profit), EA akan membuka posisi baru (dengan nilai sama dengan posisi sebelumnya), TETAPI, EA ini TIDAK membuka apa-apa posisi apabila TP terkena.
Harap kawan boleh memberi bantuan menyelesaikan masalah yang dihadapi di atas.. (kalau boleh, bagi juga full source code yang berjaya).
Terima kasih banyak-banyak.
==================================================================================================
//+------------------------------------------------------------------+
//| Order triggered order EA.mq4 |
//| [email protected] |
//+------------------------------------------------------------------+
#property copyright "[email protected]"
#property link "http://"
#property show_inputs
extern double Lot = 0.1;
extern int Take_Profit = 10;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SECTION 1:
// (1) When EA activated, 4 orders will be opened ONCE only,
// that is 1 instant OP_BUY, 1 instant OP_SELL, 1 pending OP_BUYLIMIT and 1 pending OP_SELLLIMIT.
// (2) Problem at SECION 1: After EA activated, these 4 orders are opened MANY MANY times (everytime new tick, 4 new orders are opened AGAIN)
// (3) Your opinion : How to write the code in SECTION 1 so that once EA runs, it ONLY opens 4 orders?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, 0, Bid+1*Take_Profit*Point, "Long at 1.3400", 1000, NULL, Lime);
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-1*Take_Profit*Point, 3, 0, Bid, "Long at 1.3390", 1001, NULL, CLR_NONE);
OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, 0, Ask-1*Take_Profit*Point, "Short at 1.3400", 9000, NULL, Red);
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+1*Take_Profit*Point, 3, 0, Ask, "Short at 1.3410", 9001, NULL, CLR_NONE);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SECTION 2:
// (1) At SECTION 2, when ANY ONE of above 4 orders is closed (due to take profit), EA will triggered to:
// (a) RE-OPEN SAME with previous order properties.
// (b) The process at (a) will repeat UNLIMITED times (Hit_TP_&_closed -> Reopen_same_order... Hit_TP_&_closed -> Reopen_same_order...)
// (Example: Say EURUSD market price is at 1.3400, then price move down to 1.3390 and hit the OP_BUYLIMIT.
// After a while, market price retraced to 1.3400, so take profit is achived, so earlier OP_BUYLIMIT is closed now.
// At this moment, EA is triggered to send a NEW same with previous order:
// OP_BUYLIMIT 0.1Lot at order price 1.3390, TP at 1.3400 and magic number 1001 =>same properties with earlier order.
// The EA will repeat the same, as long as TP is hit)
//
// (2) Problem at SECION 2: When one of the order TP is hit, there is NO new same properties order is Re-opened.
// (3) Your opinion : How to write the code in SECTION 2 so that the TP hit can trigger to send a new same properties order?
// That is when market price hit one TP, EA will be triggered to Re-open one new same properties order.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for(int i=3;i>=0;i--) // Check the last 3 closed orders in history
{OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderMagicNumber()==1000) //previous OP_BUY order
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-Take_Profit*Point, 3, 0, Bid, "Repeating-Long at 1.3400", 1000, NULL, CLR_NONE);
if (OrderMagicNumber()== 1001) //previous OP_BUYLIMIT order
OrderSend(Symbol(), OP_BUYLIMIT, Lot, Ask-Take_Profit*Point, 3, 0, Bid, "Repeating-Long at 1.3390", 1001, NULL, CLR_NONE);
if(OrderMagicNumber()==9000) //previous OP_SELL order
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+Take_Profit*Point, 3, 0, Ask, "Repeating-Short at 1.3400", 9000, NULL, CLR_NONE);
if (OrderMagicNumber()== 9001) //previous OP_SELLLIMIT order
OrderSend(Symbol(), OP_SELLLIMIT, Lot, Bid+Take_Profit*Point, 3, 0, Ask, "Repeating-Short at 1.3410", 9001, NULL, CLR_NONE);
return(0);
}}
//+------------------------------------------------------------------+
Last edited:
