Trade Basedon On Time Of Day
-
Hey All, I'm trying to test a strategy which takes a long position once it breaks the HOD, but only after a specific time. That said, not sure how to go about keeping track of the HOD as well as how to indicate when to take a long, based on that aforementioned time. I'd greatly appreciate any tips or pointers you guys might have, since I wasn't really able to find anything similar anywhere.
Many thanks!
-
please post what you have tried so far. Its much easier that way.
At every next() check the new high and store it in a variable and a simple date time if condition before buy would do
-
@rajanprabu
Thanks for the response.
Tbh, while I do not have an issue with manipulating data frames outside of backtrader, I'm having issues with even printing closing prices of the candles which I'm feeding to backtrader. I'm trying to feed it a standard OHLCV data from Binance which is saved as a csv.
As an example, I can print the time and date, but not the volume or close and I'm getting this in the output when i try to do so:
<backtrader.lineiterator.SingleCoupler object at 0x000002E2D3D79A30>def next(self): dt = self.data.datetime.datetime() date = self.data.datetime.date() volume = self.data.volume() print(volume)
If you would be so kind please and provide an example of looping through the data and simply comparing the current close to previous close, that'd be great.
Many thanks!
-
@run-out Much appreciated, this is very useful. Can easily compare previous close, vol, time, etc. That said, for some reason I'm getting an error when trying to compare the date of each candle. Would you happen to know what I'm doing wrong here? Please see below example.
if self.datas[0].close[0] > self.datas[0].close[-1]: print(self.datas[0].close[0]) print("Yep") else: print(self.datas[0].close[0]) print("Nope")
This works fine.
date = self.datas[0].datetime.date() print(date)
This too. But-
if self.datas[0].datetime.datetime[0] == self.datas[0].datetime.datetime[-1]: print("Yep") else: print("Nope")
Here I'm unable to compare the date of one candle to another, unlike with the close which I can do. It's due to not being able to put it in an array [0]? I'm getting the below when I try to do so:
TypeError: 'method' object is not subscriptableThanks in advance.