Announcement

Collapse
No announcement yet.

Help with learning to code a my own indicator....

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

  • Help with learning to code a my own indicator....

    Hello...Im new to the forum and to coding...would someone here mind looking at my code and telling me what im doing wrong? thank you in advance for any suggestion.....john

    All i wanted the code to do is compare the most recent bar close to the second most recent bars close ..if the close of the first is greater than the close of its previous bar then it would draw a text above the 5th bar back...if not then draw a text over the first bar....BUT ITS DRAWING A TEXT OVER BOTH BARS!! and i cant figure out why...below is the code and a screen shot...can someone please tell me what im doing wrong

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Bar States");
    setShowCursorLabel(false);
    }

    function main() {


    if (close (-1) > close (-2)) {
    drawTextAbsolute(-5, high(0), "N", Color.blue, null,
    Text.BOLD|Text.TOP|Text.FRAME, null, 7);
    } else {
    drawTextAbsolute(-1, high(0), "N", Color.blue, null,
    Text.BOLD|Text.TOP|Text.FRAME, null, 7) ;
    }
    }
    Attached Files
    Last edited by pleaman2; 12-03-2012, 09:00 PM.

  • #2
    John
    The reason the text is drawn on the previous bar and that of five bars back is because you have set that to occur in your code by using drawTextAbsolute [see the linked article in the EFS KnowledgeBase for the description of the function]
    What happens is that as the formula iterates though the historical bars [while the efs is loading in the chart] it writes the text at the absolute locations of bar -1 and bar -5 at each instance of either condition being true.
    The issue is similar to the one discussed in this thread [albeit for drawLineAbsolute in that case] and the solution is also similar to that given in the the same thread
    Alex


    Originally posted by pleaman2 View Post
    Hello...Im new to the forum and to coding...would someone here mind looking at my code and telling me what im doing wrong? thank you in advance for any suggestion.....john

    All i wanted the code to do is compare the most recent bar close to the second most recent bars close ..if the close of the first is greater than the close of its previous bar then it would draw a text above the 5th bar back...if not then draw a text over the first bar....BUT ITS DRAWING A TEXT OVER BOTH BARS!! and i cant figure out why...below is the code and a screen shot...can someone please tell me what im doing wrong

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Bar States");
    setShowCursorLabel(false);
    }

    function main() {


    if (close (-1) > close (-2)) {
    drawTextAbsolute(-5, high(0), "N", Color.blue, null,
    Text.BOLD|Text.TOP|Text.FRAME, null, 7);
    } else {
    drawTextAbsolute(-1, high(0), "N", Color.blue, null,
    Text.BOLD|Text.TOP|Text.FRAME, null, 7) ;
    }
    }

    Comment


    • #3
      Ohhhhhh...ok Alexis...Now i get it!!! First of all THANK YOU very much for taking the time to respond to my post....secondly i understand exactly what your explaining...Really appreciate your help! now lets see if i can change it to do want i intended it to do ...Thanks again for your time...John
      Last edited by pleaman2; 12-04-2012, 08:39 PM.

      Comment


      • #4
        John
        You are welcome
        Alex


        Originally posted by pleaman2 View Post
        Ohhhhhh...ok Alexis...Now i get it!!! First of all THANK YOU very much for taking the time to respond to my post....secondly i understand exactly what your explaining...Really appreciate your help! now lets see if i can change it to do want i intended it to do ...Thanks again for your time...John

        Comment


        • #5
          Click image for larger version

Name:	capture-20121205-213907.jpg
Views:	1
Size:	97.9 KB
ID:	242822hello Alex...would you mind taking a look at this code I wrote? I wanted the code to look at the most current closed bars (-1) open and subtract its close....Then do the same with its previous bar (-2).....if the first bars (-1) spread is wider than its previous (-2) then draw text above the first (-1) bar, and remain there indefinitely...but it didn't turn out like id hoped...any advice is appreciated...Thank you in advance...john

          function preMain() {
          setPriceStudy(true);
          setStudyTitle("Phase 2");
          setShowCursorLabel(false);
          }
          // determining if the current closed bars spread is greater than its previous
          // bars spread

          function main() {


          if (open (-1) - close (-1) > open (-2) - close (-2)) {
          drawTextRelative(-1, high(0), "n", Color.blue, null,
          Text.BOLD|Text.TOP|Text.FRAME, null, 12);
          }
          }
          Last edited by pleaman2; 12-05-2012, 08:51 PM. Reason: add chart/image

          Comment


          • #6
            John
            In your formula the conditional statement and corresponding command are set to evaluate and execute as follows
            “If the Open of bar(-1) minus the Close of bar(-1) is greater than the Open of bar(-2) minus the Close of bar(-2) then draw the text on bar(-1)”
            Based on your image the result of the calculation on bar(-1) is 0.00008 while that on bar(-2) is -0.0004 hence the value on bar(-1) is greater than that on bar(-2) which you yourself acknowledge in the comments in the image and which is what the efs is correctly indicating on bar(-1) as per the instructions given
            As an aside while you are drawing the text on bar(-1) you are setting the Y-value of that text to the High of bar(0) instead of the High of bar(-1). Additionally you are aligning the top of the text [ie Text.TOP] instead of the bottom [ie Text.BOTTOM] to that High.
            Alex


            Originally posted by pleaman2 View Post
            [ATTACH=CONFIG]16331[/ATTACH]hello Alex...would you mind taking a look at this code I wrote? I wanted the code to look at the most current closed bars (-1) open and subtract its close....Then do the same with its previous bar (-2).....if the first bars (-1) spread is wider than its previous (-2) then draw text above the first (-1) bar, and remain there indefinitely...but it didn't turn out like id hoped...any advice is appreciated...Thank you in advance...john

            function preMain() {
            setPriceStudy(true);
            setStudyTitle("Phase 2");
            setShowCursorLabel(false);
            }
            // determining if the current closed bars spread is greater than its previous
            // bars spread

            function main() {


            if (open (-1) - close (-1) > open (-2) - close (-2)) {
            drawTextRelative(-1, high(0), "n", Color.blue, null,
            Text.BOLD|Text.TOP|Text.FRAME, null, 12);
            }
            }

            Comment


            • #7
              Hello Alex, thank you very much for your time. I see exactly what your explaining. I was sort on the right track, I totally missed the y-axis being set a 0 though. But in a down range it works correctly. The problem occurs when the up bars come in because as you've stated (and i coded) subtracting the open from the close on an up bar returns a negative, unless the spread of the first bar is smaller than the previous. So Alex, im not going to ask you how to fix this problem! Because i genuinely want to learn to code, im going to go back to the books and see if i can decipher the answer on my own...Thank you again for your time and advice, you are appreciated!!! john
              Last edited by pleaman2; 12-06-2012, 07:38 PM.

              Comment


              • #8
                hello Alex....I was able to work out all the other aspects of the code for my indicator, but have run into a problem!..Could you please tell me if there is a function (or anything) that will allow me to code the drawing of fibs?? Thank you in advance for your time... and a BIG Thank You for all the help you gave me, couldnt have done it without your guidence...john

                Comment

                Working...
                X