Open baobach opened 8 months ago
@Mans907 I think I found a way to incorporate indicators from 2 different timeframe in the strategy
class MyStrategy(bt.Strategy):
params = dict(period=20)
def __init__(self):
# data0 is a daily data
sma0 = btind.SMA(self.data0, period=15) # 15 days sma
# data1 is a weekly data
sma1 = btind.SMA(self.data1, period=5) # 5 weeks sma
self.buysig = sma0 > sma1()
def next(self):
if self.buysig[0]:
print('daily sma is greater than weekly sma1')
In this example, I use 15 days SMA and compare it with 5 weeks SMA. Given the 2 datafeed data0
is the daily candle and data1
is weekly candle
Hey, but this strategy is for SMA and not RSI , so i am confused: are we working on RSI or SMA , dual time is only applicable on RSI , the logic is We see Weekly time frame if the RSI has crossed 40 in weekly , we look for entry in 1 Day time frame only if RSI has crossed 60
I was able to back test data with EMA Strategy and the results are astonishing have a look :
Date_Time 2017-12-31 496.15 2018-12-31 2161.25 2019-12-31 8037.00 2020-12-31 19188.35 2021-12-31 6993.30 2022-12-31 18934.55 2023-12-31 5698.85 2024-12-31 1308.15 Freq: A-DEC, Name: PROFIT, dtype: float64
Hi Robert ,
I have added new file named 5EMA.ipynb to the research area, kindly take a look. , was able to devise the strategy , and I need your help further to code to optimize the strategy further, let me know wen your available lets get on a call to understand thinks better .
I guess i am still having issues using Git , as the files which i wanted to commit is not going through , if you have received it please let me know
Implemented the 5EMA strategy to the codebase. Waiting for backtesting. Still having some problem with the input data from nifty bank
Hey as per our discussion , was able to convert data to 5 and 45 mins , but i am unable to get rid of the empty column before Date_time , could you please look into it
Hey as per our discussion , was able to convert data to 5 and 45 mins , but i am unable to get rid of the empty column before Date_time , could you please look into it
Can you give me the code you used and the sample output maybe df.head()? This helps with context and I can answer it better
I am sharing the file on git under research - File name - Converstion_of_data for your review
Date_Time Open High Low Close
0 2017-07-17 09:14:00 24011.40 24014.40 23963.15 23987.1 1 2017-07-17 09:19:00 23986.60 23998.25 23954.05 23982.9 2 2017-07-17 09:24:00 23983.55 23995.20 23967.95 23984.7 3 2017-07-17 09:29:00 23983.00 23984.85 23952.20 23954.9 4 2017-07-17 09:34:00 23954.15 23963.40 23921.20 23940.7
I am trying to get rid of - unnamed column before the Date_time.
The issue is that I am able to run the data files provided from your end like nifty50, niftybank, and BTC, but when i add the converted files its not accepting the data, sumthing to do with the coulmn issue
Take a look at this article on resampling the time series data
https://www.geeksforgeeks.org/python-pandas-dataframe-resample/
You are doing a lot of heavy work. This can be done with few lines of code. Follow this instruction and let me know if you find it's difficult. For the empty column you mentioned. It's because you didn't set the index column for the dataframe. This is a simple fix
df = pd.read_csv("your_file.csv", parse_dates =["your_date_column_name"], index_col ="your_date_column_name")
data45 = pd.read_csv("5EMA_5BN.csv", parse_dates =["Date_Time"], index_col ="Date_Time") data45
Unnamed: 0 | Open | High | Low | Close -- | -- | -- | -- | -- 0 | 24011.40 | 24014.40 | 23963.15 | 23987.1 1 | 23986.60 | 23998.25 | 23954.05 | 23982.9 2 | 23983.55 | 23995.20 | 23967.95 | 23984.7 3 | 23983.00 | 23984.85 | 23952.20 | 23954.9 4 | 23954.15 | 23963.40 | 23921.20 | 23940.7no mate its not able to take it i am getting this results
I want the data to look like this so that the backtesting.py can read the date and generate output
date,open,high,low,close,volume 2017-07-17 09:14:00,24011.4,24011.4,24011.4,24011.4,0 2017-07-17 09:15:00,24011.4,24014.4,23974.95,23974.95,0 2017-07-17 09:16:00,23975.45,23981.55,23963.15,23978.95,0 2017-07-17 09:17:00,23977.25,23995.3,23976.0,23984.6,0 2017-07-17 09:18:00,23983.25,23989.95,23983.25,23987.1,0 2017-07-17 09:19:00,23986.6,23998.25,23979.1,23992.1,0 2017-07-17 09:20:00,23991.7,23994.15,23965.5,23965.5,0 2017-07-17 09:21:00,23964.85,23970.2,23954.05,23958.6,0
So that i can move forward with testing the strategy on any time frames and try to find the logic of using the optimized candle length which suits EMA strategy , and then we can move forward optimizing other paramaters
Spent around close to 2 hours last late night figuring out what's the issue , i hope if you can find the issue and sort it in the conversation file , as that can be used for other assets in future as well . another 2 hours gone today as well
Take a look at this paper Trading Strategies BTC. Can you help me understand the indicators mentioned in the paper. I want to build the strategies using this logic.
Example logic should look like this: