แจกฟรี EA MT4 EU-M5-MAR-Grid-12APR2025
EA ตัวใหม่ MT4 เทรด EU กรอบเวลา 5 นาที (RAW หรือ Zero)
1,000 USD เปิด 0.01 Lot
เปิดบัญชี RAW หรือ Zero ค่า Spread 0 pips ได้ที่ https://exness.com/intl/th/a/73208
ลูกค้าขอทดลอง EA แจ้ง ID ที่สมัครผ่านลิงค์ผม เดี่ยวผมให้ EA ทดลองใช้ฟรี
แก้ไข code GridStep = 40; ในกรอบเวลา H1
//+------------------------------------------------------------------+
//| Martingale + Grid Strategy for EUR/USD M5 |
//| Author: ChatGPT |
//+------------------------------------------------------------------+
#property strict
extern double InitialLot = 0.01;
extern int GridStep = 10; // Grid step in pips
extern int MaxTrades = 7;
extern double TakeProfit = 5.0; // Basket TP in USD
extern double MaxLoss = -30.0; // Basket SL in USD
extern double ADXFilter = 25.0; // ADX threshold
extern int MagicNumber = 12345;
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnTick()
{
if(!IsNewCandle()) return;
double adx = iADX(NULL, 0, 14, PRICE_CLOSE, MODE_MAIN, 0);
if (adx > ADXFilter) return; // Skip trending markets
if (CountTrades() == 0)
{
double rsi = iRSI(NULL, 0, 14, PRICE_CLOSE, 0);
double bbUpper = iBands(NULL, 0, 20, 2.0, 0, PRICE_CLOSE, MODE_UPPER, 1);
double bbLower = iBands(NULL, 0, 20, 2.0, 0, PRICE_CLOSE, MODE_LOWER, 1);
double close = iClose(NULL, 0, 1);
double prevClose = iClose(NULL, 0, 2);
if (rsi < 30 || (close < bbLower && prevClose > bbLower))
OpenOrder(OP_BUY);
else if (rsi > 70 || (close > bbUpper && prevClose < bbUpper))
OpenOrder(OP_SELL);
}
else
{
ManageGrid();
CheckBasket();
}
}
//+------------------------------------------------------------------+
bool IsNewCandle()
{
static datetime lastTime = 0;
if (Time
{
lastTime = Time
return true;
}
return false;
}
//+------------------------------------------------------------------+
void OpenOrder(int type)
{
double lot = InitialLot;
double price = (type == OP_BUY) ? Ask : Bid;
int slippage = 3;
OrderSend(Symbol(), type, lot, price, slippage, 0, 0, "Grid Start", MagicNumber, 0, clrBlue);
}
//+------------------------------------------------------------------+
int CountTrades()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
count++;
}
return count;
}
//+------------------------------------------------------------------+
void ManageGrid()
{
int direction = -1;
double lastPrice = 0;
int tradeCount = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol()) continue;
tradeCount++;
direction = OrderType();
if(OrderOpenTime() > lastPrice) lastPrice = OrderOpenPrice();
}
}
if(tradeCount >= MaxTrades) return;
double gap = GridStep * Point * 10;
double price = (direction == OP_BUY) ? Ask : Bid;
double diff = MathAbs(price - lastPrice);
if(diff >= gap)
{
double lot = InitialLot * MathPow(2, tradeCount);
OpenOrder(direction);
}
}
//+------------------------------------------------------------------+
void CheckBasket()
{
double profit = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
profit += OrderProfit() + OrderSwap() + OrderCommission();
}
if(profit >= TakeProfit || profit <= MaxLoss)
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
if(OrderMagicNumber() == MagicNumber && OrderSymbol() == Symbol())
OrderClose(OrderTicket(), OrderLots(), Bid, 3, clrRed);
}
}
}