generated from Atoiyaa/mt5-manager
111 lines
No EOL
2.8 KiB
MQL5
111 lines
No EOL
2.8 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Lucid Gold Sniper EA |
|
|
//| Educational Example for MT5 |
|
|
//+------------------------------------------------------------------+
|
|
#property strict
|
|
|
|
input double LotSize = 0.01;
|
|
input int FastEMA = 9;
|
|
input int SlowEMA = 21;
|
|
input int RSI_Period = 14;
|
|
input double BuyRSI = 55;
|
|
input double SellRSI = 45;
|
|
input int StopLossPoints = 300;
|
|
input int TakeProfitPoints = 600;
|
|
|
|
int fastEMAHandle;
|
|
int slowEMAHandle;
|
|
int rsiHandle;
|
|
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
fastEMAHandle = iMA(_Symbol, PERIOD_CURRENT, FastEMA, 0, MODE_EMA, PRICE_CLOSE);
|
|
slowEMAHandle = iMA(_Symbol, PERIOD_CURRENT, SlowEMA, 0, MODE_EMA, PRICE_CLOSE);
|
|
rsiHandle = iRSI(_Symbol, PERIOD_CURRENT, RSI_Period, PRICE_CLOSE);
|
|
|
|
if(fastEMAHandle == INVALID_HANDLE ||
|
|
slowEMAHandle == INVALID_HANDLE ||
|
|
rsiHandle == INVALID_HANDLE)
|
|
{
|
|
return(INIT_FAILED);
|
|
}
|
|
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
void OnTick()
|
|
{
|
|
if(PositionsTotal() > 0)
|
|
return;
|
|
|
|
double fastEMA[2];
|
|
double slowEMA[2];
|
|
double rsi[1];
|
|
|
|
CopyBuffer(fastEMAHandle,0,0,2,fastEMA);
|
|
CopyBuffer(slowEMAHandle,0,0,2,slowEMA);
|
|
CopyBuffer(rsiHandle,0,0,1,rsi);
|
|
|
|
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
|
|
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
|
|
|
|
// BUY
|
|
if(fastEMA[0] > slowEMA[0] &&
|
|
fastEMA[1] <= slowEMA[1] &&
|
|
rsi[0] > BuyRSI)
|
|
{
|
|
OpenBuy(ask);
|
|
}
|
|
|
|
// SELL
|
|
if(fastEMA[0] < slowEMA[0] &&
|
|
fastEMA[1] >= slowEMA[1] &&
|
|
rsi[0] < SellRSI)
|
|
{
|
|
OpenSell(bid);
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
void OpenBuy(double price)
|
|
{
|
|
MqlTradeRequest request;
|
|
MqlTradeResult result;
|
|
|
|
ZeroMemory(request);
|
|
|
|
request.action = TRADE_ACTION_DEAL;
|
|
request.symbol = _Symbol;
|
|
request.volume = LotSize;
|
|
request.type = ORDER_TYPE_BUY;
|
|
request.price = price;
|
|
request.sl = price - StopLossPoints * _Point;
|
|
request.tp = price + TakeProfitPoints * _Point;
|
|
request.deviation = 10;
|
|
request.magic = 20260605;
|
|
|
|
OrderSend(request,result);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
void OpenSell(double price)
|
|
{
|
|
MqlTradeRequest request;
|
|
MqlTradeResult result;
|
|
|
|
ZeroMemory(request);
|
|
|
|
request.action = TRADE_ACTION_DEAL;
|
|
request.symbol = _Symbol;
|
|
request.volume = LotSize;
|
|
request.type = ORDER_TYPE_SELL;
|
|
request.price = price;
|
|
request.sl = price + StopLossPoints * _Point;
|
|
request.tp = price - TakeProfitPoints * _Point;
|
|
request.deviation = 10;
|
|
request.magic = 20260605;
|
|
|
|
OrderSend(request,result);
|
|
} |