- Gabriel Ibarreta: I NEED A HELP :)
Help you with what? You haven't stated a problem.
-
int OnInit(){ fastEMA = iMA(Symbol(), 0, fastEMAPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);
don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
-
if(OrdersTotal() == 0) BuyOrder();
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)You need one Magic Number for each symbol/timeframe/strategy.
Trade current timeframe, one strategy, and filter by symbol requires one MN.
If trading multiple timeframes, and filter by symbol requires use a range of MN (base plus timeframe).
Why are MT5 ENUM_TIMEFRAMES strange? - General - MQL5 programming forum - Page 2 #11 (2020) -
double stopLoss = Ask - 100 * Point; // Define SL double takeProfit = Ask + 100 * Point; // Define TP
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
Prices (open, SL, and TP) must be a multiple of ticksize. Using Point means code breaks on 4 digit brokers (if any still exists), exotics (e.g. USDZAR where spread is over 500 points), and metals. Compute what a logical PIP is and use that, not points.
How to manage JPY pairs with parameters? - MQL4 programming forum (2017)
Slippage defined in index points - Expert Advisors and Automated Trading - MQL5 programming forum (2018) -
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
-
Hi
You need to add some “normalization” functions to your code. 130 error means that there are some invalid prices in the OrderSend request.
You should Refresh prices (RefreshRates) before using Ask/Bid variables. Also you should normalize all prices (calculated sl/tp but also Ask/Bid, sometimes they have some “odd” numbers at the end and all of them has to be normalized to allow tick sizes. You can use this for example:
double normPrice(double p){ double ts = MarketInfo(_Symbol, MODE_TICKSIZE); if(ts==0) return(NormalizeDouble(p, (int)MarketInfo(_Symbol, MODE_DIGITS))); //no normalization if no ticksize info return( NormalizeDouble(MathRound(p/ts) * ts , (int)MarketInfo(_Symbol, MODE_DIGITS))); }
You should also normalize Lot size, sometimes brokers have different requirements for the lotsizes (for example min lot is 0.1 and not 0.01 etc).
Have a nice day👍📊
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
EA MQL4 LANGUAGE STRATEGY BASED ON
EMA Crossover + RSI: Identifies trend with EMA crossover and filters false signals using RSI.
EMA + Price Action + MACD: Confirms trend momentum using MACD to avoid fakeouts.
EMA Bounce + Fibonacci Retracement: Checks if the current price is near key Fibonacci retracement levels for a bounce.
EMA Slope + ADX: Only trades in strong trends when ADX > 25.
Multi-Timeframe EMA + Stochastic: Refines entries by considering overbought/oversold conditions across timeframes using Stochastic.
I NEED A HELP :)