Announcement

Collapse
No announcement yet.

referencing a symbol within an EFS formula

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

  • referencing a symbol within an EFS formula

    I'm trying to add $TRIN in a formula, but am getting a Reference Error.

    Example: ($TRIN/2)

    Is this the correct way to reference the value for $TRIN?
    I tried quotes, etc, etc.

    Thank you in advance for any help.

  • #2
    var trin;
    ...
    trin = close(0, sym("$TRIN"));

    Comment


    • #3
      Thanks. BUT, where do I place the specific code? I attached what I have now BUT I am getting "ReferenceError: $TRIN is not defined"

      //{{EFSWizard_Declarations
      var vLastAlert = -1;
      var TRIN;
      var TRINQ;
      var ADV;
      var ADVQ;
      var DECL;
      var DECLQ;

      //}}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("SHEHU LONG");

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

      TRIN=close(0,sym("$TRIN"));
      TRINQ=close(0,sym("$TRINQ"));
      ADV=close(0,sym("$ADV"));
      ADVQ=close(0,sym("$ADVQ"));
      DECL=close(0,sym("$DECL"));
      DECLQ=close(0,sym("$DECLQ"));

      //{{EFSWizard_Expression_1
      if (
      ($TRIN+$TRINQ)/2 < 1 &&
      ((($ADV+$ADVQ)/2)-(($DECL+$DECLQ)/2)) > 0
      ) onAction1();
      //}}EFSWizard_Expression_1

      //}}EFSWizard_Expressions


      //{{EFSWizard_Return
      return null;

      Comment


      • #4
        You define the variables:
        "TRIN" for the close of $TRIN,
        "TRINQ" for the close of $TRINQ, etc.

        Yet you use "$TRIN + $TRINQ" etc. in your calculations instead of the variables you created.

        Just remove the "$" from your conditional statement as I did below.
        PHP Code:
        (TRIN+TRINQ)/&&
        (((
        ADV+ADVQ)/2)-((DECL+DECLQ)/2)) > 0

        You can't use the symbol because it just identifies the instrument. The values used in calculations are the open, high, low, close, etc, or calculations based on values derived from the symbol's price action.

        Wayne
        Last edited by waynecd; 03-03-2011, 10:14 PM.

        Comment


        • #5
          Thank - I'm there!

          For education pruposes, this type of thing cannot be done using the Formula Wizard - correct? (I do not see a way to declare the variables using the Wizard.)

          One more thing: the signal only shows on the current bar, but I want it to stick to preceeding bars where the condition was met.

          (Using the wizard) This is what I have noted as my visual display:

          //{{EFSWizard_Actions
          //{{EFSWizard_Action_1
          function onAction1() {
          drawShapeRelative(0, high(), Shape.UPARROW, "", Color.RGB(0,0,255), Shape.TOP, "long");
          vLastAlert = 1;
          }
          //}}EFSWizard_Action_1

          //}}EFSWizard_Actions

          Comment


          • #6
            by coding outside the Wizard, my code does not open in the Wizard.

            So I am at the mercy of coding! What I posted was generated by the Wizard when I started my EFS in there.

            Like I wrote, the signal only appears on the current bar - and not on any preceeding bars. (Where I know the condition to have been true).

            It must be something simple, hopefully someone else will step in to help. Here is what I have:


            //{{EFSWizard_Declarations
            var vLastAlert = -1;
            var TRIN;
            var TRINQ;
            var ADV;
            var ADVQ;
            var DECL;
            var DECLQ;

            //}}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("SHEHU LONG");

            //}}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.
            */

            TRIN=close(0,sym("$TRIN"));
            TRINQ=close(0,sym("$TRINQ"));
            ADV=close(0,sym("$ADV"));
            ADVQ=close(0,sym("$ADVQ"));
            DECL=close(0,sym("$DECL"));
            DECLQ=close(0,sym("$DECLQ"));


            //{{EFSWizard_Expressions



            //{{EFSWizard_Expression_1
            if (
            (TRIN+TRINQ)/2 < 1 &&
            (((ADV+ADVQ)/2)-((DECL+DECLQ)/2)) > 0
            ) onAction1();
            //}}EFSWizard_Expression_1

            //}}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() {
            drawShapeRelative(0, high(), Shape.UPARROW, "", Color.RGB(0,0,255), Shape.TOP, "long");
            vLastAlert = 1;
            }
            //}}EFSWizard_Action_1

            //}}EFSWizard_Actions

            Comment


            • #7
              uhehs

              Like I wrote, the signal only appears on the current bar - and not on any preceeding bars. (Where I know the condition to have been true).
              See this or this post for an explanation of why this is happening and a way to resolve it
              Alex


              Originally posted by uhehs
              by coding outside the Wizard, my code does not open in the Wizard.

              So I am at the mercy of coding! What I posted was generated by the Wizard when I started my EFS in there.

              Like I wrote, the signal only appears on the current bar - and not on any preceeding bars. (Where I know the condition to have been true).

              It must be something simple, hopefully someone else will step in to help. Here is what I have:


              //{{EFSWizard_Declarations
              var vLastAlert = -1;
              var TRIN;
              var TRINQ;
              var ADV;
              var ADVQ;
              var DECL;
              var DECLQ;

              //}}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("SHEHU LONG");

              //}}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.
              */

              TRIN=close(0,sym("$TRIN"));
              TRINQ=close(0,sym("$TRINQ"));
              ADV=close(0,sym("$ADV"));
              ADVQ=close(0,sym("$ADVQ"));
              DECL=close(0,sym("$DECL"));
              DECLQ=close(0,sym("$DECLQ"));


              //{{EFSWizard_Expressions



              //{{EFSWizard_Expression_1
              if (
              (TRIN+TRINQ)/2 < 1 &&
              (((ADV+ADVQ)/2)-((DECL+DECLQ)/2)) > 0
              ) onAction1();
              //}}EFSWizard_Expression_1

              //}}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() {
              drawShapeRelative(0, high(), Shape.UPARROW, "", Color.RGB(0,0,255), Shape.TOP, "long");
              vLastAlert = 1;
              }
              //}}EFSWizard_Action_1

              //}}EFSWizard_Actions

              Comment


              • #8
                DONE - thank you.

                Comment

                Working...
                X