Using a variable instead of explicitly stated the timeframe
Hi,
I'm trying to assign 'PERIOD_M1' to a variable called 'timeframe' so I can change it once at the top but the below gives me error 'timeframe' - cannot convert enum. Any ideas?
void OnStart()
{
//---
int shift = 3;
int File;
int timeframe = PERIOD_M1;
Because timeframe is not of type INT,
is is of type ENUM_TIMEFRAMES
You have to declare it this way:
int File; ENUM_TIMEFRAMES MyTimeFrame; MyTimeFrame = PERIOD_M1; // And now you can change it like you would do to any variable.
another example:
ENUM_TIMEFRAMES timeframe = PERIOD_M1;
Because timeframe is not of type INT,
is is of type ENUM_TIMEFRAMES
You have to declare it this way:
Please do not post your reply within the quote
I have edited your post and moved it.
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor -
Please don't add text inside quoted text or CODE
blocks, put it outside.
MQL4 forum editor problem - MQL4 programming forum
Hi,
I'm trying to assign 'PERIOD_M1' to a variable called 'timeframe' so I can change it once at the top but the below gives me error 'timeframe' - cannot convert enum. Any ideas?
void OnStart()
{
//---
int shift = 3;
int File;
int timeframe = PERIOD_M1;
double open, close, high, low;
File = FileOpen("OHLC.csv", FILE_CSV|FILE_WRITE);
FileWrite(File,"Symbol","DateTime","Open","High","Low","Close");
for(shift = 1; shift <= 100; shift++)
{
open = iOpen(Symbol(),timeframe,shift);
close = iClose(Symbol(),PERIOD_M1,shift);
high = iHigh(Symbol(),PERIOD_M1,shift);
low = iLow(Symbol(),PERIOD_M1,shift);
FileWrite(File, Symbol(),iTime(Symbol(),PERIOD_M1,shift),open,high,low,close);
}
}