For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Get historical data dynamically before cerebro.run()
-
I have to lunch strategies with serveral feeds with different timeframes.
I didn't find the way to get "minpediod" to calculate "hist_start_date" variable.# My formula shuld be look like: minutes_of_one_candle = get_compression_in_minutes_from_timeframe(assetTimeframe,assetCompression) minperiod = # I don't know how to retrieve the "minperiod" from the strategy with custom timeAgoInMinutes = minperiod * minutes_of_one_candle
Follows the complete code
strategies_list = [sma_200minperiod_strategy, ema_5minperiod_strategy] assets = [ ['ticker1', 1, 'minutes',] ['ticker2', 30, 'minutes',] ['ticker3', 1, 'hours',] ['ticker4', 1, 'days',] ] for strategy in strategies_list: cerebro.addstrategy(strategy=strategy, **get_strategyParams(strategy)) for assetName in assets: dataname =assetName[0] assetTimeframe = get_bt_TimeFrame(assetName[2]) assetCompression = get_bt_compression(assetName[1]) assetCompression_in_Minutes = get_compression_in_minutes(assetTimeframe , assetCompression) minutes_of_one_candle = get_compression_in_minutes_from_timeframe(assetTimeframe,assetCompression) minperiod = # I don't know how to retrieve the "minperiod" from the strategy with custom parameters timeAgoInMinutes = minperiod * minutes_of_one_candle hist_start_date = datetime.utcnow() - timedelta(minutes=timeAgoInMinutes) data = store.getdata( dataname=dataname, timeframe=assetTimeframe, compression=assetCompression, fromdate=hist_start_date, # <======== ohlcv_limit=250, drop_newest=True) cerebro.adddata(data)
How can I get
minperiod
to setfromdate = hist_start_date
before cerebro.run()?