Announcement

Collapse
No announcement yet.

Back test Error

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

  • Back test Error

    hi,

    i have the following problem,
    i program a back testing strategy Parabolic SAR together with RSI and when i backtest, there is no cover or sell, and i think i made something wrong,
    may be someone can help me
    the following is my source code
    thanks,
    alen
    Attached Files

  • #2
    alen
    You are missing Strategy.THISBAR in lines 60 and 69. Also rather than writing
    if (getBarState() == BARSTATE_NEWBAR) {
    if (PSAR != null) {
    PSAR1 = PSAR;
    }
    }

    you can retrieve the prior value of the Parabolic with PSAR1 = study.getValue(ParabolicStudy.STOP,-1);
    Note that I have checked only for errors in the syntax/construct and not in the logic.
    Alex

    Comment


    • #3
      thank you for the tip with the Par SAR value,


      i wrote Strategy.ALL because, while back testing all the previous bars should be sold and not only this bar,

      i think there is an other mistake,
      alen

      Comment


      • #4
        alen
        Strategy.ALL defines the number of contracts/shares not the bar on which the strategy is supposed to execute. You are missing the latter parameter ie Strategy.THISBAR (or NEXTBAR whichever you want to use)
        Alex

        Comment


        • #5
          Alexis C. Montenegro

          oh i see,

          and how can i program while back testing to sell all previous bought bars?

          alen

          Comment


          • #6
            alen
            Unless I am misunderstanding what you are trying to do the problem is elsewhere and specifically that you are going Long/Short multiple times. You may want to try replacing the following in line 112
            if ((RSIStatus == "short") && (PSARStatus == "short")){
            with
            if (!Strategy.isShort() && (RSIStatus == "short") && (PSARStatus == "short")){
            and the following in line 116
            if ((RSIStatus == "long") && (PSARStatus == "long")){
            with
            if (!Strategy.isLong() && (RSIStatus == "long") && (PSARStatus == "long")){
            This will ensure that a Long/Short command will be executed only once ie when the strategy is not already long/short
            Alex

            Comment


            • #7
              Alex
              first of all thank you very much you helped me a lot!

              can you please explain to me what StopOrLimit mean
              f.g. Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), 100);

              in this case 100 is stop, but what does it exactly mean while back testing??
              I read the Becktesting Operations, but I'm not sure that I understand well,

              thank you,
              alen

              Comment


              • #8
                alen
                100 is the price at which the STOP or LIMIT order is executed/filled. The value can be a constant or the value of an indicator (such as for example a moving average that you are using as a stop). However when laying out the strategy you need to check that the price you define as the Stop (or Limit) is actually breached by the range of the bar else the Stretegy Analyzer will use whatever price you input.
                If you run a search for stop AND limit you should find various threads that cover this subject
                Alex

                Comment

                Working...
                X