Announcement

Collapse
No announcement yet.

Printing text a certain % of the stock's price above or below the current price

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

  • Printing text a certain % of the stock's price above or below the current price

    I'm having trouble when it comes to printing a text object on my chart. It's not that I am having trouble with the Text showing up. My problem lies in the fact that I want the text to appear a certain percentage either above or below the candle on the chart when the condition is triggered. Currently I have it as follows:

    drawTextRelative(-1, high()+0.10, "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    and

    drawTextRelative(0, low()-0.10, "B", Color.RGB(0,0,255), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    I have it so that the text "S" prints 10cents above the current high of the candle, and the "B" 10cents below the current low of the candle. So as to not interfere or block the view of the candle forming on the chart.

    What I would like to have it do is print the "S" at say 1% of the stock's price above the high of the candle. So that the distance above or below the candle where the text prints is uniform across stocks with very different price ranges. ex. GOOG vs F, or SPY vs ETFC.

    I know there has to be a way to do this but it is driving me crazy. Every time I add a "%" sign into the formula I get a syntax error. For example I would like it to be like this:

    drawTextRelative(-1, high()+1%, "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)


    Can someone please help me figure this out. I trade a bunch of different stocks at very different price levels and sometime the "S" or "B" that pops up is right smack on top of the candle stick in my chart if it is a very high price stock, but if it is a low priced stock say Ford, sym=F then the "S" or "B" that pops up is not even on my chart because it is beyond the scale of the chart.

    There has to be a way to do this so that the "S" or "B" text pops up consistently a certain distance away from the candle stick on the chart regarless if the stock's price is $300 or $3.

    Please help!! Thanks in advance.

  • #2
    Re: Printing text a certain % of the stock's price above or below the current price

    Hi DBBLI,

    Try the following:

    drawTextRelative(-1, 1.01*high(), "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    and

    drawTextRelative(0, 0.99*low(), "B", Color.RGB(0,0,255), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    Bsically you want to multiply the high by (100+your percentage)/100 and the low by (100-your percentage)/100.

    Hope this helps.
    Regards,
    Jane

    Originally posted by DBBLI
    I'm having trouble when it comes to printing a text object on my chart. It's not that I am having trouble with the Text showing up. My problem lies in the fact that I want the text to appear a certain percentage either above or below the candle on the chart when the condition is triggered. Currently I have it as follows:

    drawTextRelative(-1, high()+0.10, "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    and

    drawTextRelative(0, low()-0.10, "B", Color.RGB(0,0,255), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

    I have it so that the text "S" prints 10cents above the current high of the candle, and the "B" 10cents below the current low of the candle. So as to not interfere or block the view of the candle forming on the chart.

    What I would like to have it do is print the "S" at say 1% of the stock's price above the high of the candle. So that the distance above or below the candle where the text prints is uniform across stocks with very different price ranges. ex. GOOG vs F, or SPY vs ETFC.

    I know there has to be a way to do this but it is driving me crazy. Every time I add a "%" sign into the formula I get a syntax error. For example I would like it to be like this:

    drawTextRelative(-1, high()+1%, "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)


    Can someone please help me figure this out. I trade a bunch of different stocks at very different price levels and sometime the "S" or "B" that pops up is right smack on top of the candle stick in my chart if it is a very high price stock, but if it is a low priced stock say Ford, sym=F then the "S" or "B" that pops up is not even on my chart because it is beyond the scale of the chart.

    There has to be a way to do this so that the "S" or "B" text pops up consistently a certain distance away from the candle stick on the chart regarless if the stock's price is $300 or $3.

    Please help!! Thanks in advance.

    Comment


    • #3
      DBBLI
      An alternative [and easier] solution to placing the text in a constant position is to use the location flags AboveBar1, BelowBar1, AboveBar2, BelowBar2, etc [up to 4 levels] which are available for the drawTextRelative() function and also the other drawXxx() functions (see the link to the corresponding article in the EFS KnowledgeBase).
      These flags will place the graphic object at specific locations above or below the price bars irrespective of the price range as you can see in the following screenshot
      Alex

      Comment


      • #4
        Thank you Alex and jg. I tried it jg's way but the formatting still came out kinda weird.

        I think I figured it out.

        Alex, thank you so much for pointing out that KB article. the example I was looking for was all the way at the bottom of the page but it was exactly what I was looking for.

        Thanks for your timely response.

        Brian


        Originally posted by Alexis C. Montenegro
        DBBLI
        An alternative [and easier] solution to placing the text in a constant position is to use the location flags AboveBar1, BelowBar1, AboveBar2, BelowBar2, etc [up to 4 levels] which are available for the drawTextRelative() function and also the other drawXxx() functions (see the link to the corresponding article in the EFS KnowledgeBase).
        These flags will place the graphic object at specific locations above or below the price bars irrespective of the price range as you can see in the following screenshot
        Alex

        Last edited by DBBLI; 01-16-2009, 11:58 AM.

        Comment


        • #5
          Brian
          The location flag is in place of high(0), low(0), etc. Also as indicated in the article I linked in my previous reply when using those location flags you need to add a Text.PRESET flag as shown in the example enclosed below
          Alex

          PHP Code:
          drawTextRelative(-1AboveBar1"S"Color.RGB(255,0,0), Color.RGB(255,255,0), Text.PRESET Text.BOLD"Arial"14); 

          Originally posted by DBBLI
          Thank you Alex and jg. I tried it jg's way but the formatting still came out kinda weird. So I think I want to try it Alex's way using the abovebar/blowbar format.

          Alex is there anyway you can post the code for how I would add Location.BelowBar1 to the line below?

          Would I just add it into the line:

          drawTextRelative(0, low(), "B", Color.RGB(0,0,255), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

          I'm getting formula errors when I add it into the line as follows:

          drawTextRelative(-1, high(), location.AboveBar1, "S", Color.RGB(255,0,0), Color.RGB(255,255,0), Text.BOLD, "Arial", 14)

          I feel like I'm just missing something here.



          Thanks for your timely response.

          Brian

          Comment


          • #6
            Thanks Alex. The Text.PRESET was the issue, I didn't have it in full caps which was needed for it to run correctly. I got it running smoothly now. Thanks a bunch!

            -Brian

            Comment


            • #7
              Brian
              You are most welcome
              Alex


              Originally posted by DBBLI
              Thanks Alex. The Text.PRESET was the issue, I didn't have it in full caps which was needed for it to run correctly. I got it running smoothly now. Thanks a bunch!

              -Brian

              Comment

              Working...
              X