US30 Scalping EA MT5: Dow Jones Expert Advisor with MQL5 Code
A MQL5 morning breakout scalping EA for US30 (Dow Jones) on MetaTrader 5. Uses the NY open breakout pattern with ATR-based stops and a Fed announcement filter.
Historical test results
Past performance is not indicative of future results. Backtest statistics are based on historical data and do not guarantee future profits. Trading involves significant risk of loss. This content is for educational purposes only and does not constitute financial advice.
Strategy logic
Entry conditions
At 09:31 NY time, measure the high and low of the first 30-minute candle (09:00–09:30). Enter long if price breaks above the range high + 10 points, short if price breaks below range low − 10 points. ATR must be above 150 points minimum to confirm sufficient volatility.
Exit conditions
Take profit at 1x the opening range size from entry. Stop loss at 0.5x opening range size. Trail stop by 50% of profit once TP50% is reached. All positions close by 11:00 NY time.
MQL5 Expert Advisor Code
//+------------------------------------------------------------------+
//| US30 Morning Breakout EA |
//| Pineify.app |
//+------------------------------------------------------------------+
#property copyright "Pineify.app"
#property version "1.00"
input int MagicNumber = 678901;
input double Lots = 0.01;
input int RangeStartH = 9; // Range start hour (NY)
input int RangeEndH = 9; // Range end hour (NY)
input int RangeEndM = 30; // Range end minute
input int TradeStartM = 31; // Entry allowed after this minute
input int CloseHour = 11; // Close all at this hour
input int BreakoutBuffer= 10; // Extra points beyond range
input double MinATR = 150; // Minimum ATR to trade
double rangeHigh = 0, rangeLow = 0;
bool rangeSet = false, traded = false;
datetime lastDay = 0;
int atrH;
double atrBuf[];
int OnInit() {
atrH = iATR(_Symbol, PERIOD_M5, 14);
ArraySetAsSeries(atrBuf, true);
return INIT_SUCCEEDED;
}
void OnDeinit(const int reason) { IndicatorRelease(atrH); }
void OnTick() {
MqlTick tick;
if (!SymbolInfoTick(_Symbol, tick)) return;
MqlDateTime dt; TimeToStruct(tick.time, dt);
// Reset daily state
datetime today = StringToTime(TimeToString(tick.time, TIME_DATE));
if (today != lastDay) {
rangeHigh=0; rangeLow=0; rangeSet=false; traded=false; lastDay=today;
}
// Close all at CloseHour
if (dt.hour >= CloseHour) { CloseAll(); return; }
// Build range during first 30 minutes
if (dt.hour == RangeStartH && dt.min < RangeEndM) {
if (rangeHigh == 0 || tick.ask > rangeHigh) rangeHigh = tick.ask;
if (rangeLow == 0 || tick.bid < rangeLow) rangeLow = tick.bid;
return;
}
// Mark range complete
if (!rangeSet && dt.hour == RangeEndH && dt.min >= RangeEndM) rangeSet = true;
if (!rangeSet || traded) return;
CopyBuffer(atrH, 0, 0, 3, atrBuf);
if (atrBuf[1] < MinATR * _Point) return;
double ask = tick.ask, bid = tick.bid;
if (ask > rangeHigh + BreakoutBuffer * _Point) {
double range = rangeHigh - rangeLow;
OpenTrade(ORDER_TYPE_BUY, Lots, range * 0.5, range * 1.0, MagicNumber);
traded = true;
} else if (bid < rangeLow - BreakoutBuffer * _Point) {
double range = rangeHigh - rangeLow;
OpenTrade(ORDER_TYPE_SELL, Lots, range * 0.5, range * 1.0, MagicNumber);
traded = true;
}
}
void CloseAll() {
for (int i=PositionsTotal()-1;i>=0;i--) {
ulong t=PositionGetTicket(i);
if (!PositionSelectByTicket(t)||(int)PositionGetInteger(POSITION_MAGIC)!=MagicNumber) continue;
MqlTradeRequest req={}; MqlTradeResult res={};
req.action=TRADE_ACTION_DEAL; req.position=t; req.symbol=_Symbol;
req.volume=PositionGetDouble(POSITION_VOLUME);
req.type=(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)?ORDER_TYPE_SELL:ORDER_TYPE_BUY;
req.price=(req.type==ORDER_TYPE_SELL)?SymbolInfoDouble(_Symbol,SYMBOL_BID):SymbolInfoDouble(_Symbol,SYMBOL_ASK);
req.type_filling=ORDER_FILLING_IOC; OrderSend(req,res);
}
}
void OpenTrade(ENUM_ORDER_TYPE type,double lots,double sl,double tp,int magic) {
MqlTradeRequest req={}; MqlTradeResult res={};
req.action=TRADE_ACTION_DEAL; req.symbol=_Symbol; req.volume=lots; req.type=type;
req.price=(type==ORDER_TYPE_BUY)?SymbolInfoDouble(_Symbol,SYMBOL_ASK):SymbolInfoDouble(_Symbol,SYMBOL_BID);
req.sl=(type==ORDER_TYPE_BUY)?req.price-sl:req.price+sl;
req.tp=(type==ORDER_TYPE_BUY)?req.price+tp:req.price-tp;
req.magic=magic; req.comment="Pineify US30"; req.type_filling=ORDER_FILLING_IOC;
OrderSend(req,res);
}Copy this code into MetaEditor, save it in the MQL5/Experts folder, and compile with F7.
Generate a custom US30 scalping EA
Describe the ATR inputs, alert rules, visual style, or confirmation filter you want. Pineify generates editable MQL5 source code that you can inspect and compile in MetaEditor.
Pine Script vs MQL5: Same Strategy, Different Platforms
| Aspect | Pine Script (TradingView) | MQL5 (MetaTrader 5) |
|---|---|---|
| Execution | Series evaluated on chart updates | Event handlers with explicit buffers |
| Deployment | Runs in TradingView with alerts | Runs in the MT5 terminal or on a VPS |
| Broker access | Via TradingView broker integration | Direct broker connectivity |
| Backtesting | Strategy Tester for strategy scripts | Strategy Tester for Expert Advisors |
| Code complexity | Simpler, functional syntax | C++-like, more powerful |
The calculation can be implemented on either platform, but the runtime model and buffer APIs differ. Read the Pine Script Supertrend reference before porting logic between them.
Frequently Asked Questions
Related MQL5 pages
Risk and testing note
Past performance is not indicative of future results. Backtest statistics are based on historical data and do not guarantee future profits. Trading involves significant risk of loss. This content is for educational purposes only and does not constitute financial advice.