This is my first post here, and I'm open to guidance if there's a better way to engage with the community.
I'm working on a custom indicator that has two states: one for when a WMA is bullish and another for when it's bearish. For a bullish WMA, it should plot the minimum price of the candle minus the ATR value. Conversely, for a bearish WMA, it should plot the maximum price of the candle plus the ATR value. This is intended as a visual guide for a trailing-stop.
However, I'm encountering an issue where the plot always appears below the prices, even when the WMA is bearish, which doesn't make sense. The logic seems correct. I declare the plot value variables at the beginning of the class:
private double tsAtrEnLargos1; private double tsAtrEnCortos1;
Here the code for reference, though I should mention there are actually three plots involved-I've simplified the explanation to focus on the main issue.
protected override void OnBarUpdate()
{
double valorWMA = WMA(PeriodoWMA)[0];
Values[0][0] = valorWMA;
double valorATR;
if (CurrentBar > 0)
{
valorATR = ATR(PeriodoATR)[1];
double maximo = High[1];
double minimo = Low[1];
if (tsAtrEnLargos1 < minimo-valorATR)
{
tsAtrEnLargos1 = minimo-valorATR;
tsAtrEnLargos2 = minimo-(valorATR * 2);
tsAtrEnLargos3 = minimo-(valorATR * 3);
}
if (tsAtrEnCortos1 > maximo+valorATR)
{
tsAtrEnCortos1 = maximo+valorATR;
tsAtrEnCortos2 = maximo+(valorATR * 2);
tsAtrEnCortos3 = maximo+(valorATR * 3);
}
if (valorWMA > WMA(PeriodoWMA)[1])
{
PlotBrushes[0][0] = Brushes.Green;
Values[1][0] = tsAtrEnLargos1;
Values[2][0] = tsAtrEnLargos2;
Values[3][0] = tsAtrEnLargos3;
PlotBrushes[1][0] = new SolidColorBrush(Color.FromArgb(100, 0, 0, 255));
PlotBrushes[2][0] = new SolidColorBrush(Color.FromArgb(150, 0, 0, 255));
PlotBrushes[3][0] = new SolidColorBrush(Color.FromArgb(200, 0, 0, 255));
}
else if (valorWMA < WMA(PeriodoWMA)[1])
{
PlotBrushes[0][0] = Brushes.Red;
Values[1][0] = tsAtrEnCortos1;
Values[2][0] = tsAtrEnCortos2;
Values[3][0] = tsAtrEnCortos3;
PlotBrushes[1][0] = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0));
PlotBrushes[2][0] = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0));
PlotBrushes[3][0] = new SolidColorBrush(Color.FromArgb(200, 255, 0, 0));
}
}
else
{
valorATR = ATR(PeriodoATR)[0];
tsAtrEnCortos1 = Double.PositiveInfinity;
}
}
Best

Comment