I've researched all the backtesting tutorials on the Esignal forums and am having trouble resetting the entry orders for when my limit price doesn't fill. I also cannot seem to figure out why a couple graphic lines don't produce the expected results.
Anybody who is good with Esignal code? Your help will be greatly appreciated.
Sincerely,
Kirk
Code: Select all
var vEMA8 = new MAStudy(8, 0, "Close", MAStudy.EXPONENTIAL);
var vMid_1 = null;
var vLastAlert = -1;
var bLongSetup = false;
var bLongFilled = false;
var bLongNotFilled = false;
var bLongTargetHit = false;
var bLongStopHit = false;
var vTargetPrice = null;
var vLastAlert = -1;
function preMain() {
setPriceStudy(true);
setStudyTitle("test reset");
setCursorLabelName("ma", 0);
setCursorLabelName("entry", 1);
setCursorLabelName("target", 2);
setDefaultBarStyle(PS_SOLID, 0);
setDefaultBarStyle(PS_SOLID, 1);
setDefaultBarStyle(PS_SOLID, 2);
setDefaultBarFgColor(Color.red, 0);
setDefaultBarFgColor(Color.blue, 1);
setDefaultBarFgColor(Color.green, 2);
setDefaultBarThickness(2, 0);
setDefaultBarThickness(3, 1);
setDefaultBarThickness(3, 2);
setPlotType(PLOTTYPE_LINE, 0);
setPlotType(PLOTTYPE_FLATLINES, 1);
setPlotType(PLOTTYPE_FLATLINES, 2);
}
function main() {
vMid_1 = Math.round((((high(-1)-low(-1))*.5)+low(-1))*10)/10;
vTargetPrice = vMid_1 + 1.0;
if (vMid_1 == null) return;
//LONG SETUP
if (
close(-1) > vEMA8.getValue(MAStudy.MA, -1) &&
close() > vEMA8.getValue(MAStudy.MA)
) {
if(
bLongSetup != true &&
bLongFilled != true
) {
///*if (vLastAlert != 1)*/ setBarBgColor(Color.RGB(0,128,18));
bLongSetup = true;
//vMid_1 = Math.round((((high(-1)-low(-1))*.5)+low(-1))*10)/10;
drawTextRelative(0,low()-1.5,"LONGSETUP",Color.black,Color.lime,Text.ONTOP | Text.VCENTER |
Text.CENTER|Text.BOLD | Text.ITALIC,"Arial",8,getValue("rawtime") + "LS1a" );
vLastAlert = 1;
}
} else {
vMid_1 = null;
vTargetPrice = null;
}
//TEST FOR LONG FILL
if (
bLongSetup == true &&
bLongFilled != true
) {
vMid_1 = Math.round((((high(-1)-low(-1))*.5)+low(-1))*10)/10;
vTargetPrice = vMid_1 + 1.0;
if(
low(0) < vMid_1 &&
high(0) > vMid_1
) {
///*if (vLastAlert != 2)*/ setBarBgColor(Color.RGB(160,255,160));
bLongFilled = true;
drawTextRelative(0,low()-1.5,"LONG",Color.white,Color.green,Text.ONTOP | Text.VCENTER |
Text.CENTER|Text.BOLD | Text.ITALIC,"Arial",8,getValue("rawtime") + "L1a" );
vLastAlert = 2;
} else if (
(low() > vMid_1 ||
high() < vMid_1)
) {
///*if (vLastAlert != 3)*/ setBarBgColor(Color.RGB(160,160,164));
vLastAlert = 3;
bLongNotFilled = true;
}
}
//SETUP STILL TRUE, NOT YET FILLED
if (
bLongSetup == true &&
bLongFilled != true &&
bLongNotFilled == true
) {
vMid_1 = Math.round((((high(-1)-low(-1))*.5)+low(-1))*10)/10;
vTargetPrice = vMid_1 + 1.0;
if(
low(0) < vMid_1 &&
high(0) > vMid_1
) {
///*if (vLastAlert != 2)*/ setBarBgColor(Color.RGB(160,255,160));
bLongFilled = true;
} else {
bLongNotFilled = true;
}
}
debugClear();
debugPrintln("vLastAlert "+vLastAlert );
debugPrintln("vMid_1 "+vMid_1 );
debugPrintln("bLongTargetHit "+bLongTargetHit );
debugPrintln("bLongNotFilled "+bLongNotFilled );
debugPrintln("bLongFilled "+bLongFilled );
debugPrintln("bLongSetup "+bLongSetup );
if ( bLongSetup == true && bLongFilled != true && bLongNotFilled != true) {setBarBgColor(Color.RGB(0,128,18));}
if ( bLongSetup != true && bLongFilled == true && bLongNotFilled != true) {setBarBgColor(Color.RGB(160,255,160));drawTextRelative(0,low()-1.5,"LONG",Color.white,Color.green,Text.ONTOP | Text.VCENTER |
Text.CENTER|Text.BOLD | Text.ITALIC,"Arial",8,getValue("rawtime") + "L1f" );}
if ( bLongSetup != true && bLongFilled != true && bLongNotFilled == true) {setBarBgColor(Color.RGB(160,160,164));}
return new Array(
vEMA8.getValue(MAStudy.MA),
vMid_1,
vTargetPrice
);
}