Home > Mobile >  Problems with pandas_ta indicators rsi
Problems with pandas_ta indicators rsi

Time:12-31

I try to put 1 por trading strategy when rsi if > 30 and 0 if the previous period if < 30

data['rsi_compra'] = 1 if data.rsi > 30 & data.rsi.shift(periods = 1) < 30 else 0

Raise this error

Cannot perform 'rand_' with a dtyped [float64] array and scalar of type [bool]

CodePudding user response:

if you simply wish to do as, if >30 is 1 one <30 as 0

data['rsi_compra'] = (data.rsi > 30 ).astype(int)

and if you want peroid as you mentioned try this

data['rsi_compra'] = ((data.rsi > 30) & (data.rsi.shift(periods=1) < 30)).astype(int)

CodePudding user response:

Try this:

data['rsi_compra'] = ((data.rsi > 30) & (data.rsi.shift(periods=1) < 30)).map(int)

you should keep in mind yu are working with pandas series and not a scalar value , while & operand applies to a single item in that series & using parenthesis is necessary for that purpose.

  • Related