2019-10-02: The community is currently in read-only mode
hobart-liu last edited by
In some cases I need to set different status in a line.
s1 = indicator > 0.2 s2 = indicator < -0.2 signal = s1 - s2
the value of signal will be
[1, nan, nan, -1, -1, nan, -1, 1, nan, nan...]
I would like to know how to avoid nan in this case?
Today I use the code below
signal = bt.Max(0, 0) singal = b - s
I wonder is there an efficient way to initialize signal with value 0?
Your problem is that the indicators seem to be producing
NaNvalues (which is of course the case for many indicators before the warm-up period is done)
Or else the indicators in that snippet are producing
NaNvalues after the warm-up period is done. To overcome that you need to wrap the calculations in your own custom indicator.
There is no initialization. The line you are calculating is the result of the operations on the other lines. If you need more you need to wrap it.
ab_trader last edited by ab_trader
line = bt.LineNum(float(True))to set initial
Truevalues to the line. But can't find the reference now. You can try with the number instead of
line = bt.LineNum(float(True))
That doesn't initialize a line to
Trueconverted to a
float). That creates a line which delivers a constant value of