Announcement

Collapse
No announcement yet.

Everything was going well until Backtest

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Everything was going well until Backtest

    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;
    }
    }

  • #2
    You didn't say what went wrong when you tried to run this, but one thing I do see is the following:

    vTradeTarget = (close() + "Profit Target");

    will result in vTradeTarget being converted to a string and having a value something like "1191ProfitTarget" which, when compared to a numeric value later will either produce an error or provide an erroneous result (not sure which as I've never attempted this in javascript).

    Comment


    • #3
      You were quite right, that was what it did, I have fixed that now.

      But I am just getting spurious problems with the entire script, sometimes it prints exits and entries and sometimes not. It has now started shifting the entire 'return array' at the end to one side so it bears to resemblence to the prices.

      I think its in a bit of a mess and could do with some help here, all I want to do is print entries and exits and have it backtested

      Apologies for the code now, I am no programmer !

      Attached, if anybody can assist I would be grateful.
      Last edited by rogerha; 02-10-2005, 04:58 AM.

      Comment

      Working...
      X