Add Wingdings-Text next to Close Price for indicate up/down trend

Hi I would like to have an Up Thumb when up trend
and Down Thumb when down trend,
But the result is both icon appear
How can I fix it?

Many Thanks!

aasa

Plot(MA(C,20),"MA20", colorRed );

Buy=C > MA(C,20 ) ;
Sell=C < MA( C, 20 ) ;

dist = 1.5*ATR(10);

for( i = 0; i < BarCount; i++ )
{
    if (Buy[i]) PlotTextSetFont("C" ,  "Wingdings",  40, BarCount, Close[ BarCount - 1 ], colorgreen, colorDefault, -30 );

	if (sell[i]) PlotTextSetFont( "D",  "Wingdings",  40, BarCount, Close[ BarCount - 1 ], colorred, colorDefault, -20 ); // will use new font too
}

Maybe replace the entire loop in your code by following:

if( Buy[BarCount-1] ) PlotTextSetFont("C" ,  "Wingdings",  40, BarCount, Close[ BarCount - 1 ], colorgreen, colorDefault, -30 );
if( Sell[BarCount-1] ) PlotTextSetFont( "D",  "Wingdings",  40, BarCount, Close[ BarCount - 1 ], colorred, colorDefault, -20 );

@benlai0117 - it is pretty simple. Just provide correct coordinates. Currently you are using last bar value, while you should be using actual X and Y value for given bar. Your "x" coordinate is i (bar number), your "y" coordinate should be price at that bar, say Low[ i ]

Your code should look like this:

Plot(C, "Price", colorDefault, styleCandle );
Plot(MA(C,20),"MA20", colorRed );

Buy= Cross( C, MA(C,20 ) );
Sell= Cross( MA( C, 20 ), C );

dist = 1.5*ATR(10);

bi = BarIndex();
first = FirstVisibleValue( bi );
last = LastVisibleValue( bi );
last = Min( BarCount - 1, last );

for( i = first; i < last; i++ )
{
    if (Buy[i]) PlotTextSetFont("C" ,  "Wingdings",  40, i, Low[ i ], colorgreen, colorDefault, -30 );

	if (sell[i]) PlotTextSetFont( "D",  "Wingdings",  40, i, High[ i ] , colorred, colorDefault, -20 ); // will use new font too
}

Also note that it makes no sense to iterate through all bars. It is way more efficient to use visible bars only.

3 Likes

Too bad there is no PlotText for styleownscale :smiling_imp:

There can't be PlotText for styleOwnScale because each own scale plot sets separate invisible scale so simply, there is no scale to refer to (you can only refer to right or left axis scale). If you need more than 2 separate scales in single pane, consider REMAPING own scale to either left/right scale (Use Remap function).

You can also use GfxTextOut directly to plot text in any scale you wish. In fact GfxTextOut is much faster than thousands of PlotText calls.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.