Henk8
- ago
How can i count the number of days this indicator is true?
0
308
Solved
3 Replies

Reply

Bookmark

Sort
Cone8
 ( 6.32% )
- ago
#1
You didn't really say what "true" was, but since you wanted to use CrossoverIndValue, I assumed that it mean the number of days since crossing over the high value until the crossing under the low value.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript3 { public class MyStrategy : UserStrategyBase { public override void Initialize(BarHistory bars) {          _rsi = RSI.Series(bars.Close, 14);          PlotIndicator(_rsi);                    double xvalue = 55;          _ind1 = new CrossoverIndValue(bars, _rsi, xvalue, 30.00);                      PlotIndicator(_ind1, WLColor.FromArgb(255,107,139,139), PlotStyle.Line);          _barsSince = TimeSeries.BarsSince(_ind1 < 0);          PlotTimeSeriesLine(_barsSince, $"Bars Since RSI CrossOver {xvalue}", "BarsSincePane");          SetPaneMinMax(_ind1.PaneTag, -1.2, 1.2); } public override void Execute(BarHistory bars, int idx) { }       TimeSeries _barsSince;       IndicatorBase _ind1;       RSI _rsi;        } }
1
Best Answer
Henk8
- ago
#2
True for me is 1. Thanks for the code but it stays a challeng for me.
0
Cone8
 ( 6.32% )
- ago
#3
The _barsSince series has the value you want. You can get it for any bar in Execute() using _barsSince[idx].

If we're talking about blocks, then you'll need to make a custom indicator for that.
0

Reply

Bookmark

Sort