- ago
Glitch

I guess this falls into the same category of undocumented TimeSeries methods:

I have a TimeSeries where I need to know how many consecutive bars are below 0.

TimeSeries PivotWidth = (PivotHighPrice - PivotLowPrice) / bars.Close;

There's a TimeSeries method called ConsecBarsBelow(0) but the result does not correspond to what I actually expected.
0
249
Solved
5 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.31% )
- ago
#1
That was Cone's creation, let's see what he has to say about it.
0
Cone8
 ( 29.06% )
- ago
#2
Please provide a symbol, scale, and code and I'll look into it!

I think it's right.. but make sure to plot it as a histogram, otherwise you'll be confused how the lines connect while the series is "above" 0. Those 'values' will be Double.NaN.

Probably it would have been better to just make them zero.. I'll modify it for that for Build 28.
0
- ago
#3
It's not that easy because it's a part of a large calculation for price/volume contraction. However, I filtered out the affected part and made a snippet.

As a symbol take KWEB on a daily base. There has been recently such a textbook contraction pattern.



CODE:
public class MyStrategy : UserStrategyBase    {       private int PivotLength = 5;             public override void Initialize(BarHistory bars)       {          StartIndex = 20;          TimeSeries PivotHighPrice = Highest.Series(bars.High, PivotLength);          TimeSeries PivotLowPrice = Lowest.Series(bars.Low, PivotLength);          TimeSeries PivotWidth = (PivotHighPrice - PivotLowPrice) / bars.Close;          for (int i = 20; i < bars.Count; i++)             if (PivotWidth.ConsecBarsBelow(0)[i] >= 9)                // Pivot width stayed the least 9 bars below 0                    PlotTimeSeries(PivotWidth, "Pivot Width", "Pivot Width", WLColor.Black, PlotStyle.Line);       }       public override void Execute(BarHistory bars, int idx)       {                }    }
0
Cone8
 ( 29.06% )
- ago
#4
PivotWidth never goes below zero. You're showing a section where it's between 0 and 0.1. Try this:

CODE:
       private int PivotLength = 5;        public override void Initialize(BarHistory bars) {          StartIndex = 20;          TimeSeries PivotHighPrice = Highest.Series(bars.High, PivotLength);          TimeSeries PivotLowPrice = Lowest.Series(bars.Low, PivotLength);          TimeSeries PivotWidth = (PivotHighPrice - PivotLowPrice) / bars.Close;          TimeSeries consecBelow = PivotWidth.ConsecBarsBelow(0.1);          for (int i = 20; i < bars.Count; i++)             if (consecBelow[i] >= 9)                SetBackgroundColor(bars, i, WLColor.FromArgb(100, WLColor.Blue));          PlotTimeSeries(PivotWidth, "Pivot Width", "Pivot Width", WLColor.Black, PlotStyle.Line); }

By the way, these TimeSeries functions aren't "cached" like indicators - at least not currently. So it's better to save the result once to a variable and use that (like in my example).
1
Best Answer
- ago
#5
Thanks for the hint! Due to todays coding effort, I obviously couldn't see "the forest for the trees" anymore.
0

Reply

Bookmark

Sort