-
Notifications
You must be signed in to change notification settings - Fork 57
Description
//+------------------------------------------------------------------+
//| Powerful Multi-Indicator Forex Robot |
//| Integrates MA, RSI, MACD, BB, Stochastic |
//| Author: Copilot for MpenduloMsane |
//+------------------------------------------------------------------+
#property copyright "Copilot"
#property version "1.00"
#property strict
input double Lots = 0.1;
input double RiskPercent = 1.0;
input int Slippage = 5;
input int StopLoss = 200; // in points
input int TakeProfit = 400; // in points
input int MagicNumber = 12345;
// Indicator settings
input int MA_Period = 50;
input int RSI_Period = 14;
input double RSI_BuyLevel = 30;
input double RSI_SellLevel = 70;
input int MACD_Fast = 12;
input int MACD_Slow = 26;
input int MACD_Signal = 9;
input int BB_Period = 20;
input double BB_Deviation = 2.0;
input int Stoch_K = 5;
input int Stoch_D = 3;
input int Stoch_Slowing = 3;
input double Stoch_BuyLevel = 20;
input double Stoch_SellLevel= 80;
//+------------------------------------------------------------------+
//| Calculate risk-based lot size |
//+------------------------------------------------------------------+
double CalculateLotSize(double stoploss)
{
double risk = AccountBalance() * RiskPercent / 100.0;
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double lot = risk / (stoploss * tickValue * 0.1);
lot = MathMax(lot, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN));
lot = MathMin(lot, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX));
return NormalizeDouble(lot, 2);
}
//+------------------------------------------------------------------+
//| Check for Buy Signal |
//+------------------------------------------------------------------+
bool BuySignal()
{
double ma = iMA(_Symbol, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
double rsi = iRSI(_Symbol, 0, RSI_Period, PRICE_CLOSE, 0);
double macd_main, macd_signal, macd_hist;
if(!iMACD(_Symbol, 0, MACD_Fast, MACD_Slow, MACD_Signal, PRICE_CLOSE, macd_main, macd_signal, macd_hist))
return false;
double bb_upper, bb_middle, bb_lower;
iBands(_Symbol, 0, BB_Period, 0, BB_Deviation, PRICE_CLOSE, bb_upper, bb_middle, bb_lower, 0);
double k,d;
iStochastic(_Symbol, 0, Stoch_K, Stoch_D, Stoch_Slowing, MODE_SMA, 0, k, d, 0);
bool cond1 = Close[1] < ma && Close[0] > ma; // Price crosses above MA
bool cond2 = rsi < RSI_BuyLevel;
bool cond3 = macd_hist > 0 && macd_hist > macd_hist[1];
bool cond4 = Close[0] < bb_lower;
bool cond5 = k < Stoch_BuyLevel && d < Stoch_BuyLevel && k > d;
return (cond1 && cond2 && cond3 && cond4 && cond5);
}
//+------------------------------------------------------------------+
//| Check for Sell Signal |
//+------------------------------------------------------------------+
bool SellSignal()
{
double ma = iMA(_Symbol, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, 0);
double rsi = iRSI(_Symbol, 0, RSI_Period, PRICE_CLOSE, 0);
double macd_main, macd_signal, macd_hist;
if(!iMACD(_Symbol, 0, MACD_Fast, MACD_Slow, MACD_Signal, PRICE_CLOSE, macd_main, macd_signal, macd_hist))
return false;
double bb_upper, bb_middle, bb_lower;
iBands(_Symbol, 0, BB_Period, 0, BB_Deviation, PRICE_CLOSE, bb_upper, bb_middle, bb_lower, 0);
double k,d;
iStochastic(_Symbol, 0, Stoch_K, Stoch_D, Stoch_Slowing, MODE_SMA, 0, k, d, 0);
bool cond1 = Close[1] > ma && Close[0] < ma; // Price crosses below MA
bool cond2 = rsi > RSI_SellLevel;
bool cond3 = macd_hist < 0 && macd_hist < macd_hist[1];
bool cond4 = Close[0] > bb_upper;
bool cond5 = k > Stoch_SellLevel && d > Stoch_SellLevel && k < d;
return (cond1 && cond2 && cond3 && cond4 && cond5);
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
Print("Powerful Multi-Indicator EA loaded!");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
Print("EA unloaded.");
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(PositionSelect(_Symbol)) return; // Only one trade at a time
double ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);
if(BuySignal())
{
double lot=CalculateLotSize(StopLoss);
trade.Buy(lot,_Symbol,ask,(ask-StopLoss*_Point),(ask+TakeProfit*_Point),"PowerfulEA Buy",MagicNumber);
}
else if(SellSignal())
{
double lot=CalculateLotSize(StopLoss);
trade.Sell(lot,_Symbol,bid,(bid+StopLoss*_Point),(bid-TakeProfit*_Point),"PowerfulEA Sell",MagicNumber);
}
}
//+------------------------------------------------------------------+