I tried copying this formula from this http://forum.esignal.com/showthread....5&pagenumber=1 thread, and adding the function that Alexis recommended in the main function. My script now looks like this, but I get an error message in line 58 which states that efsInternal is not defined. Does anybody know what that means?
Thanks,
Whinston
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("Opening Range AM");
setCursorLabelName("Range High", 0);
setCursorLabelName("Range Low", 1);
setPlotType(PLOTTYPE_FLATLINES,0);
setPlotType(PLOTTYPE_FLATLINES,1);
setDefaultBarFgColor(Color.black,0);
setDefaultBarFgColor(Color.black,1);
setDefaultBarThickness(4,0);
setDefaultBarThickness(4,1);
setShowTitleParameters(false)
var x=0;
fpArray[x] = new FunctionParameter("xStart", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Start Time");
setLowerLimit(0);
setDefault(930);
}
fpArray[x] = new FunctionParameter("xEnd", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("End Time");
setLowerLimit(0);
setDefault(945);
}
fpArray[x] = new FunctionParameter("xInterval", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Ext Interval Used");
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("xDisplay", FunctionParameter.STRING);
with(fpArray[x++]){
setName("Display");
addOption("Show");
addOption("Hide");
setDefault("Show");
}
}
var bInit = false;
var xRange = null;
var vReturn=0;
function main(xStart,xEnd,xInterval,xDisplay) {
if ( getBarState() == BARSTATE_ALLBARS ) return; // Exit Script if we are loading still
if((hour(0)*100)+minute(0)>1300) return;
vReturn=0;
if(bInit==false){
xRange = efsInternal("calcOR",xStart,xEnd,xDisplay,inv(xInt erval));
bInit=true;
}
//setBarBgColor(Color.RGB(241,255,241), 0, getSeries(xRange,1), getSeries(xRange,0) )
//if ( getBarState() == BARSTATE_NEWBAR && close() > getSeries(xRange,0) ) debugPrintln("We are over opening range");
//if ( getBarState() == BARSTATE_NEWBAR && close() < getSeries(xRange,1) ) debugPrintln("We are BELOW opening range");
return new Array(getSeries(xRange,0),getSeries(xRange,1));
}
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);
}
Thanks,
Whinston
var fpArray = new Array();
function preMain() {
setPriceStudy(true);
setStudyTitle("Opening Range AM");
setCursorLabelName("Range High", 0);
setCursorLabelName("Range Low", 1);
setPlotType(PLOTTYPE_FLATLINES,0);
setPlotType(PLOTTYPE_FLATLINES,1);
setDefaultBarFgColor(Color.black,0);
setDefaultBarFgColor(Color.black,1);
setDefaultBarThickness(4,0);
setDefaultBarThickness(4,1);
setShowTitleParameters(false)
var x=0;
fpArray[x] = new FunctionParameter("xStart", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Start Time");
setLowerLimit(0);
setDefault(930);
}
fpArray[x] = new FunctionParameter("xEnd", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("End Time");
setLowerLimit(0);
setDefault(945);
}
fpArray[x] = new FunctionParameter("xInterval", FunctionParameter.NUMBER);
with(fpArray[x++]){
setName("Ext Interval Used");
setLowerLimit(1);
setDefault(3);
}
fpArray[x] = new FunctionParameter("xDisplay", FunctionParameter.STRING);
with(fpArray[x++]){
setName("Display");
addOption("Show");
addOption("Hide");
setDefault("Show");
}
}
var bInit = false;
var xRange = null;
var vReturn=0;
function main(xStart,xEnd,xInterval,xDisplay) {
if ( getBarState() == BARSTATE_ALLBARS ) return; // Exit Script if we are loading still
if((hour(0)*100)+minute(0)>1300) return;
vReturn=0;
if(bInit==false){
xRange = efsInternal("calcOR",xStart,xEnd,xDisplay,inv(xInt erval));
bInit=true;
}
//setBarBgColor(Color.RGB(241,255,241), 0, getSeries(xRange,1), getSeries(xRange,0) )
//if ( getBarState() == BARSTATE_NEWBAR && close() > getSeries(xRange,0) ) debugPrintln("We are over opening range");
//if ( getBarState() == BARSTATE_NEWBAR && close() < getSeries(xRange,1) ) debugPrintln("We are BELOW opening range");
return new Array(getSeries(xRange,0),getSeries(xRange,1));
}
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