If you're still running your edge on MT4, the math remains identical, but the routing is passed through the legacy OrderSend syntax.
Code: Select all
//+------------------------------------------------------------------+
//| Pro_Bracket_Execution_MT4.mq4 |
//+------------------------------------------------------------------+
#property strict
extern double RiskPercent = 1.0; // Account Risk per Trade (%)
extern int AtrPeriod = 14; // ATR Length
extern double SlMult = 1.0; // Stop Loss (ATR Multiplier)
extern double TpMult = 2.0; // Take Profit (ATR Multiplier)
void ExecuteBracket(int direction) {
// MT4 simplifies ATR calls natively
double volatility = iATR(_Symbol, 0, AtrPeriod, 1);
double sl_price, tp_price, entry_price;
int cmd;
// Calculate precise structural boundaries
if (direction == OP_BUY) {
entry_price = Ask;
sl_price = entry_price - (volatility * SlMult);
tp_price = entry_price + (volatility * TpMult);
cmd = OP_BUY;
} else {
entry_price = Bid;
sl_price = entry_price + (volatility * SlMult);
tp_price = entry_price - (volatility * TpMult);
cmd = OP_SELL;
}
// Core Position Sizing Math
double tick_value = MarketInfo(_Symbol, MODE_TICKVALUE);
double tick_size = MarketInfo(_Symbol, MODE_TICKSIZE);
double lot_step = MarketInfo(_Symbol, MODE_LOTSTEP);
double risk_money = AccountEquity() * (RiskPercent / 100.0);
double sl_ticks = MathAbs(entry_price - sl_price) / tick_size;
double lot_size = risk_money / (sl_ticks * tick_value);
// Normalize lot size to prevent broker rejection
lot_size = MathFloor(lot_size / lot_step) * lot_step;
// Route to the broker server immediately
int ticket = OrderSend(_Symbol, cmd, lot_size, entry_price, 3, sl_price, tp_price, "Pro_Bracket", 0, 0, clrBlue);
}