#define OP_BUY 0
That's not your only problem to be solved.
-
accountBalance = AccountInfoDouble(ACCOUNT_BALANCE);
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(prevMaValue == 0) { prevMaValue = iMA(_Symbol, 0, maPeriod, 0, MODE_SMA, PRICE_CLOSE);
Perhaps you should read the manual, especially the examples.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
How to call indicators in MQL5 - MQL5 Articles (2010) -
stopLossPrice = currentPrice - atr * atrMultiplier; takeProfitPrice = currentPrice + atr * atrMultiplier;
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 -
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)
-
-
int ticket= OrderSend(_Symbol ,OP_BUY ,lotSize ,currentPrice ,3 ,stopLossPrice ,takeProfitPrice ,"Buy order" ,0 ,trailingStopPrice ,clrGreen );
This is the MT4 command. Totally incompatible with MT5.
Hi , I need help , I have this EA code:
when I execute this code, I got this error: 'OP_BUY' - undeclared identifier EA2.mq5 261 39 , in this line: int orderTicket = OrderSend(Symbol(), OP_BUY, 1.0, Ask, 3, 0, 0); , I don't know how should I solve this error, would you please help me if possible?
Dont use generators or Chat GPT to help you. The OP_BUY is not a MT5 command. You can always look at the MQL5 reference manual, there you will find everything you need to know. But asking AI to help you will not solve the problem
Here is a link to a PDF that you can use, it explains in great detail how to get started and i have added a link to MQL5 reference as well.
[PDF] Expert Advisor Programming for Metatrader 5 Copy - Free Download (epdfx.com)
MQL5 Reference – How to use algorithmic/automated trading language for MetaTrader 5
![[PDF] Expert Advisor Programming for Metatrader 5 Copy - Free Download [PDF] Expert Advisor Programming for Metatrader 5 Copy - Free Download](https://c.mql5.com/36/82/pdf-expert-advisor-programming.png)
- epdfx.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi , I need help , I have this EA code:
when I execute this code, I got this error: 'OP_BUY' - undeclared identifier EA2.mq5 261 39 , in this line: int orderTicket = OrderSend(Symbol(), OP_BUY, 1.0, Ask, 3, 0, 0); , I don't know how should I solve this error, would you please help me if possible?