'Close' - undeclared identifier" Error

 

Hi guys!


I got these errors as shown on the attach and below:


1. "    double closePrice = Close[0];"

- Error:

- 'Close' - undeclared identifier 

- '[' - array required


2.  double stopLossPrice = NormalizeDouble(Ask - stopLossPips * Point, Digits);

- Error:

- 'Ask' - undeclared identifier

- ',' - open parenthesis expected

- ')' - open parenthesis expected


Please help me to fix

Thank a ton!

Files:
 
  1. Why did you post your coding question in the MT5 General section instead of the MT5 EA section?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.


  2. There are no predefined arrays in MT5 unless you define them.
              Using global arrays like Open[], Close[], Low[], High[] in custom indicator for MetaTrader 5 - MQL5 programming forum (2023)

  3. There is no predefined variable Ask in MT5.
              Migrating from MQL4 to MQL5 - MQL5 Articles № 3

  4. Don't post pictures of code, they are generally too hard to read. Please use the CODE button (Alt-S) when inserting code — https://www.mql5.com/en/articles/24#insert-code

  5. 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 iMA and iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate/OnStart (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)

 

if you say "Close" to a cat, it won't understand, the same way OnTick won't understand.

You can define the meaning of the buffer either with iClose  https://www.mql5.com/en/docs/series/iclose or CopyClose https://www.mql5.com/en/docs/series/copyclose


or else you can use the predefined MQL4 arrays in MQL5 by including this library (which works!) https://www.mql5.com/en/code/16006

Documentation on MQL5: Timeseries and Indicators Access / iClose
Documentation on MQL5: Timeseries and Indicators Access / iClose
  • www.mql5.com
Returns the Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart. Parameters symbol [in]  The symbol name of...
 
William Roeder #:
  1. Why did you post your coding question in the MT5 General section instead of the MT5 EA section?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have moved this thread.


  2. There are no predefined arrays in MT5 unless you define them.
              Using global arrays like Open[], Close[], Low[], High[] in custom indicator for MetaTrader 5 - MQL5 programming forum (2023)

  3. There is no predefined variable Ask in MT5.
              Migrating from MQL4 to MQL5 - MQL5 Articles № 3

  4. Don't post pictures of code, they are generally too hard to read. Please use the CODE button (Alt-S) when inserting code — https://www.mql5.com/en/articles/24#insert-code

  5. 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 iMA and iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate/OnStart (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)

Thank you so much William, this is the 1st time I coded either post a question on MQL5 forum.
 
Conor Mcnamara #:

if you say "Close" to a cat, it won't understand, the same way OnTick won't understand.

You can define the meaning of the buffer either with iClose  https://www.mql5.com/en/docs/series/iclose or CopyClose https://www.mql5.com/en/docs/series/copyclose


or else you can use the predefined MQL4 arrays in MQL5 by including this library (which works!) https://www.mql5.com/en/code/16006

Thank you so much Mcnamara, this is the 1st time I coded. Im learning.