Hi
I'm not a great backtester. Could anyone help me create a backtest of this strategy?!
var lastrawtime = 0;
var BarCount = 0;
var vLastAlert = -1;
var vFlag0 = 1;
var vFlag1 = 0;
function preMain() {
setPriceStudy(true);
setStudyTitle("Long/Short");
setShowCursorLabel(false);
}
function main() {
if(lastrawtime != getValue("rawtime", 0)){
BarCount += 1;
lastrawtime = getValue("rawtime", 0);
}
if(getBarState()==BARSTATE_NEWBAR){
vFlag1 = vFlag0;
}
if(vFlag0==-1&&open()<low(-2)&&close()>=low(-2)||vFlag0==-1&&low()>=low(-2)&&close()>high(-1)){
if(vLastAlert!=1)drawShapeRelative(0, low(0), Shape.UPTRIANGLE, "", Color.blue,null,"Up"+ BarCount);
}else{
removeShape("Up"+BarCount);
}
if(vFlag0==1&&open()>high(-2)&&close()<=high(-2)||vFlag0==1&&high()<=high(-2)&&close()<low(-1)){
if(vLastAlert!=2)drawShapeRelative(0, high(0), Shape.DOWNTRIANGLE, "", Color.red,null,"Dn"+ BarCount);
}else{
removeShape("Dn"+BarCount);
}
if(getBarState()==BARSTATE_NEWBAR){
if(vFlag1==-1&&open(-1)<low(-3)&&close(-1)>=low(-3)||vFlag1==-1&&low(-1)>=low(-3)&&close(-1)>high(-2)){
drawShapeRelative(-1, low(-1), Shape.UPTRIANGLE, "", Color.blue,null,"Up"+ BarCount);
Alert.playSound("long.wav");
//Alert.addToList(getSymbol()+" "+getInterval(),"LongStop",Color.black,Color.green );
vFlag0 = 1;
vLastAlert = 1;
}
if(vFlag1==1&&open(-1)>high(-3)&&close(-1)<=high(-3)||vFlag1==1&&high(-1)<=high(-3)&&close(-1)<low(-2)){
drawShapeRelative(-1, high(-1), Shape.DOWNTRIANGLE, "", Color.red,null,"Dn"+ BarCount);
Alert.playSound("short.wav");
//Alert.addToList(getSymbol()+" "+getInterval(),"ShortStop",Color.black,Color.red) ;
vFlag0 = -1;
vLastAlert = 2;
}
}
return null;
I'm not a great backtester. Could anyone help me create a backtest of this strategy?!
var lastrawtime = 0;
var BarCount = 0;
var vLastAlert = -1;
var vFlag0 = 1;
var vFlag1 = 0;
function preMain() {
setPriceStudy(true);
setStudyTitle("Long/Short");
setShowCursorLabel(false);
}
function main() {
if(lastrawtime != getValue("rawtime", 0)){
BarCount += 1;
lastrawtime = getValue("rawtime", 0);
}
if(getBarState()==BARSTATE_NEWBAR){
vFlag1 = vFlag0;
}
if(vFlag0==-1&&open()<low(-2)&&close()>=low(-2)||vFlag0==-1&&low()>=low(-2)&&close()>high(-1)){
if(vLastAlert!=1)drawShapeRelative(0, low(0), Shape.UPTRIANGLE, "", Color.blue,null,"Up"+ BarCount);
}else{
removeShape("Up"+BarCount);
}
if(vFlag0==1&&open()>high(-2)&&close()<=high(-2)||vFlag0==1&&high()<=high(-2)&&close()<low(-1)){
if(vLastAlert!=2)drawShapeRelative(0, high(0), Shape.DOWNTRIANGLE, "", Color.red,null,"Dn"+ BarCount);
}else{
removeShape("Dn"+BarCount);
}
if(getBarState()==BARSTATE_NEWBAR){
if(vFlag1==-1&&open(-1)<low(-3)&&close(-1)>=low(-3)||vFlag1==-1&&low(-1)>=low(-3)&&close(-1)>high(-2)){
drawShapeRelative(-1, low(-1), Shape.UPTRIANGLE, "", Color.blue,null,"Up"+ BarCount);
Alert.playSound("long.wav");
//Alert.addToList(getSymbol()+" "+getInterval(),"LongStop",Color.black,Color.green );
vFlag0 = 1;
vLastAlert = 1;
}
if(vFlag1==1&&open(-1)>high(-3)&&close(-1)<=high(-3)||vFlag1==1&&high(-1)<=high(-3)&&close(-1)<low(-2)){
drawShapeRelative(-1, high(-1), Shape.DOWNTRIANGLE, "", Color.red,null,"Dn"+ BarCount);
Alert.playSound("short.wav");
//Alert.addToList(getSymbol()+" "+getInterval(),"ShortStop",Color.black,Color.red) ;
vFlag0 = -1;
vLastAlert = 2;
}
}
return null;
Comment