It appears that I am taking a pretty big hit in CPU utilization when an efs() is called; especially the first time. I think part of the problem is that the efs() returns an array and a lot of time is spent getting (calculating) the various individual array values.
efslib:
indicator;
My feeling is that instead of just getting the value from the array, the entire calculation is being done over for successive calls. So in reality, since the array has 3 elements, the indicator is being calculated 3 times instead of just once
efslib:
PHP Code:
//Define the DynamicSuppRess indicator
//Note: it takes 2 functions to turn a KP indicator into a serial object
//Note: DynamicSuppRess returns an array. must use efs()
function KPDynamicSR(symbol, interval) {
if(symbol == null) symbol = getSymbol();
if(interval == null) interval = getInterval();
var vSymbol = symbol + "," + interval
return new Array(efs(KP2Path + "KPDynamicSuppRess.efs",0,sym( vSymbol)), efs(KP2Path + "KPDynamicSuppRess.efs",1,sym( vSymbol)), efs(KP2Path + "KPDynamicSuppRess.efs",2,sym( vSymbol)) );
PHP Code:
function main(fpSymbol, fpInterval, fpPT1, fpPS1, fpThick1, fpColor1, fpPT2, fpPS2, fpThick2, fpColor2, fpPT3, fpPS3, fpThick3, fpColor3, fpPVar)
{
// one time initialization
if(bInit == false){
if(fpSymbol == null) fpSymbol = getSymbol();
if(fpInterval == null) fpInterval = getInterval();
setCursorLabelName("ESKPDYNAMICSUPPRESSB_Mean " +fpSymbol + "(" + fpInterval + ")",0);
setCursorLabelName("ESKPDYNAMICSUPPRESSB_Ress " +fpSymbol + "(" + fpInterval + ")",1);
setCursorLabelName("ESKPDYNAMICSUPPRESSB_Supp " +fpSymbol + "(" + fpInterval + ")",2);
//set the Plot Type for the 1st variable
switch(fpPT1) {
case "Line":
setPlotType(PLOTTYPE_LINE,0);
break;
case "Dot":
setPlotType(PLOTTYPE_DOT,0);
break;
case "SquareWave":
setPlotType(PLOTTYPE_SQUAREWAVE,0);
break;
case "Histogram":
setPlotType(PLOTTYPE_HISTOGRAM,0);
break;
case "FlatLines":
setPlotType(PLOTTYPE_FLATLINES,0);
break;
case "InstantColorLine":
setPlotType(PLOTTYPE_INSTANTCOLORLINE,0);
break;
}
//Set the Plot Style for the 1st variable
switch(fpPS1) {
case "Solid":
setDefaultBarStyle(PS_SOLID,0);
break;
case "Dot":
setDefaultBarStyle(PS_DOT,0);
break;
case "Dash":
setDefaultBarStyle(PS_DASH,0);
break;
case "DashDot":
setDefaultBarStyle(PS_DASHDOT,0);
break;
case "DashDotDot":
setDefaultBarStyle(PS_DASHDOTDOT,0);
break;
}
//set the Plot Type for the 2nd variable
switch(fpPT2) {
case "Line":
setPlotType(PLOTTYPE_LINE,1);
break;
case "Dot":
setPlotType(PLOTTYPE_DOT,1);
break;
case "SquareWave":
setPlotType(PLOTTYPE_SQUAREWAVE,1);
break;
case "Histogram":
setPlotType(PLOTTYPE_HISTOGRAM,1);
break;
case "FlatLines":
setPlotType(PLOTTYPE_FLATLINES,1);
break;
case "InstantColorLine":
setPlotType(PLOTTYPE_INSTANTCOLORLINE,1);
break;
}
//Set the Plot Style for the 2nd variable
switch(fpPS2) {
case "Solid":
setDefaultBarStyle(PS_SOLID,1);
break;
case "Dot":
setDefaultBarStyle(PS_DOT,1);
break;
case "Dash":
setDefaultBarStyle(PS_DASH,1);
break;
case "DashDot":
setDefaultBarStyle(PS_DASHDOT,1);
break;
case "DashDotDot":
setDefaultBarStyle(PS_DASHDOTDOT,1);
break;
}
//set the Plot Type for the 3rd variable
switch(fpPT3) {
case "Line":
setPlotType(PLOTTYPE_LINE,2);
break;
case "Dot":
setPlotType(PLOTTYPE_DOT,2);
break;
case "SquareWave":
setPlotType(PLOTTYPE_SQUAREWAVE,2);
break;
case "Histogram":
setPlotType(PLOTTYPE_HISTOGRAM,2);
break;
case "FlatLines":
setPlotType(PLOTTYPE_FLATLINES,2);
break;
case "InstantColorLine":
setPlotType(PLOTTYPE_INSTANTCOLORLINE,2);
break;
}
//Set the Plot Style for the 3rd variable
switch(fpPS3) {
case "Solid":
setDefaultBarStyle(PS_SOLID,2);
break;
case "Dot":
setDefaultBarStyle(PS_DOT,2);
break;
case "Dash":
setDefaultBarStyle(PS_DASH,2);
break;
case "DashDot":
setDefaultBarStyle(PS_DASHDOT,2);
break;
case "DashDotDot":
setDefaultBarStyle(PS_DASHDOTDOT,2);
break;
}
setDefaultBarThickness( Math.round(fpThick1), 0 );
setDefaultBarThickness( Math.round(fpThick2), 1 );
setDefaultBarThickness( Math.round(fpThick3), 2 );
setDefaultBarFgColor(fpColor1,0);
setDefaultBarFgColor(fpColor2,1);
setDefaultBarFgColor(fpColor3,2);
nDYNAMICSUPPRESS = KPLib.KPDynamicSR(fpSymbol, fpInterval);
bInit = true;
} //end of initialization
// Plot the correct variables
switch(fpPVar) {
case "All":
return new Array(nDYNAMICSUPPRESS[0].getValue(0), nDYNAMICSUPPRESS[1].getValue(0), nDYNAMICSUPPRESS[2].getValue(0));
break;
case "Support":
return new Array(null, null, nDYNAMICSUPPRESS[2].getValue(0));
break;
case "Resistance":
return new Array(null, nDYNAMICSUPPRESS[1].getValue(0), null);
break;
case "Mean":
return new Array(nDYNAMICSUPPRESS[0].getValue(0), null, null);
break;
case "Support/Resistance":
return new Array(null, nDYNAMICSUPPRESS[1].getValue(0), nDYNAMICSUPPRESS[2].getValue(0));
break;
}
}
Comment