Closed mahbubk9 closed 7 years ago
Hi, I put the code in my forked repo of yours, in chapter 08 codes, as ForexSystem 0.2, could you please have a look at it. Thanks, Mahbub
Please indent your code if you want somebody to read it.
def ATR(self,data):
i = 0 TR_l = [0]
while i < len(self.resampled_prices.index):
#THIS IS WHERE I THINK THE PROBLEM IS BUT DON'T
# KNOW HOW TO SOLVE
TR = max(self.resampled_prices.get_value(i + 1, 'high')
Like this. Python relies on indentation to get your code working.
Managed to find your code and looked through it, seems to be syntactically correct. What was the problem or error message you got?
Many thanks for your reply, there were a lot of outputs, with last line "Keyerror: "High" Also, File "C:/Users/Mahbub/Documents/PythonTrading/ForexSystem 0.2.py", line 81, in ATR TR = max(self.resampled_prices.get_value(i + 1, 'high'), self.resampled_prices.get_value(i, 'close')) - min(self.resampled_prices.get_value(i + 1, 'low'), self.resampled_prices.get_value(i, 'close') above line were one of the outputs. That's how I guessed some how the loop is not working, and df.get_value is not getting the high column values. Could you please run it on your side, my credentials are there, i will change it later, plus it's practice account. Thanks
I just tried df.loc instead of df.get_value for resampled prices and got this error : KeyError: 'the label [high] is not in the [index]'
Afraid I'm unable to afford the luxury of time to work on other stuffs now, best I could do is to look through codes in some free time. You can try using PyCharm's built-in debugger to perform step-by-step debugging.
The last line of your error is pretty intuitive - there is no column high
as the index for self.resampled_prices
.
It seems you're expecting a column high
after performing ohlc
resampling, but you're overriding the dataframe's indexes with self.resampled_prices.index=n
. Please make sure the resampled_prices
dataframe is in the correct format that you need.
Hi, I am trying to use your ForexSystem.py code for trading. For my strategy I wanted to use ATR indicator, the ATR code is;
#Average True Range def ATR(df, n): i = 0 TR_l = [0] while i < df.index[-1]: TR = max(df.get_value(i + 1, 'high'), df.get_value(i, 'close')) - min(df.get_value(i + 1, 'low'), df.get_value(i, 'close')) TR_l.append(TR) i = i + 1 TR_s = pd.Series(TR_l) ATR = pd.Series(TR_s.rolling(window=12,min_periods=12,center=False).mean(), name = 'ATR_' + str(n)) df = df.join(ATR) return df
which i modified for your code as; `#Average True Rangedef ATR(self,data):
i = 0 TR_l = [0]
while i < len(self.resampled_prices.index): #THIS IS WHERE I THINK THE PROBLEM IS BUT DON'T
KNOW HOW TO SOLVE
Thanks, Mahbub khan