Hi,
there is a problem I can't solve. I wrote a formula with many variables calculated not to display them but to write them into a file.
I have a difficulty to place code line (writing this file) within the code of the main function.
some explanations :
The variables I want to calculate must be evaluated at some very precise moment (very precise bar-index) which depends on some logical conditions. And I don't know in advance the indexes for each variable. Furthermore all the variables don't have the same indexes.
Do I have to write each variable separately or at the same time ?
I tried at the same time and it didn't work. Precisely, I tried to write at the end of the loop (after the last bar). But how can I know I am at the end of the loop ?
Thanks in advance for any help.
see below summary of my code :
Mermoz.
there is a problem I can't solve. I wrote a formula with many variables calculated not to display them but to write them into a file.
I have a difficulty to place code line (writing this file) within the code of the main function.
some explanations :
The variables I want to calculate must be evaluated at some very precise moment (very precise bar-index) which depends on some logical conditions. And I don't know in advance the indexes for each variable. Furthermore all the variables don't have the same indexes.
Do I have to write each variable separately or at the same time ?
I tried at the same time and it didn't work. Precisely, I tried to write at the end of the loop (after the last bar). But how can I know I am at the end of the loop ?
Thanks in advance for any help.
see below summary of my code :
PHP Code:
function preMain(){
setPriceStudy(true);
setStudyTitle("writing of level");
setShowTitleParameters(false);
}
var R3_D = null;
var R2_D = null;
var R1_D = null;
var PP_D = null;
var S1_D = null;
var S2_D = null;
var S3_D = null;
var R3_W = null;
var R2_W = null;
var R1_W = null;
var PP_W = null;
var S1_W = null;
var S2_W = null;
var S3_W = null;
var R3_M = null;
var R2_M = null;
var R1_M = null;
var PP_M = null;
var S1_M = null;
var S2_M = null;
var S3_M = null;
var IdxD = 0;
var IdxW = 0;
var IdxM = 0;
var bRealTime= false;
var Valeur = null;
var precis = 5;
function main(){
var nBarIndex = getCurrentBarIndex();
var nBarState = getBarState();
if(getBarStateInterval("d") == BARSTATE_NEWBAR){
IdxD = nBarIndex;
H_D = high(-1,inv("d"));
L_D = low(-1,inv("d"));
C_D = close(-1);
}
if(getBarStateInterval("w") == BARSTATE_NEWBAR){
IdxW = nBarIndex;
H_W = high(-1,inv("w"));
L_W = low(-1,inv("w"));
C_W = close(-1);
}
if(getBarStateInterval("m") == BARSTATE_NEWBAR){
IdxM = nBarIndex;
H_M = high(-1,inv("m"));
L_M = low(-1,inv("m"));
C_M = close(-1);
}
if(C_D == null || C_W == null || C_M == null) { return; }
if(nBarIndex == 0 && nBarState == BARSTATE_CURRENTBAR){ bRealTime= true; }
if(bRealTime && nBarState == BARSTATE_NEWBAR){
IdxD--;
IdxW--;
IdxM--;
}
// calculus
// daily
PP_D = (H_D + L_D + C_D) / 3;
R1_D = 2*PP_D - L_D;
S1_D = 2*PP_D - H_D;
R2_D = PP_D + (H_D - L_D);
S2_D = PP_D - (H_D - L_D);
R3_D = 2*(PP_D - L_D) + H_D;
S3_D = 2*(PP_D - H_D) + L_D;
// weekly
PP_W = (H_W + L_W + C_W) / 3;
R1_W = 2*PP_W - L_W;
S1_W = 2*PP_W - H_W;
R2_W = PP_W + (H_W - L_W);
S2_W = PP_W - (H_W - L_W);
R3_W = 2*(PP_W - L_W) + H_W;
S3_W = 2*(PP_W - H_W) + L_W;
//Monthly
PP_M = (H_M + L_M + C_M) / 3;
R1_M = 2*PP_M - L_M;
S1_M = 2*PP_M - H_M;
R2_M = PP_M + (H_M - L_M);
S2_M = PP_M - (H_M - L_M);
R3_M = 2*(PP_M - L_M) + H_M;
S3_M = 2*(PP_M - H_M) + L_M;
// file open ...
var Monfichier = new File("LeFichier.txt");
Monfichier.open( "at" );
//writing of the first variable
Valeur = PP_M1.tofixed(precis);
Monfichier.writeln("PP_M1 =" + Valeur);
//writing of the second variable
Valeur = R1_M1.tofixed(precis);
Monfichier.writeln("R1_M1 =" + Valeur);
etc...
Monfichier.close()
}
Comment