Here's a little part of my data frame of forex data:
OPEN HIGH LOW CLOSE VOLUME
1,14257 1,14368 1,14234 1,14325 1474
1,14327 1,14358 1,14302 1,14334 1032
1,14339 1,14401 1,14232 1,14391 993
1,14393 1,14431 1,14371 1,14376 1401
1,14377 1,14416 1,14342 1,14414 812
1,14419 1,14474 1,14393 1,14428 1091
1,14426 1,14426 1,14375 1,14405 1190
1,14405 1,14412 1,14366 1,14388 991
1,14388 1,14439 1,14384 1,14389 781
I want to implement the following calculation on a pandas dataframe.
Example: Middle value between 'OPEN' and 'CLOSE' highest and lowest value within the 9 last candles.
=(MAX(B2:B10;E2:E10)+MIN(B2:B10;E2:E10))/2
Context:
I'm learning pandas and pandas_ta packages and following some YouTube videos. I want to create a forex trading bot that gets the values from a Forex API and sends me an email when it's time to buy or sell.
I found someone using Machine Learning for a forex bot, creating a pandas dataframe from a CSV file to teach his "IA" and adding some values in it using pandas_ta.
many TA signals can be calculated using pandas rolling function: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rolling.html https://pandas.pydata.org/docs/reference/api/pandas.Series.rolling.html
for this specific case, try this:
max_signal = df[['OPEN', 'CLOSE']].max(axis=1)
min_signal = df[['OPEN', 'CLOSE']].min(axis=1)
df['signal'] = (max_signal.rolling(9).max() + min_signal.rolling(9).min()) / 2
use fillna
if you don't want the NaN values