Hi all,
I am new to Python, though have been coding trading algos in Amibroker for a number of years now. I am trying to get to grips with Python / Numpy / Pandas but it'll be a while before I can express some complex logic in Python. I have been going through the basic samples and can manipulate/add basic logic to these but struggle with anything requiring more complexity. I'll appreciate some pointers in achieving a simple task.
I need a variable 'trend' to be defined on all the bars - the way 'trend' takes its values is -
numBarsUp is the number of bars since 10 period RSI was higher than 55 for two consecutive bars,
numBarsDown is the number of bars since 10 period RSI was lower than 45 for two consecutive bars.
if numBarsUp is less than numBarsDown then 'trend' equals 1
else if numBarsUp is greater than numBarsDown then 'trend' equals -1,
and for initial bars when none of these two conditions has been met - then 'trend' equals 0.
Appreciate all the help.