def signal1(data):
data.dropna()
vwap = data["vwap"]
close = data["Close"]
ema5 = data["ema5"]
ema10 = data["ema10"]
st = data["st"]
obv = data["obv"]
obv1 = data["obv"].shift(1)
adx = data["adx"]
if ([vwap > close] and [ema5 > ema10] and [st < close] and [adx > 25] and [obv > obv1]):
a = 1
return a
elif ([vwap < close] and [ema5 < ema10] and [st > close] and [adx < 25] and [obv < obv1]):
b = -1
return b
else:
return ""
For the above function,i can only get signal for which ever condition is in first place but not going to the elif or else conditions…all the data for technical indicators are correct…can someone let me know whats wrong?
Hi Bendi
This is happening because you are using return statements. Every time a condition is true the function returns and no further execution takes place. What you need to do is create a separate column in your dataframe to store the values of -1 and 1. Once a condition is true, update that column.
The easiest way to do this is using np.where. But I found another blog that matches your approach. Try going through this blog, especially the Step 3.
Hope this helps.
Hi Abhishek,
Can you please share the complete code. The last two lines of the code are unclear in the image attached to the query. If possible, could you share the ipynb file?
Thank you
Hi Abhishek,
Thanks for sharing the ipynb file. The code is error-free.
However, you have used five conditions to generate a signal. This made the event so rare, and we are not getting any signals on RELIANCE. Try running the same conditions on other stocks. You can also try increasing the range of the backtest period.
Thank you