This is the first formula I've done and I'm sure there's a lot of room for improvement. As it is now, it's unusably slow. I go through my watchlist pulling up the charts, and am waiting several seconds for each to load with this formula loaded. I'm hoping someone can offer some suggestions for speeding it up.
thanks alot.
thanks alot.
PHP Code:
bCurrentDay = false;
function preMain() {
setPriceStudy(true);
setStudyTitle("rwe_traderxfib2");
setCursorLabelName("yest", 0);
setCursorLabelName("today", 1);
setCursorLabelName("fib", 2);
setCursorLabelName("fib", 3);
setCursorLabelName("fib", 4);
setCursorLabelName("fib", 5);
setCursorLabelName("fib", 6);
setPlotType(PLOTTYPE_FLATLINES,0);
setPlotType(PLOTTYPE_FLATLINES,1);
setPlotType(PLOTTYPE_FLATLINES,2);
setPlotType(PLOTTYPE_FLATLINES,3);
setPlotType(PLOTTYPE_FLATLINES,4);
setPlotType(PLOTTYPE_FLATLINES,5);
setPlotType(PLOTTYPE_FLATLINES,6);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1);
setDefaultBarFgColor(Color.black,2);
setDefaultBarFgColor(Color.black,3);
setDefaultBarFgColor(Color.black,4);
setDefaultBarFgColor(Color.black,5);
setDefaultBarFgColor(Color.black,6);
}
var bInit = false;
var xRange = null;
function main(){
if (bCurrentDay == false && getDay(0) != getDay(-1)){
var vTime = getValue("time");
var vDate = new Date();
var sTime = (vTime.getMonth()+1+"/"+vTime.getDate()+"/"+vTime.getFullYear());
var sToday = (vDate.getMonth()+1+"/"+vDate.getDate()+"/"+vDate.getFullYear());
if ( sTime == sToday ) {
bCurrentDay = true;
}
}
if(bInit==false){
xRange = efsInternal("calcOR","630","645","Show",inv(15));
bInit=true;
}
orHigh = getSeries(xRange, 0);
orLow = getSeries(xRange, 1);
yestH= efsExternal("/OHLC/getPrevOHLC.efs", "High");
yestL= efsExternal("/OHLC/getPrevOHLC.efs", "Low");
yestC= efsExternal("/OHLC/getPrevOHLC.efs", "Close");
todayO= efsExternal("/OHLC/getTodayOHLC.efs", "Open");
gap = ((todayO - yestC) / yestC) * 100;
if(gap <= -1){ // gap down
yestLine = yestH;
orLine = orLow;
hiloDiff = yestLine - orLine;
fib1 = hiloDiff*0.382;
fib2 = hiloDiff*0.5;
fib3 = hiloDiff*0.618;
fib1Line = orLine + fib1;
fib2Line = orLine + fib2;
fib3Line = orLine + fib3;
fib4Line = orLine - fib1;
fib5Line = yestLine + fib1;
}else if(gap >= 1){ // gap up
yestLine = yestL;
orLine = orHigh;
hiloDiff = orLine - yestLine;
fib1 = hiloDiff*0.382;
fib2 = hiloDiff*0.5;
fib3 = hiloDiff*0.618;
fib1Line = yestLine + fib1;
fib2Line = yestLine + fib2;
fib3Line = yestLine + fib3;
fib4Line = yestLine - fib1;
fib5Line = orLine + fib1;
}else{
return;
}
if (bCurrentDay==false){
return;
}
return new Array(yestLine, orLine, fib1Line, fib2Line, fib3Line, fib4Line, fib5Line);
}
var vFlag = true;
var vFlag2 = true
var vHigh = null;
var vLow = null;
var vClose = null;
var vDay1 = null;
var vDay2 = null;
function calcOR(start,end,display,source){
if (getBarState() == BARSTATE_NEWBAR) {
if (vDay1 == null) {
vDay2 = getDay(0);
} else {
vDay2 = vDay1;
}
vDay1 = getDay(0);
if (vDay1 != vDay2) {
vHigh = null;
vLow = null;
vFlag = true;
vFlag2 = false;
}
var vHour1 = (getHour()*100)+getMinute();
if(vHour1 >= start){
vFlag2=true;
}
var vHour = (getHour()*100)+getMinute();
if (vHour >= end) {
vFlag = false;
vFlag2=false;
}
}
if (vFlag == true&&vFlag2==true) {
if (vHigh == null) {
vHigh = high(0);
}
if (vLow == null) {
vLow = low(0);
}
vHigh = Math.max(high(0), vHigh);
vLow = Math.min(low(0), vLow);
}
if(display=="Hide"){
if(vFlag==false&&vHigh!=null&&vLow!=null){
var vHigh2 = vHigh;
var vLow2 = vLow;
}
}else if(display=="Show"){
var vHigh2 = vHigh;
var vLow2 = vLow;
}
return new Array(vHigh2,vLow2);
}
Comment