Underwater Equity Transparent

Hi,

Using the AFL that fxshrat kindly shared in this thread:
https://forum.amibroker.com/t/underwater-equity/29710/2?u=yonsi72
I've created something similar to what I want:

// Cálculo del drawdown del sistema
EQ = C;
MaxEQ = Highest(EQ);
DD = 100 * (EQ - MaxEQ) / MaxEQ;
MaxDD = Lowest(DD);

// Cálculo del drawdown del índice de referencia
IdxName = "$SPX";
Idx = Foreign(IdxName, "C");
MaxIdx = Highest(Idx);
DDIdx = 100 * (Idx - MaxIdx) / MaxIdx;
MaxDDIdx = Lowest(DDIdx);

// Título con drawdowns actuales y máximos
Title  = EncodeColor(colorRed) + StrFormat(" Portfolio MDD:        %.2f%%,    DD = %.2f%%", LastValue(MaxDD), LastValue(DD));
Title += EncodeColor(colorBlue) + StrFormat("\n Benchmark MDD:   %.2f%%,   DD = %.2f%%", LastValue(MaxDDIdx), LastValue(DDIdx));

// Fondo blanco y rejilla en %
SetChartBkColor(colorWhite);
SetChartOptions(2, 0, chartGridPercent);

// Área degradada del sistema
SetGradientFill( GetChartBkColor(), colorRed, 0);
Plot( DD, "", colorRed, styleGradient | styleLine );

// Área degradada del índice ($SPX)
SetGradientFill(GetChartBkColor(), colorBlue, 0);
Plot(DDIdx, "", colorBlue, styleGradient | styleLine );

// Líneas horizontales en los máximos drawdown
Plot(MaxDD, "Max DD", colorRed, styleLine | styleNoLabel | styleDashed);
Plot(MaxDDIdx, "Max DD Index", colorBlue, styleLine| styleNoLabel);

// Aviso si no se aplica sobre gráfico de equity
if (Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY")
    Title = "?? Warning: this chart should be applied to ~~~EQUITY or ~~~OSEQUITY only!";

But I'd like to improve the transparency so the bottom plot can be seen a little better. I don't know if I'm making myself clear.
I mean, you can see a little better the benchmark which is in blue and largely covered by the portfolio in red.

Thank you very much

@Yonsi, unfortunately the functionality for the SetOpacity() function is not yet implemented (see the ReleasNotes for version 6.90.6).

You can achieve something similar using the styleArea and/or styleLine:

// Cálculo del drawdown del sistema
EQ = C;
MaxEQ = Highest( EQ );
DD = 100 * ( EQ - MaxEQ ) / MaxEQ;
MaxDD = Lowest( DD );

// Cálculo del drawdown del índice de referencia
IdxName = "$SPX";
Idx = Foreign( IdxName, "C" );
MaxIdx = Highest( Idx );
DDIdx = 100 * ( Idx - MaxIdx ) / MaxIdx;
MaxDDIdx = Lowest( DDIdx );

// Título con drawdowns actuales y máximos
Title  = EncodeColor( colorRed ) + StrFormat( " Portfolio DD = %.2f%% - Max DD: %.2f%%", SelectedValue( DD ), SelectedValue( MaxDD ) );
Title += EncodeColor( colorBlue ) + StrFormat( "\n Benchmark DD = %.2f%% - Max DD: %.2f%%", SelectedValue( DDIdx ), SelectedValue( MaxDDIdx ) );

GraphXSpace = 5;

// Fondo blanco y rejilla en %
// SetChartBkColor(colorWhite);
SetChartOptions( 2, 0, chartGridPercent );


// Área degradada del sistema
Plot( DD, "", colorRed, styleLine | styleThick );
SetOpacity( 0.25 );
// SetGradientFill( GetChartBkColor(), colorRed, 0);
Plot( DD, "", colorRed, styleArea | styleNoLabel );

SetOpacity( 1 );
// Área degradada del índice ($SPX)
Plot( DDIdx, "", colorBlue, styleLine | styleThick );
SetOpacity( 0.25 );
// SetGradientFill(GetChartBkColor(), colorBlue, 0);
Plot( DDIdx, "", colorBlue, styleArea | styleNoLabel );

SetOpacity( 1 );
// Líneas horizontales en los máximos drawdown
Plot( MaxDD, "Max DD", colorRed, styleDashed );
Plot( MaxDDIdx, "Max DD Index", colorBlue );


// Aviso si no se aplica sobre gráfico de equity
if( Name() != "~~~EQUITY" AND Name() != "~~~OSEQUITY" )
    Title = "?? Warning: this chart should be applied to ~~~EQUITY or ~~~OSEQUITY only!";

(I also made some changes to the title to show the current "SelectedValue", using labels to show the "LastValue" visible. Adjust to suit your needs)

Thank you very much, Beppe, for your time.

I've looked at it, and unfortunately, it doesn't improve what I wanted, but I'll wait for the update to be implemented. It's not a big deal, it's just a cosmetic issue.

On the other hand, you've shown me how to make the titles more visible!

Again, thanks for helping newbies.

@yonsi72, you should get something like this:

Be sure tho have the "Experimental: Use QuickGFX render" option checked

I tested it with AB 6.93.0 64-bit

Hello Beppe,

I have AB 6.93.0 64-bit too.

This is that I can see with your AFL:

I don't know what I'm doing wrong, sorry

@yonsi72, there is another setting that I forgot:

(By the way, not setting them here gives a warning executing the formula)

I have it like that too

@yonsi72, unfortunately, I'm out of ideas. Maybe @Tomasz will tell us what is causing different results.

You can either manipulate Z-order of each individual Plot() (there is ZOrder parameter in Plot() function) or just reverse the default order of drawing by adding this on top of your formula

GraphZOrder = 1; // reverse drawing order of Plot()s

Generally "transparent" means totally invisible. This usually is implemented by proper Z-ordering of Plots() i.e. plotting in correct order so "opaque" things are plotted before (beneath) "transparent" things (that should be "above").

Transluency is a different thing. It is PARTIAL transparency, so it is neither transparent nor fully opaque. Such effect is typically obtained by processing each pixel separately by blending colors of existing pixel with colors of pixels being drawn. It is called alpha-blending and it is done using calculation like this (1-alpha)*existing_pixel + (alpha)*new_pixelON EACH PIXEL. This is costly operation (because it is done on each pixel separately).

This can be done ONLY ON BITMAP DEVICES (not vectors, no PDF (unless they store just a bitmap), no printers, no EMF (metafiles)). It is also NOT supported by GDI.

Therefore you would see transluency (available via SetOpacity) IF AND ONLY IF:

  1. You display chart directly ON SCREEN (**not printer, not vector image, not part of HTML report)
  2. You don't use GDI (you MUST use "QuickGFX" that skips GDI rendering
  3. You are using AmiBroker version 6.93 OR HIGHER that supports transluency
  4. You draw with supported style (transluency isn't supported for styleGradient)

@beppe code should work just fine ON CHART (Insert the formula as a CHART)

2 Likes