Hi,
I have hit a mental block, I am new to efs and have attached my code so far.
I have tried to add a daily reset to the bInit routine of the bLong1, bLong 2... variables but have managed to stop the code giving me any trades at all! I have since removed this but it is still not giving me any trades. Any help debugging this would be great!
When it was working, the strategy would enter the first buy, the second buy and the third buy and exit at the exit signal correctly, but then it would not enter at the first buy level the next day because the bLong1 variable was still true. Any tips on the best way to code the variables to reset each day would be great as well,
thanks in advance
//*********************
function preMain() {
var aFPArray = new Array();
setPriceStudy(true);
setCursorLabelName("TodayOpen");
var x=0;
aFPArray[x] = new FunctionParameter("UserTime", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Start Time For Open (2300)");
setLowerLimit(0);
setUpperLimit(2400);
setDefault(100);
}
aFPArray[x] = new FunctionParameter("LineLen", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Line Length");
setLowerLimit(1);
setDefault(200);
}
aFPArray[x] = new FunctionParameter("Res1", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res1");
setLowerLimit(0);
setDefault(.5);
}
aFPArray[x] = new FunctionParameter("Res2", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res2");
setLowerLimit(0);
setDefault(.75);
}
aFPArray[x] = new FunctionParameter("Res3", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res3");
setLowerLimit(0);
setDefault(1);
}
aFPArray[x] = new FunctionParameter("Res4", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res4");
setLowerLimit(0);
setDefault(1.25);
}
aFPArray[x] = new FunctionParameter("Sup1", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup1");
setLowerLimit(0);
setDefault(.5);
}
aFPArray[x] = new FunctionParameter("Sup2", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup2");
setLowerLimit(0);
setDefault(.75);
}
aFPArray[x] = new FunctionParameter("Sup3", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup3");
setLowerLimit(0);
setDefault(1);
}
aFPArray[x] = new FunctionParameter("Sup4", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup4");
setLowerLimit(0);
setDefault(1.5);
}
aFPArray[x] = new FunctionParameter("TodayOnly", FunctionParameter.BOOLEAN);
with(aFPArray[x++]){
setDefault(true);
}
aFPArray[x] = new FunctionParameter("PriceOffset", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Price Offset");
setLowerLimit(0);
setDefault(3);
}
aFPArray[x] = new FunctionParameter("plotPrice", FunctionParameter.STRING);
with(aFPArray[x++]){
setName("Plot Price At");
addOption("Open Only");
addOption("Open & Res1");
addOption("Res1 & Res2 & Res3");
addOption("Res1 & Res2 & Res3 & Res4")
setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");
}
}
var nPrice=0;
var bLong1 = null;
var bLong2 = null;
var bLong3 = null;
var bLong4 = null;
var bShort1 = null;
var bShort2 = null;
var bShort3 = null;
var bShort4 = null;
var bInit = false;
function main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup 2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset) {
var xOpen = LineTag = null;
if(TodayOnly) LineTag = 105;
else LineTag = gID();
if(isMonthly() || isWeekly() || isDaily()) return;
if((hour(0)*100)+minute(0)==UserTime){
nPrice = open(0);
drawLineRelative( 0, open(0)+Res1, LineLen, open(0)+Res1, PS_DOT, 1, Color.yellow, "Up"+LineTag );
drawLineRelative( 0, open(0)+Res2, LineLen, open(0)+Res2, PS_DOT, 1, Color.green, "Up1"+LineTag );
drawLineRelative( 0, open(0)+Res3, LineLen, open(0)+Res3, PS_DOT, 1, Color.red, "Up2"+LineTag );
drawLineRelative( 0, open(0)+Res4, LineLen, open(0)+Res4, PS_DOT, 2, Color.red, "Up3"+LineTag );
drawLineRelative( 0, open(0)-Sup1, LineLen, open(0)-Sup1, PS_DOT, 1, Color.yellow, "Dwn1"+LineTag );
drawLineRelative( 0, open(0)-Sup2, LineLen, open(0)-Sup2, PS_DOT, 1, Color.green, "Dwn2"+LineTag );
drawLineRelative( 0, open(0)-Sup3, LineLen, open(0)-Sup3, PS_DOT, 1, Color.red, "Dwn3"+LineTag );
drawLineRelative( 0, open(0)-Sup4, LineLen, open(0)-Sup4, PS_DOT, 2, Color.red, "Dwn4"+LineTag );
drawLineRelative( 0, open(0), LineLen, open(0), PS_SOLID, 1, Color.blue, "OpenMid"+LineTag );
}
//Start of Strategy Object
if (getCurrentBarIndex() == 0) return;
if (bInit == false) {
var bLong1 = false;
var bLong2 = false;
var bLong3 = false;
var bLong4 = false;
var bShort1 = false;
var bShort2 = false;
var bShort3 = false;
var bShort4 = false;
bInit = true;
}
//Exit Signals
if (Strategy.isInTrade() == true) {
if (Strategy.isShort() == true) {
if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false) {
if (low(0)< nPrice && low(-1)>= nPrice) {
nExitPrice = nPrice;
Strategy.doCover("Cover Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false) {
if (low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1) {
nExitPrice = nPrice+Res1;
Strategy.doCover("Cover Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false) {
if (low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2) {
nExitPrice = nPrice+Res2;
Strategy.doCover("Cover Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true) {
if (low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3) {
nExitPrice = nPrice+Res3;
Strategy.doCover("Cover Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
}
} else if (Strategy.isLong() == true) {
if (bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice && high(-1)<= nPrice) {
nExitPrice = nPrice;
Strategy.doSell("Sell Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1) {
nExitPrice = nPrice-Sup1;
Strategy.doSell("Sell Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
if (high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2) {
nExitPrice = nPrice-Sup2;
Strategy.doSell("Sell Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true) {
if (high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3) {
nExitPrice = nPrice-Sup3;
Strategy.doSell("Sell Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
}
}
// Entry Short Signals
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1) {
nEntryPrice = nPrice+Res1;
Strategy.doShort("Entry Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort1 = true;
}
} if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2) {
nEntryPrice = nPrice+Res2;
Strategy.doShort("Entry Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort2 = true;
}
} if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3) {
nEntryPrice = nPrice+Res3;
Strategy.doShort("Entry Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort3 = true;
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4) {
nEntryPrice = nPrice+Res4;
Strategy.doShort("Entry Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort4 = true;
}
//Entry Long Signals
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1) {
nEntryPrice = nPrice-Sup1;
Strategy.doLong("Entry Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong1 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2) {
nEntryPrice = nPrice-Sup2;
Strategy.doLong("Entry Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong2 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3) {
nEntryPrice = nPrice-Sup3;
Strategy.doLong("Entry Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong3 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
if (low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4) {
nEntryPrice = nPrice-Sup4;
Strategy.doLong("Entry Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong4 = true;
}
}
if(plotPrice.indexOf("Open")!=-1) drawTextRelative(PriceOffset, nPrice, nPrice, Color.blue, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP");
if(plotPrice.indexOf("Res1")!=-1){
drawTextRelative(PriceOffset, nPrice+Res1, nPrice+Res1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_H");
if(plotPrice.indexOf("Res2")!=-1)
drawTextRelative(PriceOffset, nPrice+Res2, nPrice+Res2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_K");
if(plotPrice.indexOf("Res3")!=-1)
drawTextRelative(PriceOffset, nPrice+Res3, nPrice+Res3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_L");
if(plotPrice.indexOf("Res4")!=-1)
drawTextRelative(PriceOffset, nPrice+Res4, nPrice+Res4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_M");
if(plotPrice.indexOf("Sup1")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup1, nPrice-Sup1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_N");
if(plotPrice.indexOf("Sup2")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup2, nPrice-Sup2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_O");
if(plotPrice.indexOf("Sup3")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup3, nPrice-Sup3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_P");
if(plotPrice.indexOf("Sup4")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup4, nPrice-Sup4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_Q");
}
}
var grID = 0;
function gID() {
grID ++;
return( grID );
}
I have hit a mental block, I am new to efs and have attached my code so far.
I have tried to add a daily reset to the bInit routine of the bLong1, bLong 2... variables but have managed to stop the code giving me any trades at all! I have since removed this but it is still not giving me any trades. Any help debugging this would be great!
When it was working, the strategy would enter the first buy, the second buy and the third buy and exit at the exit signal correctly, but then it would not enter at the first buy level the next day because the bLong1 variable was still true. Any tips on the best way to code the variables to reset each day would be great as well,
thanks in advance
//*********************
function preMain() {
var aFPArray = new Array();
setPriceStudy(true);
setCursorLabelName("TodayOpen");
var x=0;
aFPArray[x] = new FunctionParameter("UserTime", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Start Time For Open (2300)");
setLowerLimit(0);
setUpperLimit(2400);
setDefault(100);
}
aFPArray[x] = new FunctionParameter("LineLen", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Line Length");
setLowerLimit(1);
setDefault(200);
}
aFPArray[x] = new FunctionParameter("Res1", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res1");
setLowerLimit(0);
setDefault(.5);
}
aFPArray[x] = new FunctionParameter("Res2", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res2");
setLowerLimit(0);
setDefault(.75);
}
aFPArray[x] = new FunctionParameter("Res3", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res3");
setLowerLimit(0);
setDefault(1);
}
aFPArray[x] = new FunctionParameter("Res4", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Res4");
setLowerLimit(0);
setDefault(1.25);
}
aFPArray[x] = new FunctionParameter("Sup1", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup1");
setLowerLimit(0);
setDefault(.5);
}
aFPArray[x] = new FunctionParameter("Sup2", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup2");
setLowerLimit(0);
setDefault(.75);
}
aFPArray[x] = new FunctionParameter("Sup3", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup3");
setLowerLimit(0);
setDefault(1);
}
aFPArray[x] = new FunctionParameter("Sup4", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Sup4");
setLowerLimit(0);
setDefault(1.5);
}
aFPArray[x] = new FunctionParameter("TodayOnly", FunctionParameter.BOOLEAN);
with(aFPArray[x++]){
setDefault(true);
}
aFPArray[x] = new FunctionParameter("PriceOffset", FunctionParameter.NUMBER);
with(aFPArray[x++]){
setName("Price Offset");
setLowerLimit(0);
setDefault(3);
}
aFPArray[x] = new FunctionParameter("plotPrice", FunctionParameter.STRING);
with(aFPArray[x++]){
setName("Plot Price At");
addOption("Open Only");
addOption("Open & Res1");
addOption("Res1 & Res2 & Res3");
addOption("Res1 & Res2 & Res3 & Res4")
setDefault("Open & Res1 & Res2 & Res3 & Res4 & Sup1 & Sup2 & Sup3 & Sup4");
}
}
var nPrice=0;
var bLong1 = null;
var bLong2 = null;
var bLong3 = null;
var bLong4 = null;
var bShort1 = null;
var bShort2 = null;
var bShort3 = null;
var bShort4 = null;
var bInit = false;
function main(UserTime,LineLen,Res1,Res2,Res3,Res4,Sup1,Sup 2,Sup3,Sup4,TodayOnly,plotPrice,PriceOffset) {
var xOpen = LineTag = null;
if(TodayOnly) LineTag = 105;
else LineTag = gID();
if(isMonthly() || isWeekly() || isDaily()) return;
if((hour(0)*100)+minute(0)==UserTime){
nPrice = open(0);
drawLineRelative( 0, open(0)+Res1, LineLen, open(0)+Res1, PS_DOT, 1, Color.yellow, "Up"+LineTag );
drawLineRelative( 0, open(0)+Res2, LineLen, open(0)+Res2, PS_DOT, 1, Color.green, "Up1"+LineTag );
drawLineRelative( 0, open(0)+Res3, LineLen, open(0)+Res3, PS_DOT, 1, Color.red, "Up2"+LineTag );
drawLineRelative( 0, open(0)+Res4, LineLen, open(0)+Res4, PS_DOT, 2, Color.red, "Up3"+LineTag );
drawLineRelative( 0, open(0)-Sup1, LineLen, open(0)-Sup1, PS_DOT, 1, Color.yellow, "Dwn1"+LineTag );
drawLineRelative( 0, open(0)-Sup2, LineLen, open(0)-Sup2, PS_DOT, 1, Color.green, "Dwn2"+LineTag );
drawLineRelative( 0, open(0)-Sup3, LineLen, open(0)-Sup3, PS_DOT, 1, Color.red, "Dwn3"+LineTag );
drawLineRelative( 0, open(0)-Sup4, LineLen, open(0)-Sup4, PS_DOT, 2, Color.red, "Dwn4"+LineTag );
drawLineRelative( 0, open(0), LineLen, open(0), PS_SOLID, 1, Color.blue, "OpenMid"+LineTag );
}
//Start of Strategy Object
if (getCurrentBarIndex() == 0) return;
if (bInit == false) {
var bLong1 = false;
var bLong2 = false;
var bLong3 = false;
var bLong4 = false;
var bShort1 = false;
var bShort2 = false;
var bShort3 = false;
var bShort4 = false;
bInit = true;
}
//Exit Signals
if (Strategy.isInTrade() == true) {
if (Strategy.isShort() == true) {
if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false) {
if (low(0)< nPrice && low(-1)>= nPrice) {
nExitPrice = nPrice;
Strategy.doCover("Cover Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false) {
if (low(0)< nPrice+Res1 && low(-1)>= nPrice+Res1) {
nExitPrice = nPrice+Res1;
Strategy.doCover("Cover Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false) {
if (low(0)< nPrice+Res2 && low(-1)>= nPrice+Res2) {
nExitPrice = nPrice+Res2;
Strategy.doCover("Cover Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == true) {
if (low(0)< nPrice+Res3 && low(-1)>= nPrice+Res3) {
nExitPrice = nPrice+Res3;
Strategy.doCover("Cover Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, BelowBar2, Color.green);
}
}
} else if (Strategy.isLong() == true) {
if (bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice && high(-1)<= nPrice) {
nExitPrice = nPrice;
Strategy.doSell("Sell Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice-Sup1 && high(-1)<= nPrice-Sup1) {
nExitPrice = nPrice-Sup1;
Strategy.doSell("Sell Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
if (high(0)> nPrice-Sup2 && high(-1)<= nPrice-Sup2) {
nExitPrice = nPrice-Sup2;
Strategy.doSell("Sell Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
} if (bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == true) {
if (high(0)> nPrice-Sup3 && high(-1)<= nPrice-Sup3) {
nExitPrice = nPrice-Sup3;
Strategy.doSell("Sell Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nExitPrice);
drawShape(Shape.DIAMOND, AboveBar2, Color.green);
}
}
}
// Entry Short Signals
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res1 && high(-1)<= nPrice+Res1) {
nEntryPrice = nPrice+Res1;
Strategy.doShort("Entry Short1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort1 = true;
}
} if (bShort1 == true && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res2 && high(-1)<= nPrice+Res2) {
nEntryPrice = nPrice+Res2;
Strategy.doShort("Entry Short2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort2 = true;
}
} if (bShort1 == true && bShort2 == true && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res3 && high(-1)<= nPrice+Res3) {
nEntryPrice = nPrice+Res3;
Strategy.doShort("Entry Short3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort3 = true;
}
} if (bShort1 == true && bShort2 == true && bShort3 == true && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (high(0)> nPrice+Res4 && high(-1)<= nPrice+Res4) {
nEntryPrice = nPrice+Res4;
Strategy.doShort("Entry Short4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.DOWNARROW, AboveBar2, Color.red);
bShort4 = true;
}
//Entry Long Signals
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == false && bLong2 == false && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup1 && low(-1)>= nPrice-Sup1) {
nEntryPrice = nPrice-Sup1;
Strategy.doLong("Entry Long1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong1 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == false && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup2 && low(-1)>= nPrice-Sup2) {
nEntryPrice = nPrice-Sup2;
Strategy.doLong("Entry Long2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong2 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == false && bLong4 == false) {
if (low(0)< nPrice-Sup3 && low(-1)>= nPrice-Sup3) {
nEntryPrice = nPrice-Sup3;
Strategy.doLong("Entry Long3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong3 = true;
}
} if (bShort1 == false && bShort2 == false && bShort3 == false && bShort4 == false && bLong1 == true && bLong2 == true && bLong3 == true && bLong4 == false) {
if (low(0)< nPrice-Sup4 && low(-1)>= nPrice-Sup4) {
nEntryPrice = nPrice-Sup4;
Strategy.doLong("Entry Long4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.DEFAULT, nEntryPrice);
drawShape(Shape.UPARROW, BelowBar2, Color.blue);
bLong4 = true;
}
}
if(plotPrice.indexOf("Open")!=-1) drawTextRelative(PriceOffset, nPrice, nPrice, Color.blue, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP");
if(plotPrice.indexOf("Res1")!=-1){
drawTextRelative(PriceOffset, nPrice+Res1, nPrice+Res1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_H");
if(plotPrice.indexOf("Res2")!=-1)
drawTextRelative(PriceOffset, nPrice+Res2, nPrice+Res2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_K");
if(plotPrice.indexOf("Res3")!=-1)
drawTextRelative(PriceOffset, nPrice+Res3, nPrice+Res3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_L");
if(plotPrice.indexOf("Res4")!=-1)
drawTextRelative(PriceOffset, nPrice+Res4, nPrice+Res4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_M");
if(plotPrice.indexOf("Sup1")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup1, nPrice-Sup1, Color.yellow, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_N");
if(plotPrice.indexOf("Sup2")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup2, nPrice-Sup2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_O");
if(plotPrice.indexOf("Sup3")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup3, nPrice-Sup3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_P");
if(plotPrice.indexOf("Sup4")!=-1)
drawTextRelative(PriceOffset, nPrice-Sup4, nPrice-Sup4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_Q");
}
}
var grID = 0;
function gID() {
grID ++;
return( grID );
}
Comment