Announcement

Collapse
No announcement yet.

High function, multiple charts

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

  • High function, multiple charts

    I have a couple questions about the high() function...

    I'm wanting to backtest a breakout futures trading strategy against 2 daily charts simultaneously.

    For instance, I want to go long when the closing price exceeds the high of the previous bar for *both* ZSN9 and QBSN9.

    I'm guessing the condition would be:

    close() >= math.max( high(-1, sym("ZSN9,D")), high(-1, sym("QBSN9,D")))

    1) Would this work?

    2) Is there a way to code this for 2 unspecified charts, so I can just select 2 charts and backtest, rather than having to rewrite the strategy for each specific pair of symbols?

  • #2
    Re: High function, multiple charts

    hprinfi
    1) Other than the fact that syntax for the Math Object would need to be Math.max(...) it should work
    2) Instead of hard coding the symbols make those two user defined variables that you set using the FunctionParameter Object (see the link to the corresponding article in the EFS KnowledgeBase).
    Alex


    Originally posted by hprinfi
    I have a couple questions about the high() function...

    I'm wanting to backtest a breakout futures trading strategy against 2 daily charts simultaneously.

    For instance, I want to go long when the closing price exceeds the high of the previous bar for *both* ZSN9 and QBSN9.

    I'm guessing the condition would be:

    close() >= math.max( high(-1, sym("ZSN9,D")), high(-1, sym("QBSN9,D")))

    1) Would this work?

    2) Is there a way to code this for 2 unspecified charts, so I can just select 2 charts and backtest, rather than having to rewrite the strategy for each specific pair of symbols?

    Comment


    • #3
      Is there a way to avoid hardcoding the symbols if I'm using the Wizard, or would this necessitate coding the whole thing myself?

      Comment


      • #4
        hprinfi
        It is not possible to do this using the Formula Wizard and it would require you to code it yourself
        Alex


        Originally posted by hprinfi
        Is there a way to avoid hardcoding the symbols if I'm using the Wizard, or would this necessitate coding the whole thing myself?

        Comment


        • #5
          Is there any chance you could give me some advice on how to do this? My Java background isn't that great.

          Here's the code that was generated by the Wizard:
          -----------------------------------------

          //{{EFSWizard_Description
          //
          // This formula was generated by the Alert Wizard
          //
          //}}EFSWizard_Description


          //{{EFSWizard_Declarations
          var vLastAlert = -1;
          //}}EFSWizard_Declarations


          function preMain() {
          /**
          * This function is called only once, before any of the bars are loaded.
          * Place any study or EFS configuration commands here.
          */
          //{{EFSWizard_PreMain
          setPriceStudy(true);
          setStudyTitle("Breakout (Simple)");
          //}}EFSWizard_PreMain

          }

          function main() {
          /**
          * The main() function is called once per bar on all previous bars, once per
          * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
          * in your preMain(), it is also called on every tick.
          */

          //{{EFSWizard_Expressions
          //{{EFSWizard_Expression_1
          if (
          Strategy.isLong() == false &&
          close() > high(-1)
          ) onAction1()
          //}}EFSWizard_Expression_1

          //{{EFSWizard_Expression_2
          else if (
          Strategy.isShort() == false &&
          close() < low(-1)
          ) onAction2();
          //}}EFSWizard_Expression_2

          //}}EFSWizard_Expressions


          //{{EFSWizard_Return
          return null;
          //}}EFSWizard_Return

          }

          function postMain() {
          /**
          * The postMain() function is called only once, when the EFS is no longer used for
          * the current symbol (ie, symbol change, chart closing, or application shutdown).
          */
          }

          //{{EFSWizard_Actions
          //{{EFSWizard_Action_1
          function onAction1() {
          if (vLastAlert != 1) Strategy.doLong("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vLastAlert = 1;
          }
          //}}EFSWizard_Action_1

          //{{EFSWizard_Action_2
          function onAction2() {
          if (vLastAlert != 2) Strategy.doShort("", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
          vLastAlert = 2;
          }
          //}}EFSWizard_Action_2

          //}}EFSWizard_Actions


          -----------------------------------------------------------------

          Comment

          Working...
          X