Coding help: how to plot a bar gradually?

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Coding help: how to plot a bar gradually?

Postby 2haerim » 22 Jun 2009

I am trying to paint a bar in a tick-count chart. For example, 10 tick chart.

I would like to paint the bar(possibly candle) in 10 levels for each tick received. For the 1st tick, I would paint 1/10th of the bar, for 2nd tick, 2/10th of the bar, and so on. For the last 10th tick, the bar would be painted fully. Once the current bar becomes an old one, the painting for that bar should be removed.

I am thinking to use this as an alternative for the Tick counter.

Is this possible? If so, please kindly write a code for this.

Thanks.

HR

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 22 Jun 2009

I got it myself as below. It's the simple and basic, and someone might refine more.

Code: Select all

Var: Level(0);
Level = (h-l)*Ticks/BarInterval;
PlotPaintBar(L+Level ,Low,l,L+Level ,"",Yellow, BarInterval);
NoPlot(1)[1];
NoPlot(2)[1];
NoPlot(3)[1];
NoPlot(4)[1];

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Postby TJ » 22 Jun 2009

PlotPaintBar(h, l, o, c, "p", blue, default, ticks);

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Postby TJ » 22 Jun 2009

I just realized, LineWidth can go beyond 14 !


PlotPaintBar (BarHigh, BarLow, BarOpen, BarClose <,"PlotName"<,PlotColor <,Default <,LineWidth >>>>)


LineWidth
- an optional parameter; specifies the plot line width, ranging from 1 to 14

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 22 Jun 2009

TJ,

thanks for the tips.

But your code does not clearly show when the tick bar will be completed, meanwhile, mine works like level gauge. When the last tick is to received, 9/10th of the bar gets colored yellow, and finally the last tick completely fills the bar with yellow. So, it is easier to know then end of a bar is approaching, I think.

HR

User avatar
TJ
Posts: 6551
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 966 times
Been thanked: 1892 times

Postby TJ » 22 Jun 2009

TJ,

thanks for the tips.

But your code does not clearly show when the tick bar will be completed, meanwhile, mine works like level gauge. When the last tick is to received, 9/10th of the bar gets colored yellow, and finally the last tick completely fills the bar with yellow. So, it is easier to know then end of a bar is approaching, I think.

HR



I posted my simple suggestion before I saw your post.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 22 Jun 2009

A little more refinement.
It now changes color depending on the direction.

Code: Select all

Var: GaugeLevel(0);
GaugeLevel = (h-l)*Ticks/BarInterval;
PlotPaintBar(Low+GaugeLevel,Low,Low,Low+GaugeLevel,"",iff(O>C,Blue,iff(O<C,Red,Yellow)), BarInterval);
NoPlot(1)[1];
NoPlot(2)[1];
NoPlot(3)[1];
NoPlot(4)[1];


Return to “User Contributed Studies and Indicator Library”