- ago
Is there a transformer that colors the trend of an indicator? Say I want to have the indicator color different when above a value or above/below another indicator. I could not find it in Transformer Indicators list. Maybe it is located somewhere else? Thanks.
1
714
Solved
22 Replies

Reply

Bookmark

Sort
- ago
#1
Yes, it's called SetSeriesBarColor and you can set it in C# code as per example below:

https://www.wealth-lab.com/Support/ApiReference/UserStrategyBase
0
Cone8
 ( 24.56% )
- ago
#2
This kind of customization is not available with Building Blocks.
0
- ago
#3
Thanks, I was looking for one as an indicator transformer (drag and drop list). I guess there is none?
0
Glitch8
 ( 7.81% )
- ago
#4
No, the purpose of Transformers is the transform an indicator's values in some way, not to apply a color. You could look at the two build-in plot styles "Oscillator" and "HistogramTwoColor" for this effect though.

0
Best Answer
- ago
#5
Thank you,
I am trying to color the SMA line when above another SMA line(see code below) I'm getting an error. It works ok when I compare to a numerical value though.
Please advice.

CODE:
public override void Initialize(BarHistory bars) {          indicator1 = new SMA(bars.Close,20);          PlotIndicator(indicator1,new WLColor(0,0,0));          indicator2 = new SMA(bars.Close,40);          PlotIndicator(indicator2,new WLColor(0,0,255));          //Changes the color of indicator lines according to condition below          for (int i = 0; i < bars.Count; i++)          {             SetSeriesBarColor(indicator1, i, indicator1[i] > indicator2 ? WLColor.DarkCyan : indicator1[i] < indicator2 ? WLColor.DarkRed : WLColor.Magenta);          } }


0
Glitch8
 ( 7.81% )
- ago
#6
You'll need to put the indexer [i] on indicator2 as well.
0
- ago
#7
Thank you, I knew it was something dumb.
0
- ago
#8
Nobody mentioned PlotIndicatorCloud, which was added in WL8 Build 28. That's the way I would prefer to do it. Below is a comparison of PlotIndicatorCloud and PlotTimeSeriesHistogramTwoColor. Both plots shade the same differences but in different ways. Pick which you like better.

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript1 {    public class MyStrategy0 : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {          fastSMA = new SMA(bars.Close, 20);          slowSMA = new SMA(bars.Close, 40);          PlotIndicatorCloud(fastSMA, slowSMA, WLColor.Green, WLColor.Firebrick, paneTag: "SMA cloud difference");          PlotTimeSeriesHistogramTwoColor(fastSMA-slowSMA, "SMA difference", "SMA difference", WLColor.Green, WLColor.Firebrick);       }       public override void Execute(BarHistory bars, int idx)       {          if (HasOpenPosition(bars, PositionType.Long))          {             //code your sell conditions here          }          else          {             //code your buy conditions here          }       }       SMA fastSMA, slowSMA;    } }
0
Glitch8
 ( 7.81% )
- ago
#9
Nice application of Cloud plotting!
0
- ago
#10
How would I apply the 2 color to an indicator C# created in the Indicator Builder? (Not C# Strategy or Blocks). Say if Close[0] > Close[1] color Green.
I can't find any examples. Thanks.
0
- ago
#11
QUOTE:
How would I apply the 2 color to an indicator C# created in the Indicator Builder. Say if Close[0] > Close[1] color Green.

What you're asking for is to create the WL Momentum indicator with a period of 1. You can drag the Momentum indicator onto the Chart, select "Close", and period of 1 (since you want Closes one bar apart), and then select HistogramTwoColor for the plot style.



But to create your own Momentum indicator (which is what you're asking), you need to define an AddParameter statement for each parameter showing in the indicator Settings dialog box. I haven't used the indicator builder before (I use Visual Studio instead), but I think there are examples for the SMA and RSI indicators available in the builder that show this. There's also an example defining the SMA indicator at https://www.wealth-lab.com/Support/ExtensionApi/IndicatorLibrary

If you want to do this in code, it's easy. But keep in mind we are calling PlotIndicatorHistogramTwoColor, not PlotTimeSeriesHistogramTwoColor as we did before, because we are now plotting an indicator as an input parameter instead of a TimeSeries.

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; namespace WealthScript3 {    public class MyStrategy : UserStrategyBase    {       public override void Initialize(BarHistory bars)       {          Momentum closeDelta = new Momentum(bars.Close, 1);          PlotIndicatorHistogramTwoColor(closeDelta);       }       public override void Execute(BarHistory bars, int idx) { }    } }
0
- ago
#12
superticker thanks. I look in the link and the examples you provided. As i said I could not find an indicator that shows the color based on trend. I have ask before for a strategy (see above) but my question this time is for an indicator. I guess in the indicator you have to modify this portion of the code?

CODE:
//default color       public override WLColor DefaultColor       {          get          {             return WLColor.FromArgb(255,34,139,34);          }       }
0
- ago
#13
QUOTE:
in the indicator you have to modify this portion of the code?

Yes, that will give you the default positive color for the HistogramTwoColor PlotStyle. There's a little more information at https://www.wealth-lab.com/Support/ApiReference/IndicatorBase

But I don't know how the "negative color" is defined. Not even the Visual Studio Object Browser can find a property for that. That's a mystery to me. Some else needs to explain that. I don't know.
0
- ago
#14
The reference link refers to the indicator base as created in a strategy environment. But I am Not sure if it can be done in an indicator environment. (ie. using the indicator builder) BTW I was told that the Indicator Builder can not be linked to Visual Studio as the Strategy Environment can.
0
- ago
#15
QUOTE:
... the Indicator Builder cannot be linked to Visual Studio as the Strategy Environment can.

If you're using the Visual Studio IDE (which is much more powerful than the Indicator Builder), then you don't need the Indicator Builder. Not everyone is a code developer, so they don't want the complexity of learning an IDE (Integrated Design Environment) such as Visual Studio. The Indicator Builder is offered as a simpler way to craft an indicator without the complexity of learning an IDE.

If you're installing Visual Studio, give yourself three days to get familiar with it. It's a very power IDE, especially for low-level symbolic debugging.
0
- ago
#16
I use Visual Studio for Strategy coding in WL but via the link. I have not used it for creating indicators.
0
- ago
#17
In the IndicatorBase class in Visual Studio in the Populate method, is there a way to colorize a TimeSeries based on the trend?
0
Cone8
 ( 24.56% )
- ago
#18
The "WealthLab Way" is to do it in a strategy with `SetSeriesBarColor()`, but actually you can do it in a custom indicator by initializing the SeriesBarColors list as shown below. This is a snippet of the sample code for an SMA custom indicator, but with "bar color logic" added.

CODE:
//populate       public override void Populate() {          TimeSeries source = Parameters[0].AsTimeSeries;          Int32 period = Parameters[1].AsInt;                      DateTimes = source.DateTimes;                    //initialize for colors          this.SeriesBarColors = new DateSynchedList<WLColor>(DateTimes, WLColor.Empty);                                      if (period <= 0)           return;          for (int n = period - 1; n < source.Count; n++)          {             Values[n] = CustomSMA.Value(n, source, period);             //add the up/down color             if (!Double.IsNaN(Values[n]) && !Double.IsNaN(Values[n - 1]))                this.SeriesBarColors[n] = Values[n] >= Values[n - 1] ? DefaultColor : WLColor.Red;          } }
3
- ago
#19
Thanks! I wasn't yet familiar with the SeriesBarColors property.
Is there also a way to add an arrow up/down symbol to visualize a trend change?
0
Cone8
 ( 24.56% )
- ago
#20
Sure, just call DrawBarAnnotation() in a strategy.
... you won't be able to get to that one from Indicator code.
0
- ago
#21
QUOTE:
you won't be able to get to that one from Indicator code.


Can live with that. Simply the fact that I've learned that DateSynchedList<T> is the parent of TimeSeriesBase helps me to create TimeSeries of different types.
0

Reply

Bookmark

Sort