//+------------------------------------------------------------------+
//| Indicator Name: All Rounder Indicator (Converted from Pine Script) |
//| Author: Custom Conversion for MT4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// Input Parameters
input int emaPeriod = 50; // EMA Period
input int rsiPeriod = 14; // RSI Period
input int macdFast = 12; // MACD Fast Length
input int macdSlow = 26; // MACD Slow Length
input int macdSignal = 9; // MACD Signal Length
input int atrPeriod = 14; // ATR Period
input double LotSize = 0.01; // Lot Size
input int TakeProfit = 50; // TP in pips
input int StopLoss = 50; // SL in pips
input bool AutoTrading = true; // Enable/Disable Auto Trading
// Indicator Buffers
double BuySignalBuffer[];
double SellSignalBuffer[];
// Indicator Handles
int EMAHandle, RSIHandle, MACDMainHandle, MACDSignalHandle, ATRHandle;
//+------------------------------------------------------------------+
//| Initialization Function (OnInit) |
//+------------------------------------------------------------------+
int OnInit()
{
// Bind Buffers
SetIndexBuffer(0, BuySignalBuffer);
SetIndexBuffer(1, SellSignalBuffer);
// Indicator Handles
EMAHandle = iMA(Symbol(), 0, emaPeriod, 0, MODE_EMA, PRICE_CLOSE);
RSIHandle = iRSI(Symbol(), 0, rsiPeriod, PRICE_CLOSE);
MACDMainHandle = iMACD(Symbol(), 0, macdFast, macdSlow, macdSignal, PRICE_CLOSE,
MODE_MAIN);
MACDSignalHandle = iMACD(Symbol(), 0, macdFast, macdSlow, macdSignal,
PRICE_CLOSE, MODE_SIGNAL);
ATRHandle = iATR(Symbol(), 0, atrPeriod);
if (EMAHandle == INVALID_HANDLE || RSIHandle == INVALID_HANDLE || MACDMainHandle
== INVALID_HANDLE || ATRHandle == INVALID_HANDLE)
{
Print("Error initializing indicators!");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Buy/Sell Signal Calculation (Same as Pine Script) |
//+------------------------------------------------------------------+
void CalculateSignals()
{
int bars = iBars(Symbol(), 0);
if (bars < 50) return;
for (int i = 0; i < Bars; i++)
{
double EMAValue = iMA(Symbol(), 0, emaPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
double RSIValue = iRSI(Symbol(), 0, rsiPeriod, PRICE_CLOSE, i);
double MACDMain = iMACD(Symbol(), 0, macdFast, macdSlow, macdSignal,
PRICE_CLOSE, MODE_MAIN, i);
double MACDSignal = iMACD(Symbol(), 0, macdFast, macdSlow, macdSignal,
PRICE_CLOSE, MODE_SIGNAL, i);
// Define Buy Condition (Same as Pine Script)
bool BuySignal = (Close[i] > EMAValue) && (RSIValue > 50) && (MACDMain >
MACDSignal);
// Define Sell Condition (Same as Pine Script)
bool SellSignal = (Close[i] < EMAValue) && (RSIValue < 50) && (MACDMain <
MACDSignal);
// Store Signals in Buffers
BuySignalBuffer[i] = BuySignal ? Close[i] : EMPTY_VALUE;
SellSignalBuffer[i] = SellSignal ? Close[i] : EMPTY_VALUE;
}
}
//+------------------------------------------------------------------+
//| Draw Buy/Sell Arrows on Chart |
//+------------------------------------------------------------------+
void DrawSignals()
{
ObjectsDeleteAll();
for (int i = 0; i < Bars; i++)
{
if (BuySignalBuffer[i] != EMPTY_VALUE)
{
ObjectCreate(0, "BuyArrow_" + IntegerToString(i), OBJ_ARROW, 0,
Time[i], BuySignalBuffer[i]);
ObjectSetInteger(0, "BuyArrow_" + IntegerToString(i),
OBJPROP_ARROWCODE, 233);
ObjectSetInteger(0, "BuyArrow_" + IntegerToString(i), OBJPROP_COLOR,
clrBlue);
}
if (SellSignalBuffer[i] != EMPTY_VALUE)
{
ObjectCreate(0, "SellArrow_" + IntegerToString(i), OBJ_ARROW, 0,
Time[i], SellSignalBuffer[i]);
ObjectSetInteger(0, "SellArrow_" + IntegerToString(i),
OBJPROP_ARROWCODE, 234);
ObjectSetInteger(0, "SellArrow_" + IntegerToString(i), OBJPROP_COLOR,
clrRed);
}
}
}
//+------------------------------------------------------------------+
//| Generate Alerts for Buy/Sell Signals |
//+------------------------------------------------------------------+
void GenerateAlerts()
{
static datetime lastAlertTime = 0;
if (TimeCurrent() - lastAlertTime < 10)
return;
if (BuySignalBuffer[0] != EMPTY_VALUE)
{
Alert("📈 Buy Signal on ", Symbol(), " at ", DoubleToString(Close[0], 5));
lastAlertTime = TimeCurrent();
}
if (SellSignalBuffer[0] != EMPTY_VALUE)
{
Alert("📉 Sell Signal on ", Symbol(), " at ", DoubleToString(Close[0], 5));
lastAlertTime = TimeCurrent();
}
}
//+------------------------------------------------------------------+
//| Execute Trades Based on Buy/Sell Signals |
//+------------------------------------------------------------------+
void ExecuteTrades()
{
if (OrdersTotal() > 0) return;
double price, sl, tp;
if (BuySignalBuffer[0] != EMPTY_VALUE)
{
price = Ask;
sl = price - (StopLoss * Point);
tp = price + (TakeProfit * Point);
int buyTicket = OrderSend(Symbol(), OP_BUY, LotSize, price, 3, sl, tp, "All
Rounder Indicator", 0, 0, clrBlue);
if (buyTicket > 0) Print("✅ Buy Order Placed at ", price);
else Print("❌ Buy Order Failed! Error: ", GetLastError());
}
if (SellSignalBuffer[0] != EMPTY_VALUE)
{
price = Bid;
sl = price + (StopLoss * Point);
tp = price - (TakeProfit * Point);
int sellTicket = OrderSend(Symbol(), OP_SELL, LotSize, price, 3, sl, tp,
"All Rounder Indicator", 0, 0, clrRed);
if (sellTicket > 0) Print("✅ Sell Order Placed at ", price);
else Print("❌ Sell Order Failed! Error: ", GetLastError());
}
}
//+------------------------------------------------------------------+
//| Main Execution Function (OnTick) |
//+------------------------------------------------------------------+
void OnTick()
{
CalculateSignals();
DrawSignals();
GenerateAlerts();
if (AutoTrading)
{
ExecuteTrades();
}
}