Summary: Error 130 stops your EA from trading. This guide explains why it happens (stop loss too close to market price) and shows two solutions: adjusting EA parameters or modifying MQL4 code.
Step 1: Identify Error 130 in Your EA
Open the ‘Experts’ tab in MT4’s Toolbox window (press Ctrl+T). Look for red text saying ‘Error 130’ or ‘Invalid stops’. This appears when your EA tries to place an order but the stop loss or take profit is too close to the current market price. Screenshot: Experts tab showing red Error 130 message.
Step 2: Check Your Broker’s Minimum Stop Distance
Different brokers have different rules. Go to ‘Tools’ → ‘Options’ → ‘Trade’ tab. Alternatively, right-click in Market Watch, select ‘Symbols’, choose your pair, and click ‘Properties’. Look for ‘Stop Level’ or ‘Stops Level’ in points. Screenshot: Symbol properties window showing Stop Level value.
Step 3: Adjust EA Input Parameters
Many EAs let you set stop loss in points or pips. Open the EA’s input window (right-click chart → ‘Expert Advisors’ → ‘Properties’). Increase the stop loss distance value until it exceeds your broker’s minimum. For example, if Stop Level is 20 points, set your EA’s stop loss to at least 25 points. Screenshot: EA properties window with stop loss parameter highlighted.
Step 4: Modify MQL4 Code (For Custom EAs)
If the EA has no adjustable parameter, open the .mq4 file in MetaEditor (F4). Search for ‘StopLoss’, ‘stoploss’, or ‘SL’. Look for lines like ‘OrderSend(…, StopLoss, …)’. Add a safety margin. Example code: ‘int minStop = MarketInfo(Symbol(), MODE_STOPLEVEL) + 5;’ Then ensure your stop loss is never below this value. Screenshot: MQL4 code showing minStop calculation.
Step 5: Add a Distance Check Before OrderSend
Insert this code before your OrderSend function: ‘if (StopLoss_Value < minStop) StopLoss_Value = minStop;’ This forces the EA to use a valid distance. Recompile (F7) and reattach the EA. Screenshot: distance check code added before OrderSend.
Step 6: Test on Demo First
After making changes, always test on a demo account. Attach the EA and watch the Experts tab for 10-15 minutes. No red Error 130 means the fix worked. Screenshot: Demo chart with EA running without errors.
Reference: MetaQuotes MQL4 Documentation – OrderSend Function and Trade Constants.