Color.FromArgb() Alpha parameter useless ?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Verbose
Posts: 1
Joined: 18 Jun 2013

Color.FromArgb() Alpha parameter useless ?  [SOLVED]

Postby Verbose » 18 Jun 2013

Hi,
Here is a simple code that plots 2 Simple MA and colors the gap between them. I would like to use the Alpha parameter from Color.FromArgb() method to make some transparency effect. But whatever the Alpha value is, the color remain the same, like if it is useless.
Is it a bug ? (Note that it is purely an aesthetic concern)

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class TwoSMA : IndicatorObject
{
public TwoSMA(object _ctx):base(_ctx){}

private IPlotObject SMA_plt_1, SMA_plt_2;
private Function.AverageFC SMA_fnc_1, SMA_fnc_2;

private int r_Length_1 = 16;
[Input]
public int Length_1 { get { return r_Length_1; } set { r_Length_1 = value; } }

private int r_Length_2 = 32;
[Input]
public int Length_2 { get { return r_Length_2; } set { r_Length_2 = value; } }

private Color r_UP_color = Color.DodgerBlue;
[Input]
public Color UP_color { get { return r_UP_color; } set { r_UP_color = value; } }

private Color r_DW_color = Color.Gold;
[Input]
public Color DW_color { get { return r_DW_color; } set { r_DW_color = value; } }

private int r_Alpha = 32;
[Input]
public int Alpha { get { return r_Alpha; } set { r_Alpha = value; } }


protected override void Create()
{
SMA_fnc_1 = new Function.AverageFC(this);
SMA_plt_1 = AddPlot(new PlotAttributes("aSMA_1", EPlotShapes.BarHigh, Color.Black, Color.Black, 6, 0, true));

SMA_fnc_2 = new Function.AverageFC(this);
SMA_plt_2 = AddPlot(new PlotAttributes("aSMA_2", EPlotShapes.BarLow, Color.Black, Color.Black, 6, 0, true));
}


protected override void StartCalc()
{
SMA_fnc_1.price = Bars.Close;
SMA_fnc_1.length = this.Length_1;

SMA_fnc_2.price = Bars.Close;
SMA_fnc_2.length = this.Length_2;
}


protected override void CalcBar()
{
SMA_plt_1.Values[0] = SMA_fnc_1[0];
SMA_plt_2.Values[0] = SMA_fnc_2[0];
if (SMA_fnc_1[0] > SMA_fnc_2[0]) { SMA_plt_1.Colors[0] =Color.FromArgb(Alpha, UP_color); SMA_plt_2.Colors[0] = Color.FromArgb(Alpha, UP_color); }
else if (SMA_fnc_1[0] < SMA_fnc_2[0]) { SMA_plt_1.Colors[0] =Color.FromArgb(Alpha, DW_color); SMA_plt_2.Colors[0] = Color.FromArgb(Alpha, DW_color);}
else { SMA_plt_1.Colors[0] = Color.FromArgb(Alpha, Color.Green); SMA_plt_2.Colors[0] = Color.FromArgb(Alpha, Color.Green); }
}
}
}

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Color.FromArgb() Alpha parameter useless ?

Postby Henry MultiСharts » 19 Jun 2013

Hello Verbose,

Color.FromArgb() Alpha parameter cannot be used in MultiCharts.
When Color is used in Plot, Alpha channel is ignored.

User avatar
WildWex
Posts: 5
Joined: 01 Jan 2019
Has thanked: 5 times
Contact:

Re: Color.FromArgb() Alpha parameter useless ?

Postby WildWex » 21 Jan 2019

Hello Verbose,

Color.FromArgb() Alpha parameter cannot be used in MultiCharts.
When Color is used in Plot, Alpha channel is ignored.
I'd really like to see MC implement Alpha channel into color so we can have transparency in our indicators.

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: Color.FromArgb() Alpha parameter useless ?

Postby Jobauma » 22 Jan 2019

Hi, WildWex.

You have to blend the color with the background color of your chart. :)

Code: Select all

// Method

public static Color BlendColor( Color MainColor, Color BGColor, double Opacity )
{
Opacity = Opacity * 2.55;

byte R = (byte)( ( MainColor.R * Opacity / 255 ) + BGColor.R * ( 255 - Opacity ) / 255 );
byte G = (byte)( ( MainColor.G * Opacity / 255 ) + BGColor.G * ( 255 - Opacity ) / 255 );
byte B = (byte)( ( MainColor.B * Opacity / 255 ) + BGColor.B * ( 255 - Opacity ) / 255 );

return Color.FromArgb( R, G, B );
}



protected override void CalcBar()
{
m_ColorWithOpacity = BlendColor( m_MainColor, Environment.BGColor, m_Color_Opacity );
}
You'll have to take the plot object with "opacity" behind other plot objects ( if possible ), to hide the background color ("Environment.BGColor") of the blending. If there is no other plot objects, then this solution is the same as alpha, otherwise the blend in most cases overlaps other plot objects all right. :) If not, then change the color fully to the background color ( with size "0", to make "invisible" as possible ), when overlap occurs, then take it back to the desired color ( and size ). :P

If you change the background color of your chart, after loading the indicator, you'll have to recalculate it. :D



Best regards,
Johannes Hillestad Baumann

darob
Posts: 207
Joined: 20 Nov 2014
Has thanked: 57 times
Been thanked: 32 times

Re: Color.FromArgb() Alpha parameter useless ?

Postby darob » 22 Jan 2019

A working alpha channel would enable highlighting intersections of indicators
+1 for this feature

User avatar
WildWex
Posts: 5
Joined: 01 Jan 2019
Has thanked: 5 times
Contact:

Re: Color.FromArgb() Alpha parameter useless ?

Postby WildWex » 01 Feb 2019

Hi, WildWex.

You have to blend the color with the background color of your chart. :)

Code: Select all

// Method

public static Color BlendColor( Color MainColor, Color BGColor, double Opacity )
{
Opacity = Opacity * 2.55;

byte R = (byte)( ( MainColor.R * Opacity / 255 ) + BGColor.R * ( 255 - Opacity ) / 255 );
byte G = (byte)( ( MainColor.G * Opacity / 255 ) + BGColor.G * ( 255 - Opacity ) / 255 );
byte B = (byte)( ( MainColor.B * Opacity / 255 ) + BGColor.B * ( 255 - Opacity ) / 255 );

return Color.FromArgb( R, G, B );
}



protected override void CalcBar()
{
m_ColorWithOpacity = BlendColor( m_MainColor, Environment.BGColor, m_Color_Opacity );
}
You'll have to take the plot object with "opacity" behind other plot objects ( if possible ), to hide the background color ("Environment.BGColor") of the blending. If there is no other plot objects, then this solution is the same as alpha, otherwise the blend in most cases overlaps other plot objects all right. :) If not, then change the color fully to the background color ( with size "0", to make "invisible" as possible ), when overlap occurs, then take it back to the desired color ( and size ). :P

If you change the background color of your chart, after loading the indicator, you'll have to recalculate it. :D



Best regards,
Johannes Hillestad Baumann

Thank you Johannes - certainly an interesting workaround (thank you) - there is a few use cases where I can apply this. However, a true alpha would be preferred and it's certainly not out of line given the capabilities available within today's GPU devices. I would like Multicharts to implement this.

Jobauma
Posts: 113
Joined: 16 Apr 2013
Has thanked: 25 times
Been thanked: 6 times

Re: Color.FromArgb() Alpha parameter useless ?

Postby Jobauma » 04 Mar 2019

It's actually important with alpha. Especially with compact indicators with plots, trendlines, grids, levels and other stuff, all in one place. :)

Indicators on top of each other is also something that makes alpha useful. I hope this is at least implemented in MultiCharts 13.

To blend colors with the background color is still a solution to make colors more balanced, but alpha in addition would make everything perfect.

I use something I call "frame" with compact indicators. It's the same as the "main" plots/trendlines but with a bigger size, and it's behind with the background color. This is to see things more clearly. The only thing that is missing is alpha. :) If necessary I take all the frames gathered behind all the other main trendlines/plots. :D This way crosses overlap without the frame. :P



Best regards,
Johannes Hillestad Baumann


Return to “MultiCharts .NET”