Hi Coders, I'm a beginner without programming background and I created a simple export script as follows :-
Due to the loop's results are more than one day, my mission now is to get the 1st Shift # (startSf) of lower timeframe (TF) from D1 for each line of output, but I yet failed to get the correct codes. My incorrect codes are as follows :-
Kindly open my Excel attachment for better understanding.
The output shift # of the "startSf" is a must for me as I need to use it for other calculation purposes. Furthermore, the "startSf" must be an integer.
The problem now is the 1st Shift # (startSf) of lower timeframe (TF) from D1 does not change at all on each next new day (not looped) and I do not know where my codes go wrong. Kindly help to correct my script codes, highly appreciated, thank you.
Inserted Code
int mxBar=100;
int TF=60;
int start() {
int handle;
handle=FileOpen("history.csv", FILE_CSV|FILE_WRITE, ',');
if(handle>0) {for(int i=1; i<=mxBar; i++)
FileWrite(handle,i,
TimeToStr(iTime(Symbol(),TF,i),TIME_DATE|TIME_SECONDS),
Symbol(),
iBarShift(Symbol(),1440,iTime(Symbol(),TF,i),true), // Shift# of D1
DoubleToStr(iOpen(Symbol(),TF,i),5)
); FileClose(handle);
}
return(0);} Due to the loop's results are more than one day, my mission now is to get the 1st Shift # (startSf) of lower timeframe (TF) from D1 for each line of output, but I yet failed to get the correct codes. My incorrect codes are as follows :-
Inserted Code
int mxBar=100;
int TF=60;
int start() {
int handle;
handle=FileOpen("history.csv", FILE_CSV|FILE_WRITE, ',');
if(handle>0) {for(int k=1; k<=mxBar; k++) {
int daySf=iBarShift(Symbol(),1440,iTime(Symbol(),TF,k),true);
int startSf=iBarShift(Symbol(),TF,iTime(Symbol(),1440,daySf),true);
// to get 1st Shift # of D1
if(startSf==-1) startSf=iBarShift(Symbol(),TF,iTime(Symbol(),1440,daySf),false)-1;
// for symbols that NOT 24 hours
for(int i=k; i<=mxBar; i++)
FileWrite(handle,i,
TimeToStr(iTime(Symbol(),TF,i),TIME_DATE|TIME_SECONDS),
Symbol(),
iBarShift(Symbol(),1440,iTime(Symbol(),TF,i),true), // Shift# of D1
startSf,
DoubleToStr(iClose(Symbol(),TF,startSf),5), // newly added
DoubleToStr(iClose(Symbol(),TF,i),5)
); FileClose(handle);
}
}
return(0);} Kindly open my Excel attachment for better understanding.
The output shift # of the "startSf" is a must for me as I need to use it for other calculation purposes. Furthermore, the "startSf" must be an integer.
The problem now is the 1st Shift # (startSf) of lower timeframe (TF) from D1 does not change at all on each next new day (not looped) and I do not know where my codes go wrong. Kindly help to correct my script codes, highly appreciated, thank you.
Attached File(s)