-
Notifications
You must be signed in to change notification settings - Fork 57
Description
//+------------------------------------------------------------------+
//| Powerful Scalping EA |
//+------------------------------------------------------------------+
#property strict
input double Lots = 0.1;
input double RiskPercent = 1.0; // % of balance to risk per trade
input int Slippage = 3;
input int MagicNumber = 12345;
// Indicator settings
input int EMA_Period = 50;
input int RSI_Period = 14;
input int MACD_Fast = 12, MACD_Slow = 26, MACD_Signal = 9;
input int BB_Period = 20;
input double BB_Deviation = 2.0;
input int Stoch_K = 5, Stoch_D = 3, Stoch_Slowing = 3;
input int ADX_Period = 14;
input int ATR_Period = 14;
input double ATR_Multiplier_SL = 1.5;
input double ATR_Multiplier_TP = 2.0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Indicator values
double ema = iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_CLOSE,0);
double rsi = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,0);
double macd_main = iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_MAIN,0);
double macd_signal = iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_hist = iMACD(NULL,0,MACD_Fast,MACD_Slow,MACD_Signal,PRICE_CLOSE,MODE_HISTOGRAM,0);
double bb_upper = iBands(NULL,0,BB_Period,BB_Deviation,0,PRICE_CLOSE,MODE_UPPER,0);
double bb_lower = iBands(NULL,0,BB_Period,BB_Deviation,0,PRICE_CLOSE,MODE_LOWER,0);
double stoch_k = iStochastic(NULL,0,Stoch_K,Stoch_D,Stoch_Slowing,MODE_SMA,0,MODE_MAIN,0);
double stoch_d = iStochastic(NULL,0,Stoch_K,Stoch_D,Stoch_Slowing,MODE_SMA,0,MODE_SIGNAL,0);
double adx = iADX(NULL,0,ADX_Period,PRICE_CLOSE,MODE_MAIN,0);
double atr = iATR(NULL,0,ATR_Period,0);
// Position sizing
double accRisk = AccountBalance() * RiskPercent/100.0;
double stopLossPips = ATR_Multiplier_SL * atr / Point;
double lotSize = Lots;
if(stopLossPips > 0 && MarketInfo(Symbol(),MODE_TICKVALUE) > 0)
lotSize = MathMin(Lots, NormalizeDouble(accRisk/(stopLossPips*MarketInfo(Symbol(),MODE_TICKVALUE)),2));
if(lotSize <= 0) lotSize = Lots;
// Only open one trade at a time per symbol and magic number
int totalOrders = 0;
for(int i=0; i<OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
totalOrders++;
}
}
if(totalOrders > 0) return; // Only one trade per symbol
// Entry logic (sample)
if (ema < Close[0] && rsi > 50 && macd_hist > 0 && stoch_k > stoch_d && stoch_k < 30 && adx > 20)
{
double sl = NormalizeDouble(Bid - ATR_Multiplier_SLatr,Digits);
double tp = NormalizeDouble(Bid + ATR_Multiplier_TPatr,Digits);
int ticket = OrderSend(Symbol(),OP_BUY,lotSize,Ask,Slippage,sl,tp,"ScalpBuy",MagicNumber,0,clrBlue);
if(ticket < 0) Print("OrderSend failed with error #",GetLastError());
}
// Sell example (reverse logic)
if (ema > Close[0] && rsi < 50 && macd_hist < 0 && stoch_k < stoch_d && stoch_k > 70 && adx > 20)
{
double sl = NormalizeDouble(Ask + ATR_Multiplier_SLatr,Digits);
double tp = NormalizeDouble(Ask - ATR_Multiplier_TPatr,Digits);
int ticket = OrderSend(Symbol(),OP_SELL,lotSize,Bid,Slippage,sl,tp,"ScalpSell",MagicNumber,0,clrRed);
if(ticket < 0) Print("OrderSend failed with error #",GetLastError());
}
}
//+------------------------------------------------------------------+