Search code examples
algorithmic-tradingmql4metatrader4mt4

'Open' - undeclared identifier


Does somebody know why this code inside a .mqh file throws the error 'Open' - undeclared identifier?

It seems like Open, Close, High, Low functions aren´t "detected" in my library. ( Other system functions like Print() are properly loaded ).

bool isBlueCandle( int candle ) export {
   return Open[candle] < Close[candle];
}

Solution

  • Not exactly, neither 1:1 copy, nor any MODs, return any error:

    //+------------------------------------------------------------------+
    //|  isBlueCandle TESTs                     MetaLang.exe: Build 1154 |
    //+------------------------------------------------------------------+
    bool isBlueCANDLE_TEST(        int candle ) export
    {
       return Open[candle] < Close[candle];
    }
    
    bool isBlueCANDLE_TEST2(       int candle ) export {
       return Open[candle] < Close[candle];
    }
    
    bool isBlueCANDLE_TEST3( const int candle ) export {
       return Open[candle] < Close[candle];
    }
    
    bool isBlueCANDLE_TEST4( const int candle ) export {
       return( Open[candle] < Close[candle] );
    }
    

    As posted in the comment above, the missing context would help trace the root-cause for your stated issue.

    Post a complete copy of the MetaLang.exe Error-description. Use mouse-right-click + copy ( in MetaLang.exe-Toolbox window on [Error]-page + paste that complete description on StackOverflow )

    As an example:

    return value of 'OrderModify' should be checked
    FOREX_SimpleSAR_EA_msMOD_0.00.mq4   227 19
    

    Just for a clarity sake:

    MQL4 recognises both functions ( Print() ) and other objects ( Open ) with specific access-protocol to work with them. In case of functions, one passes "arguments" compatible with the function´s expectations.

    Open, High, Volume et al, are not functions, but Arrays, the more, these arrays are special and carefully constructed in the internal MT4-engine, so as to provide a very fast & very efficient manipulation.

    MetaQuotes call this a TimeSeries-object, a reversed-stepping-index into ( otherwise normal ) array.

    So, your function isBlueCandle() is indeed a function, however, internally it does not call a function, but it compares a cell-values of Open ( the [anIntIndexAsPtrIntoTimeSeriesOrderedARRAY]-*referenced cell ) against a value of Close ( namely the [anIntIndexAsPtrIntoTimeSeriesOrderedARRAY]-*referenced cell ) to construct a bool which the isBlueCandle() function is about to return.