Announcement

Collapse
No announcement yet.

HELP! Backtest EFS open of candle & close of candle

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

  • HELP! Backtest EFS open of candle & close of candle

    Hello,

    I was wondering if some could help me create a Backtesting EFS formula (i can't program anything for the life of me) that would open a trade (long/short) at the open of a candle bar and close the position on the close of candle bar (good for any time frame). I particular trade the s&p eminis.

    Your help would be greatly appreciated.

    Thankfully....PC

  • #2
    PC
    If you post what the conditions are then someone may be able to help.
    Alex

    Comment


    • #3
      PC, hope this helps. Regards, Andy


      function preMain() {
      setPriceStudy(true);
      setStudyTitle("Strategy");

      }

      function main() {
      var vHL = high() - low();
      var vVar = vHL * 0.25;
      var vAddVar = vVar * 0.35;
      var i = 0;


      if(!Strategy.isLong() //&& your buy condition){
      Strategy.doLong("Long", Strategy.OPEN, Strategy.NEXTBAR);
      drawShapeRelative(0, low() - vVar, Shape.UPARROW, "", Color.lime, null, "buyShp" + getValue("time"));
      drawTextRelative(-1, low() - (vVar + vAddVar), "Buy", Color.black, Color.lime, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
      }

      if(!Strategy.isShort() //&& your sell condition){
      Strategy.doShort("Short", Strategy.CLOSE, Strategy.THISBAR);
      drawShapeRelative(0, high() + vVar, Shape.DOWNARROW, "", Color.red, null, "sellShp" + getValue("time"));
      drawTextRelative(-1, high() + (vVar + vAddVar), "Sell", Color.black, Color.red, Text.BOTTOM | Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
      }

      return;
      }

      Comment


      • #4
        Thanks!

        Andy,

        Thanks for all your help it is greatly appreciated.

        I tried running the efs formula but i get the following error:

        SyntaxError: missing ) after condition: Strategy.doLong("Long", Strategy.OPEN, Strategy.NEXTBAR);

        Please advise.

        Thanks again for everything....PC

        by the way here are the conditions:

        enter long if candle opens above previous candle's close.

        enter short if candle opens below previous candles's close.

        Comment


        • #5
          You have the opening brace, {, inside a comment

          function preMain() {
          setPriceStudy(true);
          setStudyTitle("Strategy");

          }

          function main() {
          var vHL = high() - low();
          var vVar = vHL * 0.25;
          var vAddVar = vVar * 0.35;
          var i = 0;


          if(!Strategy.isLong() { //&& your buy condition)
          Strategy.doLong("Long", Strategy.OPEN, Strategy.NEXTBAR);
          drawShapeRelative(0, low() - vVar, Shape.UPARROW, "", Color.lime, null, "buyShp" + getValue("time"));
          drawTextRelative(-1, low() - (vVar + vAddVar), "Buy", Color.black, Color.lime, Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
          }

          if(!Strategy.isShort() { //&& your sell condition)
          Strategy.doShort("Short", Strategy.CLOSE, Strategy.THISBAR);
          drawShapeRelative(0, high() + vVar, Shape.DOWNARROW, "", Color.red, null, "sellShp" + getValue("time"));
          drawTextRelative(-1, high() + (vVar + vAddVar), "Sell", Color.black, Color.red, Text.BOTTOM | Text.BOLD | Text.ONTOP, null, null, "buyTxt" + getValue("time"));
          }

          return;
          }

          Comment


          • #6
            PC
            Enclosed is the formula for the strategy outlined by you.
            If the open is higher than the prior close the system paints the bar in blue and goes long at the open. If the open is lower than the prior close the system paints the bar in red and goes short.
            Either trade is liquidated on the close of the same bar.
            Alex

            PHP Code:
            function preMain() {
            setPriceStudy(true);
            setStudyTitle("OneBar Strategy"); 
            setShowCursorLabel(false);
            setColorPriceBars(true);
            setDefaultPriceBarColor(Color.black);

            }

            function 
            main() {


            if(!
            Strategy.isLong() && open()>close(-1)){
            setPriceBarColor(Color.blue);
            Strategy.doLong("Long"Strategy.MARKETStrategy.THISBAR);
            }

            if(!
            Strategy.isShort() && open()<close(-1)){
            setPriceBarColor(Color.red);
            Strategy.doShort("Short"Strategy.MARKETStrategy.THISBAR);
            }

            if(
            Strategy.isLong()==true){
            Strategy.doSell("Sell",Strategy.CLOSE,Strategy.THISBAR);
            }
            if(
            Strategy.isShort()==true){
            Strategy.doCover("Cover",Strategy.CLOSE,Strategy.THISBAR);
            }

            return;

            Comment

            Working...
            X