Migrating from MQL4 to MQL5 - some strange Problems!

 

I have a huge include File that now compiles for MQL5 with no Error.

Within I have two functions

double calcPrice(ENUM_TIMEFRAMES per=PERIOD_CURRENT, int calc=0) { .. }
...
double chckPrice() {
...
        double v = calcPrice(Period(),k); // it's line 3457, at 37 is the P of Period()
...
}

NOW - if I compile an indicator that loads myDefs.mqh but does not call any of these two functions I get this compiler error:

'Period' - cannot convert enum  myDefs.mqh      3457    37

Both the first variable of the function (per) and the function Period() are define as ENUM_TIMEFRAMES - why it has to be converted, and why it fails?

Anyone with a little light in my darkness?

 

have you tried _Period

 
Marco vd Heijden:

have you tried _Period

I have previously had _Period (from mt4) but in MQL5 it returns an integer while Period() returns an enum.

 

Are you sure about that ?

https://www.mql5.com/en/docs/standardlibrary/chart_object_classes/obj_controls/cchartobjectsubchart/cchartobjectsubchartperiod

Maybe 

double calcPrice(ENUM_TIMEFRAMES per=PERIOD_CURRENT, int calc=0) { .. }
...
ENUM_TIMEFRAMES timeframe = Period();
double chckPrice() {
...
        double v = calcPrice(timeframe,k); // it's line 3457, at 37 is the P of Period()
...
}
Documentation on MQL5: Standard Library / Graphic Objects / Control Objects / CChartObjectSubChart / Period
Documentation on MQL5: Standard Library / Graphic Objects / Control Objects / CChartObjectSubChart / Period
  • www.mql5.com
Standard Library / Graphic Objects / Control Objects / CChartObjectSubChart / Period - Reference on algorithmic/automated trading language for MetaTrader 5
 

That's what my reference to mql5 tells me:


Sorry I tried twice to upload an image?
Files:
p3.PNG  28 kb
 
Carl Schreiber:

That's what my reference to mql5 tells me:


 double v = calcPrice((ENUM_TIMEFRAME)Period(),k); // it's line 3457, at 37 is the P of Period()

or 

 double v = calcPrice(PERIOD_CURRENT,k); // it's line 3457, at 37 is the P of Period()

try these ones. 

 
Icham Aidibe:

or 

try these ones. 

I tried the last one and that satisfies the compiler - could have thought of that myself :(
 

It clearly states:

Period (Get Method)

Gets the value of "Period" property.

int  Period() const

Return Value

Value of "Period" property of the object assigned to the class instance. If there is no object assigned, it returns 0.

 
Carl Schreiber:
I tried the last one and that satisfies the compiler - could have thought of that myself :(

Yeah err ... your snippets returns the ENUM as an integer ; apparently indicators strictly need it as a ENUM. 

 
Marco vd Heijden:

It clearly states:

Period (Get Method)

Gets the value of "Period" property.

Return Value

Value of "Period" property of the object assigned to the class instance. If there is no object assigned, it returns 0.

Hmm - the reference of the editor for mql5 b. 1870 26 June 1028 tell something different:

Period

Gibt den Wert von Timeframe des laufenden Charts zurück.


ENUM_TIMEFRAMES  Period();
 

Rückgabewert

Inhalt der Variable _Period, in Timeframewert des laufenden Charts aufbewahren wird. Wert kann einer der Enumerationswerte ENUM_TIMEFRAMES sein.

Sehen Sie auch

PeriodSeconds, Chartperioden, Datum und Zeit, Objektsichtbarkeit

I can't add any image... :(

 
Carl Schreiber:

Hmm - the reference of the editor for mql5 b. 1870 26 June 1028 tell something different:

I can't add any image... :(

Still same issue, you are compiling an mq4 file I guess ?