Announcement

Collapse
No announcement yet.

Draw Text in efs studies

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

  • Draw Text in efs studies

    I am interested in seeing text with the current value as an output on a given study eg. If I use a moving average in the efs study customMA.efs, I would like to see the words "MA" and the length and interval as an output on the chart just above or near the MA line.

    Something like 20-SMA-D (20 period MA for daily interval.

    I tired to modify the efs with drawText line but nothing happened.

    I added line 73 in the efs below. Would appreciate if anybody can help.

    PHP Code:
    drawText("Length MA Interval"Color.redText.BOLD|Text.FRAME|Text.CENTER"MA"); 

  • #2
    CutomMA.efs I modified is attached

    Attached to this message is the modified customMA.efs
    Attached Files

    Comment


    • #3
      Picture of what I would like to see

      I added the text on the chart, but when I change the symbol the text disappears, so if I could add the text as part of the efs, it will be there even if I change the symbol.

      AK
      Attached Files

      Comment


      • #4
        I found partial answer

        Well I figured out some of the stuff and now I would like it to be next to the Line instead of where it is. How can I do it.

        I used this

        PHP Code:
         drawTextAbsolute(2,xMA"MA = " +xMAColor.fushcianullText.FRAME Text.TOP Text.BOLD"Arial"12"MA"); 
        How can I get it next to the line
        Attached Files

        Comment


        • #5
          akiri
          Replace your line of code with the following one
          PHP Code:
          drawTextAbsolute(2xMA.getValue(0), "MA = " +xMA.getValue(0), Color.fushcianull,
                          
          Text.FRAME Text.VCENTER Text.BOLD"Arial"12"MA"); 
          Then move the line of code outside of the bInit routine insering it just above the return statement.
          The result should be as shown in the enclosed screenshot
          Alex

          Comment


          • #6
            Adding 2 more items to the Text

            Thanks Alexis, I had figured out removing the line out of the loop same time u posted here.

            Now is it possible to Add the Parameters length and interval to the label. So its can show for example

            20 period Daily MA = 1455 or 20 D MA = 1455

            10 period 60 min MA = 1432 etc

            Thanks.

            I tired adding getInterval() and or vSymbol but that does not do the trick

            AK

            PS This is the first time I started medling with programming, so do not fully understand how this works, but I will work on it

            Comment


            • #7
              AK
              In your drawTextAbsolute(...) function replace the text parameter ie "MA = " +xMA.getValue(0) with
              Length+" "+Type+" "+(Interval==null?getInterval():Interval)+" = "+xMA.getValue(0)
              The result of this change is shown in the enclosed image
              If you are unfamiliar with programming in efs and are interested in learning then the best way to do that is to review the JavaScript for EFS videos 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.
              Alex

              Comment


              • #8
                Perfect Picture Changes with Time

                Thank you Alexis, I am right now trying to learn thru searches and examples, and later in the year When I have more time to I will try learning in a systematic fashion

                I modified the efs and also added a rounding to 2 digits, using Steve' Library, as he claims in a previous post that it is a faster method of rounding.

                Any way I also modified the custom PSAR.efs too, so I could get my perfect picture which is shown here
                Attached Files

                Comment


                • #9
                  Perfect Picture Changes with time

                  The perfect picutre changes with time

                  The modified code in the AKcustomMA.efs is
                  PHP Code:
                  drawTextAbsolute(2xMA.getValue(0).round2(), Length" "+Type+" "+
                                  (
                  Interval==null?getInterval():Interval)+"=" +xMA.getValue(0).round2(), 
                                  
                  Color.fushcianullText.FRAME Text.VCENTER Text.BOLD"Arial"12"MA"); 
                  and in the AKcustomPSAR.efs is
                  PHP Code:
                  drawTextAbsolute(2xPSAR.getValue(0).round2(), (Interval==null?getInterval():Interval)+
                                  
                  "-PSAR = " +xPSAR.getValue(0).round2(), Color.blacknull,
                                  
                  Text.FRAME Text.VCENTER |  Text.BOLD"Arial"12"PSAR"); 
                  But when I change the time from 60 min to say W I get an error.
                  Is it the code or is it cause I am using same efs multiple times in the same chart.
                  Attached Files

                  Comment


                  • #10
                    Files Attached

                    And This what the Formula Output says.
                    Attached Files

                    Comment


                    • #11
                      The modified files

                      I have been trying to do multiple time frame MA, PSAR and other stuff, in a single intraday chart, but also would like the ability to change time frames without getting errors. If the label is next to the object drawn it makes it easier to know what time frame it represents.

                      I have attached the files here, if anybody would like to take a stab at it.

                      Thanks -AK
                      Attached Files

                      Comment


                      • #12
                        The other File

                        The other file attached.


                        Is there a way to attach multiple files in a single message, I could not do it, so multiple messages.
                        Attached Files

                        Comment


                        • #13
                          AK
                          That error is happening because while the study is priming it is returning null which is not a valid value for the rounding function.
                          To correct this you need to perform a null check on the value prior to modifying any of its properties. Add the following line before the drawTextAbsolute(...) command and you will no longer get an error (this example refers to ak customma.efs - replace the variable name with the appropriate one for other studies)
                          if(xMA.getValue(0)==null) return;
                          Alex

                          Comment


                          • #14
                            Hello,
                            In the example what does (Interval==null?getInterval():Interval) mean?
                            Thank you in advance
                            Raffaele

                            Comment


                            • #15
                              Raffaele
                              That is called a Ternary operator and is a one line conditional statement. In that specific context it checks if the value of the functionParameter "Interval" is null in which case it uses the chart interval else it uses the value set in the functionParameter. Here is another example of the use of this operator
                              PHP Code:
                              close(0)>open(0)?x=close(0);x=open(0); 
                              is the same as writing
                              PHP Code:
                              if(close(0)>open(0){
                                  
                              close(0);
                              } else {
                                  
                              open(0);

                              For more information on the Ternary operator see this article in the EFS KnowledgeBase
                              Alex

                              Comment

                              Working...
                              X