I have a parenthesis error. I still can't find it. Anyone want to teach?

 
I have a parenthesis error in my android software. I still can't find it. Anyone want to teach?
Files:
zero_divide.mq5  28 kb
 
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++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. 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:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 
William Roeder:

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++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. 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:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. 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?

 
William Roeder:

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++.

  1. They are initialized once on program load.

  2. They don't update unless you assign to them.

  3. 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:

    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. 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?

 
Kutluhan Yesilkaya:

I got very confused. How can you do? I need help?

remove those 3 lines 55, 56, 57. see if error goes away.

 
Kutluhan Yesilkaya:

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.

Documentation on MQL5: Trade Functions / PositionGetDouble
Documentation on MQL5: Trade Functions / PositionGetDouble
  • www.mql5.com
PositionGetDouble - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Revo Trades:

remove those 3 lines 55, 56, 57. see if error goes away.

No it didn't fix

 
Kutluhan Yesilkaya:

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.

 
Revo Trades:

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?

Files:
en_ss.jpeg  11 kb
 
Kutluhan Yesilkaya:

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.

 
Revo Trades:

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

Files:
Uniano1.mq5  4 kb
ATRStopV2.mq5  6 kb
Reason: