const double open_price = PositionGetDouble(POSITION_PRICE_OPEN);
That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price 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.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price 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.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
const double open_price = PositionGetDouble(POSITION_PRICE_OPEN); This code already existed. There was no problem, but when I added the macd codes, there was a problem. I'm very confused. Could you help?
That is not an assignment; it's initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and
Don't try to use any price 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.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
I got very confused. How can you do? I need help?
I got very confused. How can you do? I need help?
remove those 3 lines 55, 56, 57. see if error goes away.
I got very confused. How can you do? I need help?
https://www.mql5.com/en/docs/trading/positiongetdouble
Position must be selected first, otherwise your positiongetdouble will always return 0.
To select the position you have to call:
https://www.mql5.com/en/docs/trading/positionselect
But you can't run any logic on the global scope, so remove the const modifier and move the initialization of the variables
to the OnInit/OnStart/OnCalculate function.
- www.mql5.com
remove those 3 lines 55, 56, 57. see if error goes away.
No it didn't fix
No it didn't fix
ghen post more information. like the log that shows the error. You have not shown the error, or given an error msg, only said it was a parenthesis issue, but i have compiled the file many times with no errors.
without the indicators we can not help more.
ghen post more information. like the log that shows the error. You have not shown the error, or given an error msg, only said it was a parenthesis issue, but i have compiled the file many times with no errors.
without the indicators we can not help more.
I'm taking a screenshot. It gives an error in parentheses on these lines. Didn't it give you an error?
I'm taking a screenshot. It gives an error in parentheses on these lines. Didn't it give you an error?
no. but i dont have all the files. the ea requires some indicators, that could be why i dont have errors.
no. but i dont have all the files. the ea requires some indicators, that could be why i dont have errors.
ı am add to indicators.please check ea
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use