All_Rounder_Indicator
All_Rounder_Indicator
//| 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);
return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
//| Buy/Sell Signal Calculation (Same as Pine Script) |
//+------------------------------------------------------------------+
void CalculateSignals()
{
int bars = iBars(Symbol(), 0);
if (bars < 50) return;
//+------------------------------------------------------------------+
//| Draw Buy/Sell Arrows on Chart |
//+------------------------------------------------------------------+
void DrawSignals()
{
ObjectsDeleteAll();
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 (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;
if (BuySignalBuffer[0] != EMPTY_VALUE)
{
price = Ask;
sl = price - (StopLoss * Point);
tp = price + (TakeProfit * Point);
if (SellSignalBuffer[0] != EMPTY_VALUE)
{
price = Bid;
sl = price + (StopLoss * Point);
tp = price - (TakeProfit * Point);
//+------------------------------------------------------------------+
//| Main Execution Function (OnTick) |
//+------------------------------------------------------------------+
void OnTick()
{
CalculateSignals();
DrawSignals();
GenerateAlerts();
if (AutoTrading)
{
ExecuteTrades();
}
}