help with %change labels on chart

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
aczk
Posts: 71
Joined: 08 Feb 2012
Has thanked: 8 times
Been thanked: 1 time

help with %change labels on chart

Postby aczk » 23 May 2012

Hi wonder if anyone got this:

On a daily chart, text labels that appear above for example the Friday bar that show the percentage change value in price since Monday for each week.

thx & appreciate any feedback!

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: help with %change labels on chart

Postby piranhaxp » 26 May 2012

Here one simple code (not tested that much). I'm sure there are better solutions. No comparison for Monday is a trading day or not included. You can find the Suri's trading day func here to implement it (http://www.bigmiketrading.com/148803-post6.html). Test it and play a little bit with it.
input: Txt.Pos.Color(darkgreen), Txt.Neg.Color(red), Txt.Flat.Color(black);
input: Track.Diff.Open(1), Track.Diff.Close(0);
input: Txt.Adj(5), Txt.Size(8);

var: mo.open(0), mo.close(0), fr.close(0);
var: perc.chg(0);
var: txt.color(0),txt.id(0), txt.diff("");


if dayofweek(date) = 0 then // reset numbers on Sunday to (0)
begin
mo.open = 0;
mo.close = 0;
fr.close = 0;
end;


if dayofweek(date) = 1 then // begin to track open/close on Monday (1)
begin
mo.open = open;
mo.close = close;
end;

if dayofweek(date) = 5 then // begin calculation and "plot" text on Friday
begin
fr.close = close;
// tracking difference monday's open to friday's close
if track.diff.open = 1 then
begin
//calculation difference monday's open to friday's close
if mo.open <> 0 then perc.chg = ((fr.close - mo.open)*100)/mo.open;
txt.diff = " O: " + numtostr(perc.chg,2) + "%"; // text to "plot"
// comparison of difference for text color statement
if perc.chg > 0 then txt.color = txt.pos.color else // show color when diff is positive (>0)
if perc.chg < 0 then txt.color = txt.neg.color else // show color when diff is negative (<0)
if perc.chg = 0 then txt.color = txt.flat.color; // show color when diff is flat (=0)
// text in chart
txt.id = text_new( date, time[0], h + txt.adj, txt.diff);
text_setstyle( txt.id,2,1 );
text_setcolor( txt.id,txt.color);
end;

// tracking difference monday's open to friday's close
if track.diff.close = 1 then
begin
if mo.close <> 0 then perc.chg = ((fr.close - mo.close)*100)/mo.close; // calculation difference monday's close to friday's close
txt.diff = " C: " + numtostr(perc.chg,2) + "%"; // text to "plot"
// comparison of difference for text color statement
if perc.chg > 0 then txt.color = txt.pos.color else // show color when diff is positive (>0)
if perc.chg < 0 then txt.color = txt.neg.color else // show color when diff is negative (<0)
if perc.chg = 0 then txt.color = txt.flat.color; // show color when diff is flat (=0)
// text in chart
txt.id = text_new( date, time[0], h + txt.adj, txt.diff);
text_setstyle( txt.id,2,1 );
text_setcolor( txt.id,txt.color);
end;
// plot1(perc.chg, "%Chg");
end;
Image

Stefan aka "SP" has a nice solution for text_plotting with IFF-statement in the forum. Code looks not nice with this QUOTE func in this forum so the overview may is not that nice.

My regards.

Mike
Attachments
Code_%ChgMoToFR.png
(54.2 KiB) Downloaded 1041 times

User avatar
piranhaxp
Posts: 241
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 30 times

Re: help with %change labels on chart

Postby piranhaxp » 03 Jun 2012

@ACZK

Helpful or not ?

aczk
Posts: 71
Joined: 08 Feb 2012
Has thanked: 8 times
Been thanked: 1 time

Re: help with %change labels on chart

Postby aczk » 03 Jun 2012

yep...this is great!

thx


Return to “User Contributed Studies and Indicator Library”