But as I admitted last time I don't know - I'm not a programmer by training. Although I finally was able to do my own trivial code to answer my last question on my own - a snap for a guru, no ?
Anyway, here are two scripts that do the same thing - indentically on the screen -
Here's the question, which version will take up less computer resources - which one will theoretically run faster ?
And it would be worthwhile to hear the explanation of the
if ( bInit == false )
and why the good programmers use this.
Best Regards,
Glenn
var bInit = false;
function preMain() {
setPriceStudy(true);
setDefaultBarFgColor(Color.RGB(50,50,0),0);
setDefaultBarFgColor(Color.RGB(45,0,0),1);
}
function main() {
if ( bInit == false ) {
w20 = wma(20)
w60 = wma(60)
bInit = true;
}
myw20 = w20.getValue(0);
myw20p = w20.getValue(-1);
drawLineRelative(0, myw20, 5, (myw20+5*(myw20-myw20p)), PS_SOLID, 1, Color.RGB(50,50,0), 0 );
myw60 = w60.getValue(0);
myw60p = w60.getValue(-1);
drawLineRelative(0, myw60, 5, (myw60+5*(myw60-myw60p)), PS_SOLID, 1, Color.RGB(45,0,0), 1 );
return new Array(myw20,myw60);
}
OR
function preMain() {
setPriceStudy(true);
setDefaultBarFgColor(Color.RGB(50,50,0),0);
setDefaultBarFgColor(Color.RGB(45,0,0),1);
}
function main() {
w20 = wma(20)
w60 = wma(60)
drawLineRelative(0, w20, 5, (w20+5*(w20-w20.getValue(-1))), PS_SOLID, 1, Color.RGB(50,50,0),0);
drawLineRelative(0, w60, 5, (w60+5*(w60-w60.getValue(-1))), PS_SOLID, 1, Color.RGB(45,0,0), 1);
return new Array(w20,w60);
}
Anyway, here are two scripts that do the same thing - indentically on the screen -
Here's the question, which version will take up less computer resources - which one will theoretically run faster ?
And it would be worthwhile to hear the explanation of the
if ( bInit == false )
and why the good programmers use this.
Best Regards,
Glenn
var bInit = false;
function preMain() {
setPriceStudy(true);
setDefaultBarFgColor(Color.RGB(50,50,0),0);
setDefaultBarFgColor(Color.RGB(45,0,0),1);
}
function main() {
if ( bInit == false ) {
w20 = wma(20)
w60 = wma(60)
bInit = true;
}
myw20 = w20.getValue(0);
myw20p = w20.getValue(-1);
drawLineRelative(0, myw20, 5, (myw20+5*(myw20-myw20p)), PS_SOLID, 1, Color.RGB(50,50,0), 0 );
myw60 = w60.getValue(0);
myw60p = w60.getValue(-1);
drawLineRelative(0, myw60, 5, (myw60+5*(myw60-myw60p)), PS_SOLID, 1, Color.RGB(45,0,0), 1 );
return new Array(myw20,myw60);
}
OR
function preMain() {
setPriceStudy(true);
setDefaultBarFgColor(Color.RGB(50,50,0),0);
setDefaultBarFgColor(Color.RGB(45,0,0),1);
}
function main() {
w20 = wma(20)
w60 = wma(60)
drawLineRelative(0, w20, 5, (w20+5*(w20-w20.getValue(-1))), PS_SOLID, 1, Color.RGB(50,50,0),0);
drawLineRelative(0, w60, 5, (w60+5*(w60-w60.getValue(-1))), PS_SOLID, 1, Color.RGB(45,0,0), 1);
return new Array(w20,w60);
}
Comment