Hi,
Everything was working fine with my script until I added the backtest, can you give me any clue what I have done wron from this, I have declared all variables:
//LONG//
if ((vTrend == null && vExitflag == false && vTrendMkds != nCntr)||(vTrendMku == nCntr && vTrend == "long")){
if (close() > HighLinearRegValue && MontDir == "up"){
drawShapeRelative(0, low(), Shape.UPARROW, null, Color.white, Image.ONTOP, "up"+nCntr);
if (vFlag == false){
Alert.playSound("warning.wav");
vFlag = true
}
vTrend = "long"
vTrendMku = nCntr;
vExitflag = true;
Strategy.doLong("Enter Long", Strategy.CLOSE, Strategy.THISBAR);
vTradeTarget = (close() + "Profit Target");
vStopLoss = (close() - "Stop Loss");
}
if (vTrendMku == nCntr && close() < HighLinearRegValue){
removeShape("up"+nCntr);
vTrend = null;
vExitflag = false;
}
}
if ((vTrend == "long" && vExitflag == true)||(vTrendMkus == nCntr && vTrend == null)){
if ((close() < vStopLoss)||(close() > vTradeTarget)) {
drawShapeRelative(0, high(), Shape.CIRCLE, null, Color.white, Image.ONTOP, "exitlong"+nCntr);
if (vFlag == false){
Alert.playSound("breakglass.wav");
vFlag = true
}
vTrend = null
vTrendMkus = nCntr;
vExitflag = false;
Strategy.doCover("Exit Trade", Strategy.CLOSE, Strategy.THISBAR);
}
if (vTrendMkus == nCntr && close() > LinearRegValue){
removeShape("exitlong"+nCntr);
vTrend = "long";
vExitflag = true;
}
}
//SHORT//
if ((vTrend == null && vExitflag == false && vTrendMkus != nCntr)||(vTrendMkd == nCntr && vTrend == "short")){
if (close() < LowLinearRegValue && MontDir == "dn"){
drawShapeRelative(0, high(), Shape.DOWNARROW, null, Color.white, Image.ONTOP, "dn"+nCntr);
if (vFlag == false){
Alert.playSound("warning.wav");
vFlag = true
}
vTrend = "short"
vTrendMkd = nCntr;
vExitflag = true;
Strategy.doShort("Enter Short", Strategy.CLOSE, Strategy.THISBAR);
vTradeTarget = (close() - "Profit Target");
vStopLoss = (close() + "Stop Loss");
}
if (vTrendMkd == nCntr && close() > LowLinearRegValue){
removeShape("dn"+nCntr);
vTrend = null;
vExitflag = false;
}
}
if ((vTrend == "short" && vExitflag == true)||(vTrendMkds == nCntr && vTrend == null)){
if ((close() > vStopLoss)||(close() < vTradeTarget)) {
drawShapeRelative(0, low(), Shape.CIRCLE, null, Color.white, Image.ONTOP, "exitshort"+nCntr);
if (vFlag == false){
Alert.playSound("breakglass.wav");
vFlag = true
}
vTrend = null
vTrendMkds = nCntr;
vExitflag = false;
Strategy.doCover("Exit Trade", Strategy.CLOSE, Strategy.THISBAR);
}
if (vTrendMkds == nCntr && close() < LinearRegValue){
removeShape("exitshort"+nCntr);
vTrend = "short";
vExitflag = true;
}
}
Everything was working fine with my script until I added the backtest, can you give me any clue what I have done wron from this, I have declared all variables:
//LONG//
if ((vTrend == null && vExitflag == false && vTrendMkds != nCntr)||(vTrendMku == nCntr && vTrend == "long")){
if (close() > HighLinearRegValue && MontDir == "up"){
drawShapeRelative(0, low(), Shape.UPARROW, null, Color.white, Image.ONTOP, "up"+nCntr);
if (vFlag == false){
Alert.playSound("warning.wav");
vFlag = true
}
vTrend = "long"
vTrendMku = nCntr;
vExitflag = true;
Strategy.doLong("Enter Long", Strategy.CLOSE, Strategy.THISBAR);
vTradeTarget = (close() + "Profit Target");
vStopLoss = (close() - "Stop Loss");
}
if (vTrendMku == nCntr && close() < HighLinearRegValue){
removeShape("up"+nCntr);
vTrend = null;
vExitflag = false;
}
}
if ((vTrend == "long" && vExitflag == true)||(vTrendMkus == nCntr && vTrend == null)){
if ((close() < vStopLoss)||(close() > vTradeTarget)) {
drawShapeRelative(0, high(), Shape.CIRCLE, null, Color.white, Image.ONTOP, "exitlong"+nCntr);
if (vFlag == false){
Alert.playSound("breakglass.wav");
vFlag = true
}
vTrend = null
vTrendMkus = nCntr;
vExitflag = false;
Strategy.doCover("Exit Trade", Strategy.CLOSE, Strategy.THISBAR);
}
if (vTrendMkus == nCntr && close() > LinearRegValue){
removeShape("exitlong"+nCntr);
vTrend = "long";
vExitflag = true;
}
}
//SHORT//
if ((vTrend == null && vExitflag == false && vTrendMkus != nCntr)||(vTrendMkd == nCntr && vTrend == "short")){
if (close() < LowLinearRegValue && MontDir == "dn"){
drawShapeRelative(0, high(), Shape.DOWNARROW, null, Color.white, Image.ONTOP, "dn"+nCntr);
if (vFlag == false){
Alert.playSound("warning.wav");
vFlag = true
}
vTrend = "short"
vTrendMkd = nCntr;
vExitflag = true;
Strategy.doShort("Enter Short", Strategy.CLOSE, Strategy.THISBAR);
vTradeTarget = (close() - "Profit Target");
vStopLoss = (close() + "Stop Loss");
}
if (vTrendMkd == nCntr && close() > LowLinearRegValue){
removeShape("dn"+nCntr);
vTrend = null;
vExitflag = false;
}
}
if ((vTrend == "short" && vExitflag == true)||(vTrendMkds == nCntr && vTrend == null)){
if ((close() > vStopLoss)||(close() < vTradeTarget)) {
drawShapeRelative(0, low(), Shape.CIRCLE, null, Color.white, Image.ONTOP, "exitshort"+nCntr);
if (vFlag == false){
Alert.playSound("breakglass.wav");
vFlag = true
}
vTrend = null
vTrendMkds = nCntr;
vExitflag = false;
Strategy.doCover("Exit Trade", Strategy.CLOSE, Strategy.THISBAR);
}
if (vTrendMkds == nCntr && close() < LinearRegValue){
removeShape("exitshort"+nCntr);
vTrend = "short";
vExitflag = true;
}
}
Comment