Announcement

Collapse
No announcement yet.

Atr

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

  • Atr

    Hi, i want to calculate a study, based on the ATR. Think, it`s a simple question(for you, not for me):

    I don`t want to plot the ATR, but the result of

    ATR(10)*Close()*200


    How to change the Indikator formular?

    By Alexis C. Montenegro for eSignal © December 2004


    /************************************************** *******
    By Alexis C. Montenegro for eSignal © December 2004
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ATR");
    setCursorLabelName("ATR", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    }

    function main() {

    return atr(14);
    }

  • #2
    Hello Bügeleisen,

    You're closer than you might think. Try changing the return statement to the following.

    PHP Code:
    function main() {

        return 
    atr(10)*close(0)*200;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Originally posted by JasonK
      Hello Bügeleisen,

      You're closer than you might think. Try changing the return statement to the following.

      PHP Code:
      function main() {

          return 
      atr(10)*close(0)*200;

      Thank you!! Quick answer!

      Is it possible to show the last result of the indikator, instead of plotting the line, to plot the number above the last quote on the right side? Into the quote chart?
      Regards

      Comment


      • #4
        Hello Bügeleisen,

        You're most welcome.

        EFS does not currently interact with the quote window. However, you can display a text label on the chart to the right of the price bars using the drawTextRelative() function. Set your study to a price study with setPriceStudy(true) in preMain. Then for the drawText function, use 1 or 2 for the bar index parameter, which will draw the text to the right of the price bars. You could use close(0) for the yValue parameter. Pass your custom atr calculation to the text parameter. Lastly, specify a fixed string for the tagID parameter so that only one label will be drawn. You will do this before the return statement in main() and you will also need to remove your atr calc from the return statement so that it does not plot the line. Give it a try and if you have any trouble, post your code.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Hi,
          i have tried it:
          Now the code draws "ATR(10)*200 , not the result of the "ATR(10)*200.
          Above the bar, ok, but: Every bar, not only the last bar
          What`s wrong?
          Thanks


          /************************************************** *******
          By Alexis C. Montenegro for eSignal © December 2004
          Use and/or modify this code freely. If you redistribute it
          please include this and/or any other comment blocks and a
          description of any changes you make.
          ************************************************** ********/

          function preMain() {

          setPriceStudy(true);
          setStudyTitle("ATR");


          }

          function main() {

          drawTextRelative( 0, AboveBar1, "ATR(10)*200", Color.red, null, Text.PRESET | Text.BOLD, null, 12 );
          return;
          }

          Comment


          • #6
            Bügeleisen

            Now the code draws "ATR(10)*200 , not the result of the "ATR(10)*200
            That is happening because you enclosed the equation in quotes which makes it a text string. Remove the quotes and you will get the result of the equation written on the chart. Note that the equation should be atr(10)*200 and not ATR(10)*200

            Every bar, not only the last bar
            As Jason suggested you need to also specify a fixed string as the TagID parameter so that only one instance of the text will be written (ie the last one). Replace the command line with the one enclosed below
            Alex

            PHP Code:
            drawTextRelative0AboveBar1atr(10)*200Color.rednullText.PRESET Text.BOLDnull12"text" ); 

            Comment


            • #7
              Thanks.
              A new problem: If the result is e.g. "245", there`s only the first "2" drawn on the right side obove the bar. What`s happens there?

              Comment


              • #8
                Bugeleisen
                Please post the code you are using and also provide details about the symbol and interval on which you are running the script.
                Alex

                Comment


                • #9
                  Hi, after restart it was ok. Thank you.
                  Another question: How to round up the result to a whole decimal place?
                  thanks

                  Comment


                  • #10
                    Bugeleisen
                    To do that you would use the .toFixed(nn) method where nn is the number of decimals you want to display
                    For example (atr(10)*200).toFixed(2) will return 2 decimals
                    Alex

                    Comment


                    • #11
                      Thanks a lot.
                      Is it possible to change the color of the result number or the backround of the number?
                      eg.
                      if (atr(10)*200).toFixed(2)<=5 draw blue
                      if (atr(10)*200).toFixed(2)>5 and <= 10 draw yellow
                      if (atr(10)*200).toFixed(2)> 10 draw green

                      ?

                      Comment


                      • #12
                        Bügeleisen
                        To do what you want you need to first create two local variables (ie inside main) called for example myValue and myColor to which you assign the value of your equation and a default color
                        PHP Code:
                        var myValue = (atr(10)*200).toFixed(2);
                        var 
                        myColor Color.black
                        Once you have done that you can write your conditions using the variable myValue. For each condition you then assign the appropriate color to the variable myColor (see the example below). For a list of colors see this article in the EFS KnowledgeBase.
                        PHP Code:
                        if (myValue<=5myColor Color.blue;
                        if (
                        myValue>&& myValue <= 10)  myColor Color.yellow;
                        if (
                        myValue> ....) myColor = ....;
                        //etc 
                        Then inside the drawTextRelative() command replace the equation and the color with myValue and myColor.
                        As you seem to have been using eSignal for a while you may find it to your benefit to learn how to program in efs as that will considerably increase your ability to make full use of the program. If you are interested then you may want to start by reviewing the JavaScript for EFS video series. That 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.
                        Alex

                        Comment


                        • #13
                          Hi, i have added a bgcolor in the code. Now i get the message:
                          Line 28 Parameter number 10 of funktion drawTextRelative is invalid.
                          Do you know, what`s wrong?



                          function preMain() {

                          setPriceStudy(true);
                          setStudyTitle("ATR");



                          }

                          function main() {
                          var myValue = ((1/atr(10)).toFixed(2))*100;
                          var myColor = Color.black;
                          var mybgColor = Color.black;
                          if (myValue<=7) myColor = Color.aqua;
                          if (myValue<=7) mybgColor = bgColor.teal;
                          if (myValue>7 && myValue <= 18) myColor = Color.olive;
                          if (myValue>7 && myValue <= 18) mybgColor = bgColor.green;
                          if (myValue>18) myColor = myColor = Color.navy;
                          if (myValue>18) myColor = mybgColor = bgColor.blue;

                          ( Line 28) drawTextRelative( 0, AboveBar1, myValue , mybgColor, myColor, null, Text.PRESET | Text.BOLD, null, 14, "text" );
                          return;
                          }

                          Comment


                          • #14
                            Does drawTextRelative have 10 parameters? I think it may have only nine. You may have an extra Null in there.

                            Comment


                            • #15
                              0?

                              I have only added

                              "mybgColor," in the line.

                              Comment

                              Working...
                              X