Hi,
In the attached image you will note that the high/low is not correctly returned by the following script regardless of use of BARSTATE_NEWBAR, or high(0)/high(-1) or low(0)/low(-1).
I need the study to return the price bar high of the bar when stochs %K is below the 20 and is crossing up through %D and the price bar low when %K is above the 80 and %K is crossing down under the %D.
Any help is greatly appreciated.
wayne
In the attached image you will note that the high/low is not correctly returned by the following script regardless of use of BARSTATE_NEWBAR, or high(0)/high(-1) or low(0)/low(-1).
I need the study to return the price bar high of the bar when stochs %K is below the 20 and is crossing up through %D and the price bar low when %K is above the 80 and %K is crossing down under the %D.
Any help is greatly appreciated.
wayne
PHP Code:
function preMain() {
setStudyTitle("TEST - Stochastic");
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarFgColor(Color.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarThickness(1, 0);
setDefaultBarThickness(1, 1);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_LINE, 1);
}
var vStochK = null;
var vStochD = null;
var bInit = false;
var vHigh = 0;
var vHigh_1 = 0;
var vLow = 0;
var vLow_1 = 0;
vTrigger = 0;
function main() {
if(bInit == false){
setCursorLabelName("%K ",0)
setCursorLabelName("%D ",1)
setCursorLabelName("H ",2)
setCursorLabelName("H_1 ",3)
setCursorLabelName("L ",4)
setCursorLabelName("L_1 ",5)
if(vStochK==null) vStochK = stochK(14, 3, 3);
vStochK = getSeries(vStochK);
if(vStochD==null) vStochD = stochD(14, 3, 3);
vStochD = getSeries(vStochD);
addBand( 80, PS_SOLID, 1, Color.black,2);
addBand( 20, PS_SOLID, 1, Color.black,3);
}
xHigh = high(0);
xLow = low(0);
xHigh_1 = high(-1);
xLow_1 = low(-1);
if(vStochK.getValue(-1) > vStochD.getValue(-1) && vStochK.getValue(0) < vStochD.getValue(0) && vStochK.getValue(0) > 80){
setBarBgColor(Color.RGB(246, 168, 188)); // light red
vTrigger = 1
}else if(vStochK.getValue(-1) < vStochD.getValue(-1) && vStochK.getValue(0) > vStochD.getValue(0) && vStochK.getValue(0) < 20){
setBarBgColor( Color.RGB(178, 243, 171)); // light green
vTrigger = -1
}else vTrigger = 0;
// if(getBarState() == BARSTATE_NEWBAR){
if(vTrigger == 1){
vHigh = xHigh;
vHigh_1 = xHigh_1;
}
else if(vTrigger == -1){
vLow = xLow;
vLow_1 = xLow_1;
}
else{
vHigh = 0;
vHigh_1 = 0;
vLow = 0;
vLow_1 = 0;
// }
}
return new Array(vStochK,vStochD,vHigh.toFixed(),vHigh_1.toFixed(),vLow.toFixed(),vLow_1.toFixed());
}
Comment