Announcement

Collapse
No announcement yet.

Simple Indicator on price basis

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

  • Simple Indicator on price basis

    Hi all,
    I have to admit that I'm fairly new to esignal and I'm doing my first steps with the java script software.

    I was trying to establish a simple indicator which shows me a simple triangle in the chart when the statment (eg close > close 1) is true. I've tried it with the wizard but seems not to work. Here is what I tried:

    //
    //}}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("");
    setCursorLabelName("FAKE LONG FDAX", 5);
    setDefaultBarStyle(PS_SOLID,5);
    setDefaultBarFgColor(Color.blue,5);
    setDefaultBarThickness(2, 0);
    setPlotType(PLOTTYPE_SQUARE, 5);
    //}}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 (
    close(1) < low(2) &&
    close > high(1)
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return ;
    //}}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, low(), Shape.TRIANGLE, "", Color.RGB(155,0,0), Shape.LEFT, "Fake Long");
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions

    Somebody got an idea about that?
    Regards
    Volker

  • #2
    Re: Simple Indicator on price basis

    Volker
    If your condition is that the Close of the prior bar is lower than the Low of two bars ago and the Close of the current bar is greater than the High of the prior bar then you need to change the Offset of each of those prices to a negative number eg close(-1) instead of close(1) as you currently have it in your script.
    Positive numbers reference the bars following to the one being processed while negative number reference the previous bars.
    Alex





    Originally posted by thecrow2
    Hi all,
    I have to admit that I'm fairly new to esignal and I'm doing my first steps with the java script software.

    I was trying to establish a simple indicator which shows me a simple triangle in the chart when the statment (eg close > close 1) is true. I've tried it with the wizard but seems not to work. Here is what I tried:

    //
    //}}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("");
    setCursorLabelName("FAKE LONG FDAX", 5);
    setDefaultBarStyle(PS_SOLID,5);
    setDefaultBarFgColor(Color.blue,5);
    setDefaultBarThickness(2, 0);
    setPlotType(PLOTTYPE_SQUARE, 5);
    //}}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 (
    close(1) < low(2) &&
    close > high(1)
    ) onAction1();
    //}}EFSWizard_Expression_1

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return ;
    //}}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, low(), Shape.TRIANGLE, "", Color.RGB(155,0,0), Shape.LEFT, "Fake Long");
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //}}EFSWizard_Actions

    Somebody got an idea about that?
    Regards
    Volker

    Comment


    • #3
      Second issue same problem

      The same as before but this time I wanted to create a pop up alarm for the same condition:

      "close(1) < low(2)"

      still not works as I have tried the following:

      //{{EFSWizard_Description
      //
      // This formula was generated on the Alert Wizard by Kobus Lotter
      //
      //}}EFSWizard_Description
      var vLastAlert = -1;

      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("Fake 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
      //{{EFSWizard_Expression_1
      if (
      close(1) < low(2)
      ) onAction1()
      //}}EFSWizard_Expression_1




      //{{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) Alert.playSound("Chime Down.wav");
      vLastAlert = 1;
      if (vLastAlert != 1) Alert.addToList("FDAX", "Fake Long", Color.green, Color.black);
      vLastAlert = 1;
      }


      //}}EFSWizard_Actions

      Any ideas are welcome. You may want to use this setup adding the following condition to and add it to your trend following setups: Close > High 1
      Regards
      Volker

      Comment


      • #4
        Re: Re: Simple Indicator on price basis

        hi Alex,
        thx for the quick reply but still does not work with me. Does it work on your machine?
        Volker

        Originally posted by Alexis C. Montenegro
        Volker
        If your condition is that the Close of the prior bar is lower than the Low of two bars ago and the Close of the current bar is greater than the High of the prior bar then you need to change the Offset of each of those prices to a negative number eg close(-1) instead of close(1) as you currently have it in your script.
        Positive numbers reference the bars following to the one being processed while negative number reference the previous bars.
        Alex

        Comment


        • #5
          Volker,

          what you posted wasn't changed per Alex's post.

          Make those changes and where it says "chime down", change to pop

          try that and repost your results.

          Kirk

          Comment


          • #6
            Re: Re: Re: Simple Indicator on price basis

            Volker
            Yes it does (see screenshot below). Note however that because in the drawShapeRelative() function you are using the same tagName for all graphic objects drawn by that command only one (and specifically the last) triangle will be drawn.
            In order to draw a triangle on each event you need to change the tagName to something that will be unique to each graphical object such as for example the name plus the bar count which you can get using the getCurrentBarCount() function (see the example enclosed below)
            Alex






            Originally posted by thecrow2
            hi Alex,
            thx for the quick reply but still does not work with me. Does it work on your machine?
            Volker

            Comment


            • #7
              Re: Re: Re: Re: Simple Indicator on price basis

              thx Alex,
              better now but returns me only one triangle (in my case fot the fdax) but we had a couple of them today. I've changed the formula to the following:

              //
              //}}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("");
              //}}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 (
              close(-1) < low(-2) &&
              close() > high(-1)
              ) 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, low(), Shape.TRIANGLE, "", Color.RGB(155,0,0), Shape.LEFT, "Fake Long FDAX",getCurrentBarCount());
              vLastAlert = 1;
              }
              //}}EFSWizard_Action_1

              //}}EFSWizard_Actions

              Sorry, bur I'm still far away from being perfect on the java script. using easy language before with tradesignal was a little bit easier. Any ways, still appreciating your help.
              Volker

              Originally posted by Alexis C. Montenegro
              Volker
              Yes it does (see screenshot below). Note however that because in the drawShapeRelative() function you are using the same tagName for all graphic objects drawn by that command only one (and specifically the last) triangle will be drawn.
              In order to draw a triangle on each event you need to change the tagName to something that will be unique to each graphical object such as for example the name plus the bar count which you can get using the getCurrentBarCount() function (see the example enclosed below)
              Alex



              Comment


              • #8
                Re: Re: Re: Re: Re: Simple Indicator on price basis

                Volker
                You are only getting one triangle because in your script the tagName is still common to all graphic objects being drawn.
                This is because the tagName is
                drawShapeRelative(...,"Fake Long FDAX",getCurrentBarCount());
                instead of
                drawShapeRelative(...,"Fake Long FDAX"+getCurrentBarCount());
                as I showed in my previous reply
                Once you make that change you will get a triangle on each event
                Alex





                Originally posted by thecrow2
                thx Alex,
                better now but returns me only one triangle (in my case fot the fdax) but we had a couple of them today. I've changed the formula to the following:

                //
                //}}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("");
                //}}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 (
                close(-1) < low(-2) &&
                close() > high(-1)
                ) 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, low(), Shape.TRIANGLE, "", Color.RGB(155,0,0), Shape.LEFT, "Fake Long FDAX",getCurrentBarCount());
                vLastAlert = 1;
                }
                //}}EFSWizard_Action_1

                //}}EFSWizard_Actions

                Sorry, bur I'm still far away from being perfect on the java script. using easy language before with tradesignal was a little bit easier. Any ways, still appreciating your help.
                Volker

                Comment


                • #9
                  Re: Re: Re: Re: Re: Re: Simple Indicator on price basis

                  yeah,
                  great stuff! thx for your patience. did you have a look to one with the alert? I'm not quite sure if zellers comment was the only mistake. Will there be somewhere a alert list. I know that with the usual alerts you get something like a list. Will this also happen with my personal alert.

                  this is what I have after the change:
                  //{{EFSWizard_Description
                  //
                  // This formula was generated on the Alert Wizard by Kobus Lotter
                  //
                  //}}EFSWizard_Description
                  var vLastAlert = -1;

                  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("Fake 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
                  //{{EFSWizard_Expression_1
                  if (
                  close(-1) < low(-2)
                  ) onAction1()
                  //}}EFSWizard_Expression_1




                  //{{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) Alert.pop("Fake");
                  vLastAlert = 1;
                  if (vLastAlert != 1) Alert.addToList("FDAX", "Fake Long", Color.green, Color.black);
                  vLastAlert = 1;
                  }


                  //}}EFSWizard_Actions


                  Originally posted by Alexis C. Montenegro
                  Volker
                  You are only getting one triangle because in your script the tagName is still common to all graphic objects being drawn.
                  This is because the tagName is
                  drawShapeRelative(...,"Fake Long FDAX",getCurrentBarCount());
                  instead of
                  drawShapeRelative(...,"Fake Long FDAX"+getCurrentBarCount());
                  as I showed in my previous reply
                  Once you make that change you will get a triangle on each event
                  Alex

                  Comment


                  • #10
                    Volker
                    As it is written the formula will trigger an alert one time only and specifically the first time that the event occurs after which it will no longer trigger any alerts. This is because in your conditions you have selected to trigger an alert "...while the following will happen only the first time".
                    In order to accomplish this the Formula Wizard creates a flag which the formula engine uses to determine which actions have been performed. When a condition evaluates to true the formula engine checks the state of this flag which tells it whether that action has already been performed or not. If not then the formula engine performs the action and sets the flag to some other state so that the action is only performed once.
                    At this point the formula engine needs some other event to reset the flag to a state that tells it that the next time your condition is true it can go ahead and perform the action.
                    In your script you have only one Set (ie conditional statement) which means that there is no other condition that can change the state of that flag hence no further alerts will be triggered even if your condition will subsequently evaluate to true.
                    In order to resolve this you need to add another condition (ie Set2) in which you check for some event that happens once every bar so that the formula engine can reset the flag. To do this you can use the getBarState() function which has a state (ie BARSTATE_NEWBAR) that tells the formula engine that a new bar has been formed on the chart.
                    So in your formula you need to add a Set2 that is defined as in the screenshot enclosed below. This condition will evaluate to true on the first tick of every bar and in doing so it will reset the flag.
                    After you have implemented this modification save the formula with a different name then open both the original and this one using the Editor so that you can compare them and see how the code changed.
                    If you are unfamiliar with programming in efs and are interested in learning you may want to start by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
                    Hope this helps
                    Alex




                    Originally posted by thecrow2
                    yeah,
                    great stuff! thx for your patience. did you have a look to one with the alert? I'm not quite sure if zellers comment was the only mistake. Will there be somewhere a alert list. I know that with the usual alerts you get something like a list. Will this also happen with my personal alert.

                    this is what I have after the change:
                    //{{EFSWizard_Description
                    //
                    // This formula was generated on the Alert Wizard by Kobus Lotter
                    //
                    //}}EFSWizard_Description
                    var vLastAlert = -1;

                    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("Fake 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
                    //{{EFSWizard_Expression_1
                    if (
                    close(-1) < low(-2)
                    ) onAction1()
                    //}}EFSWizard_Expression_1




                    //{{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) Alert.pop("Fake");
                    vLastAlert = 1;
                    if (vLastAlert != 1) Alert.addToList("FDAX", "Fake Long", Color.green, Color.black);
                    vLastAlert = 1;
                    }


                    //}}EFSWizard_Actions

                    Comment

                    Working...
                    X