Login Page - Create Account

Support Board


Date/Time: Tue, 26 Nov 2024 13:32:36 +0000



[Programming Help] - Possible to change color of a Moving average based on condition?

View Count: 437

[2023-11-23 14:34:36]
BenjFlame - Posts: 324
Hi,
Do you know a way to paint a moving average?

I'd like with ASCIL to color moving average depending on the value of another indicator (say ADX).
So, each moving average value will be colored depending on the 10 ADX value ranges I would define.

I don't want to paint the entire moving average of a single color: moving average segments could be of any of the 10 colors corresponding to the defined adx ranges.
Date Time Of Last Edit: 2023-11-23 14:35:04
[2023-11-23 16:31:12]
Tony - Posts: 518
I think what you could do is using MA formula to write your
own subgraph, then you can set what ever color you want, say,
from Index[1] to Index[N] as Color1 and from Index[N+1} to
Index[M] as Color2, etc, based on your ADX condition.
[2023-11-24 02:37:04]
Flipper_2 - Posts: 57
like this : )




SCSFExport scsf_Line_Color_Threshold(SCStudyInterfaceRef sc)

{

SCSubgraphRef ADX_Subgraph = sc.Subgraph[0];
SCSubgraphRef SMA_Subgraph = sc.Subgraph[1];


SCInputRef BarColor10 = sc.Input[0];
SCInputRef BarColor15 = sc.Input[1];
SCInputRef BarColor25 = sc.Input[2];
SCInputRef BarColor33 = sc.Input[3];
SCInputRef BarColor66 = sc.Input[4];
SCInputRef BarColor75 = sc.Input[6];
SCInputRef BarColor85 = sc.Input[6];
SCInputRef BarColor90 = sc.Input[7];
SCInputRef Input_DXLength = sc.Input[8];
SCInputRef Input_DXMovAngLength = sc.Input[9];


if (sc.SetDefaults)

{
sc.AutoLoop = 1;
sc.GraphName = "Color Line Based on ADX";
sc.GraphRegion = 0;

// Graphs

ADX_Subgraph.Name = "ADX ";
ADX_Subgraph.DrawStyle = DRAWSTYLE_IGNORE;
ADX_Subgraph.DrawZeros = true;

SMA_Subgraph.Name = "SMA ";
SMA_Subgraph.DrawStyle = DRAWSTYLE_LINE;
SMA_Subgraph.DrawZeros = true;


// Inputs

BarColor10.Name = "10% Bar Range Color";
BarColor10.SetColor(RGB(128, 0, 0));

BarColor15.Name = "15% Bar Range Color";
BarColor15.SetColor(RGB(255, 0, 0));

BarColor25.Name = "25% Bar Range Color";
BarColor25.SetColor(RGB(240, 128, 128));

BarColor33.Name = "33% Bar Range Color";
BarColor33.SetColor(RGB(255, 233, 108));

BarColor66.Name = "66% Bar Range Color";
BarColor66.SetColor(RGB(154, 205, 50));

BarColor75.Name = "75% Bar Range Color";
BarColor75.SetColor(RGB(173, 255, 47));

BarColor85.Name = "85% Bar Range Color";
BarColor85.SetColor(RGB(50, 205, 50));

BarColor90.Name = "90% Bar Range Color";
BarColor90.SetColor(RGB(0, 100, 0));

Input_DXLength.Name = "DX Length";
Input_DXLength.SetInt(14);
Input_DXLength.SetIntLimits(1, INT_MAX);


Input_DXMovAngLength.Name = "DX Mov Avg Length";
Input_DXMovAngLength.SetInt(14);
Input_DXMovAngLength.SetIntLimits(1, INT_MAX);



return;

}


sc.ADX(sc.BaseData, ADX_Subgraph, Input_DXLength.GetInt(), Input_DXMovAngLength.GetInt());
float adx = ADX_Subgraph[sc.Index];

sc.SimpleMovAvg(sc.Close, SMA_Subgraph, Input_DXLength.GetInt());

if (adx < 10)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor10.GetColor();
}
else if (adx < 15)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor15.GetColor();
}
else if (adx < 25)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor25.GetColor();;
}
else if (adx < 33)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor33.GetColor();
}
else if (adx < 66)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor66.GetColor();
}
else if (adx < 75)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor75.GetColor();
}
else if (adx < 85)
{
SMA_Subgraph.DataColor[sc.Index] = BarColor85.GetColor();
}
else
{
SMA_Subgraph.DataColor[sc.Index] = BarColor90.GetColor();
}


}

[2023-11-24 09:36:26]
BenjFlame - Posts: 324
Excellent, works like a charm. Sky is the limit.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account