line value behaviour
-
BV = value created with
bt.If
as a line in__init__
every value in this line should be <float('Inf')
buy = if c(0) > BV
scenario 1:
data = 5min ohlc
BV occurs at 9:05 am
c(0) > BV
occurs at 9:10 am
buy signal occursscenario 2:
data = 5min ohlc
BV occurs at 9:05 am
c(0) > BV
occurs at 9:35 am
(all prices between 9:05 and 9:35 <BV
)
buy signal does NOT occurIf
c(0) > BV
occurs in the 5min bar that comes immediately afterBV
then buy signal happens.
but ifc(0) > BV
occurs in a 5min bar not immediately afterBV
the buy signal does not happen.Shouldn't
c(0)
be compared to the last value created in theBV
line, no matter how long ago it
was created?
Why does scenario 2 happen?
How to enable a buy signal in scenario 2?Thanks.
-
Sorry but the magical powers of recreating your code out of thin air and seeing your data in a crystal ball are far beyond what my humble human condition allows to me do.
- No idea what
BV
is (even if you think you have completely specified it) - No idea what
c(x)
is - No idea what your data is.
- No idea where
c(x)
andBV
are being compared.
@kam-dorra said in line value behaviour:
If
c(0) > BV
occurs in the 5min bar that comes immediately after BV then buy signal happens.
butif c(0) > BV
occurs in a 5min bar not immediately after BV the buy signal does not happen.Even if you believe those sentences make sense, they don't.
@kam-dorra said in line value behaviour:
Shouldn't
c(0)
be compared to the last value created in theBV
line, no matter how long ago it was created?Apparently
BV
is also a line created withbt.If
. The last value is NOT created long ago. It has a value for each iteration. - No idea what
-
class tester(bt.Strategy): def __init__(self): h = self.data.high l= self.data.low c = self.data.close BBBV = bt.And(h(-3) > h(-2), h(-2) > h(-1)) # 3 highs down in row BBV = bt.If(BBBV, h(-1), float('Inf')) # returns h(-1) or Inf BV = bt.If(BBV < float('Inf'), BBV, float('Inf')) # returns only non-Inf BBV? or does this do something else? self.buy = c(0) > BV
-
@kam-dorra said in line value behaviour:
self.buy = c(0) > BV
Simpler writing does help ... try ...
self.buy = self.data.close > BV
@kam-dorra said in line value behaviour:
BV = bt.If(BBV < float('Inf'), BBV, float('Inf')) # returns only non-Inf BBV? or does this do something else?
It's an
if
condition. It will return the current value ofBBV
(which can befloat('Inf')
) orfloat('Inf')
.Rather than asking yourself that question, a
print(BV[0])
in eachnext
iteration will show you the actual values. -
when I add
print (BV[0])
, i get:
IndexError: array index out of rangewhen I add
print (BV)
, i get:
<backtrader.functions.If object at 0x7f1565ab8310>- an object somewhere in memory?
-
@kam-dorra said in line value behaviour:
when I add print (BV[0]), i get:
IndexError: array index out of rangeAnd you expect us to know where you do that ... because we will see it using tea leaves?