'RBO.mq5' 0 'IndicatorShortName' - undeclared identifier RBO.mq5 141 5 'Initial Opening…
- User
'RBO.mq5' 0 'IndicatorShortName' - undeclared identifier RBO.mq5 141 5 'Initial Opening Balance Range w…' - some operator expected RBO.mq5 141 25 'SetIndexEmptyValue' - undeclared identifier RBO.mq5 145 9 ',' - unexpected token RBO.mq5 145 29 'i' - some operator expected RBO.mq5 145 28 ')' - unexpected token RBO.mq5 145 42 6 errors, 0 warnings 6 0
- Assistant
Great job narrowing down the errors!
These errors are because of a misuse of theIndicatorShortNameandSetIndexEmptyValuefunctions.
In MQL5, the correct function names areIndicatorSetString(INDICATOR_SHORTNAME, ...)andPlotIndexSetDouble(,PLOT_EMPTY_VALUE,...)(or you can set the empty value directly on the buffer).Here’s how to fix your code:
1. Replace
IndicatorShortName(...)with:IndicatorSetString(INDICATOR_SHORTNAME, "Initial Opening Balance Range with Fib (08:20-09:20 NY)");
2. Replace the loop:
for (int i = 0; i < 12; i++) { SetIndexEmptyValue(i, EMPTY_VALUE); }with:
PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(6, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(7, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(8, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(9, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(10, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(11, PLOT_EMPTY_VALUE, EMPTY_VALUE);
3. Remove the line with just
i)(it’s a copy-paste artifact).
Here is the corrected
OnInit()function:int OnInit() { // Range Buffers SetIndexBuffer(0, HighBuffer); SetIndexBuffer(1, LowBuffer); // Fib Buffers SetIndexBuffer(2, Fib0Buffer); SetIndexBuffer(3, Fib236Buffer); SetIndexBuffer(4, Fib382Buffer); SetIndexBuffer(5, Fib45Buffer); SetIndexBuffer(6, Fib50Buffer); SetIndexBuffer(7, Fib618Buffer); SetIndexBuffer(8, Fib80Buffer); SetIndexBuffer(9, Fib100Buffer); SetIndexBuffer(10, Fib1272Buffer); SetIndexBuffer(11, Fib1618Buffer); IndicatorSetString(INDICATOR_SHORTNAME, "Initial Opening Balance Range with Fib (08:20-09:20 NY)"); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(4, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(5, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(6, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(7, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(8, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(9, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(10, PLOT_EMPTY_VALUE, EMPTY_VALUE); PlotIndexSetDouble(11, PLOT_EMPTY_VALUE, EMPTY_VALUE); return(INIT_SUCCEEDED); }
After making these changes, your indicator should compile without those errors!
If you have any more errors, please paste the exact error message and the relevant code section.
- User
now convert this into a MT5 EA, once price breakouts and retraces to the 45% fib level, the EA must execute the trade with the stop loss at the 80% fib level and take profit is based on risk to reward settings. allow for training stop and lots size and percentage of equitly per trade.
- Assistant
Absolutely! Here’s a clear, robust MT5 EA (Expert Advisor) that implements your requirements:
EA Logic Overview
- ORB Range: Calculate the high/low from 08:20 to 09:20 NY time (adjustable offset).
- Breakout Detection: Wait for price to close above (bullish) or below (bearish) the range.
- Entry: After breakout, wait for price to retrace to the 45% Fib level, then enter a trade in the breakout direction.
- Stop Loss: At the 80% Fib level.
- Take Profit: Based on user-defined risk:reward ratio.
- Lot Size: Based on fixed lot or % of equity.
- Trailing Stop: Optional, user-defined.
- One trade per day per direction.
EA Code
Copy and paste this into a new
.mq5file in MetaEditor, compile, and attach to a chart.//+------------------------------------------------------------------+ //| ORB Fib Retrace EA for MT5 | //+------------------------------------------------------------------+ #property copyright "2024" #property version "1.00" #property strict //--- Inputs input int NY_Time_Offset_Hours = -4; // NY Time Offset from GMT (e.g., -4 for DST, -5 for Standard) input double Risk_Per_Trade_Percent = 1.0; // % of equity to risk per trade input double Fixed_Lot = 0.0; // If >0, use fixed lot size, else use risk percent input double Risk_Reward = 2.0; // Take profit = RR * stop loss input double Trailing_Stop_Points = 0; // 0 = off, else trailing stop in points input int Slippage = 5; input int Magic = 20240724; //--- Global variables datetime lastORBDate = 0; double ORB_High = 0, ORB_Low = 0; datetime ORB_EndTime = 0; bool breakoutBull = false, breakoutBear = false; bool tradedBull = false, tradedBear = false; double fib45 = 0, fib80 = 0, fib0 = 0, fib100 = 0, fibBreakout = 0; int direction = 0; // 1 = bull, -1 = bear //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { Print("ORB Fib Retrace EA loaded."); return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { static datetime lastBarChecked = 0; MqlDateTime nyStruct; datetime now = TimeCurrent(); datetime nyNow = now + NY_Time_Offset_Hours * 3600; TimeToStruct(nyNow, nyStruct); datetime todayNY = StructToTime(nyStruct) - (nyStruct.hour*3600 + nyStruct.min*60 + nyStruct.sec); // 1. Calculate ORB range if new day if(todayNY != lastORBDate) { ResetDayVars(); CalculateORBRange(todayNY); lastORBDate = todayNY; } // 2. Wait for breakout after ORB if(ORB_EndTime > 0 && TimeCurrent() > ORB_EndTime) { if(!breakoutBull && Close[0] > ORB_High) { breakoutBull = true; direction = 1; fib0 = ORB_High; fib100 = ORB_Low; fib45 = fib0 + 0.45 * (fib100 - fib0); fib80 = fib0 + 0.80 * (fib100 - fib0); fibBreakout = Close[0]; Print("Bullish breakout detected. Waiting for retrace to 45%: ", DoubleToString(fib45, _Digits)); } if(!breakoutBear && Close[0] < ORB_Low) { breakoutBear = true; direction = -1; fib0 = ORB_Low; fib100 = ORB_High; fib45 = fib0 + 0.45 * (fib100 - fib0); fib80 = fib0 + 0.80 * (fib100 - fib0); fibBreakout = Close[0]; Print("Bearish breakout detected. Waiting for retrace to 45%: ", DoubleToString(fib45, _Digits)); } } // 3. Wait for retrace to 45% and trade (one trade per day per direction) if(direction == 1 && breakoutBull && !tradedBull) { if(Low[0] <= fib45 && Close[0] >= fib45) { double stopLoss = MathAbs(fib45 - fib80); double takeProfit = stopLoss * Risk_Reward; double entry = fib45; double sl = fib80; double tp = entry + takeProfit; double lot = CalculateLot(stopLoss); if(lot > 0) { if(OrderSend(Symbol(), OP_BUY, lot, entry, Slippage, sl, tp, "ORB Bull", Magic, 0, clrBlue) > 0) { tradedBull = true; Print("Bullish trade placed at ", DoubleToString(entry, _Digits), " SL: ", DoubleToString(sl, _Digits), " TP: ", DoubleToString(tp, _Digits), " Lot: ", DoubleToString(lot, 2)); } } } } if(direction == -1 && breakoutBear && !tradedBear) { if(High[0] >= fib45 && Close[0] <= fib45) { double stopLoss = MathAbs(fib45 - fib80); double takeProfit = stopLoss * Risk_Reward; double entry = fib45; double sl = fib80; double tp = entry - takeProfit; double lot = CalculateLot(stopLoss); if(lot > 0) { if(OrderSend(Symbol(), OP_SELL, lot, entry, Slippage, sl, tp, "ORB Bear", Magic, 0, clrRed) > 0) { tradedBear = true; Print("Bearish trade placed at ", DoubleToString(entry, _Digits), " SL: ", DoubleToString(sl, _Digits), " TP: ", DoubleToString(tp, _Digits), " Lot: ", DoubleToString(lot, 2)); } } } } // 4. Trailing stop if(Trailing_Stop_Points > 0) { TrailStops(); } } //+------------------------------------------------------------------+ //| Calculate ORB Range | //+------------------------------------------------------------------+ void CalculateORBRange(datetime todayNY) { int startSec = 8*3600 + 20*60; int endSec = 9*3600 + 20*60; double hi = -DBL_MAX, lo = DBL_MAX; datetime orbEnd = 0; for(int i=Bars-1; i>=0; i--) { datetime barTime = Time[i]; datetime nyTime = barTime + NY_Time_Offset_Hours * 3600; MqlDateTime nyStruct; TimeToStruct(nyTime, nyStruct); datetime barDay = StructToTime(nyStruct) - (nyStruct.hour*3600 + nyStruct.min*60 + nyStruct.sec); if(barDay != todayNY) continue; int sec = nyStruct.hour*3600 + nyStruct.min*60 + nyStruct.sec; if(sec >= startSec && sec < endSec) { if(High[i] > hi) hi = High[i]; if(Low[i] < lo) lo = Low[i]; orbEnd = barTime; } if(sec >= endSec) break; } if(hi > -DBL_MAX && lo < DBL_MAX) { ORB_High = hi; ORB_Low = lo; ORB_EndTime = orbEnd + NY_Time_Offset_Hours * 3600; // Broker time Print("ORB Range: High=", DoubleToString(ORB_High, _Digits), " Low=", DoubleToString(ORB_Low, _Digits)); } } //+------------------------------------------------------------------+ //| Reset daily variables | //+------------------------------------------------------------------+ void ResetDayVars() { ORB_High = 0; ORB_Low = 0; ORB_EndTime = 0; breakoutBull = false; breakoutBear = false; tradedBull = false; tradedBear = false; direction = 0; fib45 = 0; fib80 = 0; fib0 = 0; fib100 = 0; fibBreakout = 0; } //+------------------------------------------------------------------+ //| Calculate lot size | //+------------------------------------------------------------------+ double CalculateLot(double stopLoss) { double lot = Fixed_Lot; if(lot > 0) return lot; double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE); double contract = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE); double equity = AccountInfoDouble(ACCOUNT_EQUITY); double riskMoney = equity * Risk_Per_Trade_Percent / 100.0; double slPoints = stopLoss / SymbolInfoDouble(_Symbol, SYMBOL_POINT); if(slPoints < 1) slPoints = 1; double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP); double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN); double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX); double pipValue = (tickValue / tickSize) * SymbolInfoDouble(_Symbol, SYMBOL_POINT); lot = riskMoney / (slPoints * pipValue); lot = MathMax(minLot, MathMin(maxLot, MathFloor(lot / lotStep) * lotStep)); return lot; } //+------------------------------------------------------------------+ //| Trailing stop logic | //+------------------------------------------------------------------+ void TrailStops() { for(int i=PositionsTotal()-1; i>=0; i--) { ulong ticket = PositionGetTicket(i); if(PositionGetInteger(POSITION_MAGIC) != Magic) continue; if(PositionGetString(POSITION_SYMBOL) != _Symbol) continue; double price = PositionGetDouble(POSITION_PRICE_OPEN); double sl = PositionGetDouble(POSITION_SL); double tp = PositionGetDouble(POSITION_TP); double cur = SymbolInfoDouble(_Symbol, SYMBOL_BID); double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT); double trail = Trailing_Stop_Points * point; if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { double newSL = cur - trail; if(newSL > sl && cur - price > trail) { trade.PositionModify(ticket, newSL, tp); } } if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { double newSL = cur + trail; if(newSL < sl && price - cur > trail) { trade.PositionModify(ticket, newSL, tp); } } } } //+------------------------------------------------------------------+ //| OrderSend wrapper for MT5 | //+------------------------------------------------------------------+ #include <Trade\Trade.mqh> CTrade trade; int OrderSend(string symbol, int cmd, double lot, double price, int slippage, double sl, double tp, string comment, int magic, int expiry, color arrow_color) { ENUM_ORDER_TYPE type = (cmd==OP_BUY) ? ORDER_TYPE_BUY : ORDER_TYPE_SELL; double ask = SymbolInfoDouble(symbol, SYMBOL_ASK); double bid = SymbolInfoDouble(symbol, SYMBOL_BID); double p = (cmd==OP_BUY) ? ask : bid; sl = NormalizeDouble(sl, _Digits); tp = NormalizeDouble(tp, _Digits); if(cmd==OP_BUY) return trade.Buy(lot, symbol, p, sl, tp, comment) ? 1 : -1; else return trade.Sell(lot, symbol, p, sl, tp, comment) ? 1 : -1; }
How to Use
- Compile in MetaEditor.
- Attach to a chart (M1 or M5 recommended for accuracy).
- Set your parameters (risk, lot, trailing stop, etc).
- Let it run. The EA will only trade once per direction per day, after a valid breakout and retrace.
Notes
- NY time offset: Adjust for DST as needed.
- Risk calculation: If
Fixed_Lotis 0, risk is % of equity per trade. - Trailing stop: Set to 0 to disable.
- Magic number: Change if running multiple EAs.
- No martingale, no grid, no re-entries: One trade per direction per day.
If you want more features (alerts, panel, etc), just ask!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.