zarovnani baru u not div60 resolutions, +ind na FE
This commit is contained in:
19
testy/tradebarresolution.py
Normal file
19
testy/tradebarresolution.py
Normal file
@ -0,0 +1,19 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
def find_bar_start_time(trade_time, resolution_seconds):
|
||||
# Calculate the number of seconds to subtract to align with resolution
|
||||
remainder = trade_time.second % resolution_seconds
|
||||
seconds_to_subtract = remainder if remainder < resolution_seconds / 2 else resolution_seconds - remainder
|
||||
|
||||
# Subtract the calculated seconds and microseconds from the trade_time
|
||||
bar_start_time = trade_time - timedelta(seconds=seconds_to_subtract, microseconds=trade_time.microsecond)
|
||||
|
||||
return bar_start_time
|
||||
|
||||
# Example usage:
|
||||
trade_time = datetime(2023, 9, 13, 10, 30, 30) # Replace with the actual trade time
|
||||
resolution_seconds = 54 # Replace with your desired resolution in seconds
|
||||
|
||||
bar_start_time = find_bar_start_time(trade_time, resolution_seconds)
|
||||
print("Trade Time:", trade_time)
|
||||
print("Bar Start Time:", bar_start_time)
|
||||
@ -375,6 +375,28 @@ def next(data, state: StrategyState):
|
||||
return 0, val
|
||||
#random.randint(10, 20)
|
||||
|
||||
#TODO error handling obecne v indicatorech
|
||||
# def average(params):
|
||||
# funcName = "average"
|
||||
# lookback = int(safe_get(params, "lookback",1))
|
||||
# source = safe_get(params, "source", None)
|
||||
# if source is None:
|
||||
# state.ilog(lvl=1,e=f"INSIDE {funcName} source required 0", **params)
|
||||
# return 0,0
|
||||
|
||||
# if source in ["open","high","low","close","vwap","hlcc4"]:
|
||||
# source_series = state.bars[source]
|
||||
# else:
|
||||
# source_series = state.indicators[source]
|
||||
|
||||
# state.ilog(lvl=0,e=f"INSIDE {funcName}", source_series=source_series, **params)
|
||||
|
||||
# delka_pole = len(source_series)
|
||||
# if delka_pole < lookback:
|
||||
# lookback = delka_pole
|
||||
|
||||
# return 0, Average(source_series[-lookback:])
|
||||
|
||||
#abs/rel divergence of two indicators
|
||||
def divergence(params):
|
||||
funcName = "indicatorDivergence"
|
||||
@ -418,6 +440,8 @@ def next(data, state: StrategyState):
|
||||
lookback_priceline = safe_get(params, "lookback_priceline", None)
|
||||
if lookback_priceline is None:
|
||||
lookback_series = source_series
|
||||
elif lookback_priceline in ["open","high","low","close","vwap","hlcc4"]:
|
||||
lookback_series = state.bars[lookback_priceline]
|
||||
else:
|
||||
lookback_series = state.indicators[lookback_priceline]
|
||||
|
||||
@ -842,7 +866,7 @@ def next(data, state: StrategyState):
|
||||
state.vars.last_50_deltas.append(last_update_delta)
|
||||
avg_delta = Average(state.vars.last_50_deltas)
|
||||
|
||||
state.ilog(lvl=1,e=f"-----{data['index']}-{conf_bar}--delta:{last_update_delta}---AVGdelta:{avg_delta}")
|
||||
state.ilog(lvl=1,e=f"-----{data['index']}-{conf_bar}--delta:{last_update_delta}---AVGdelta:{avg_delta}", data=data)
|
||||
|
||||
conf_bar = data['confirmed']
|
||||
process_delta()
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -271,8 +271,10 @@ class TradeAggregator:
|
||||
|
||||
self.newBar['open'] = data['p']
|
||||
|
||||
#UPRAVENO - pouze pro prvni bar a ROUND, jinak bereme cas baru podle noveho tradu
|
||||
#TODO: do budoucna vymyslet, kdyz bude mene tradu, tak to radit vzdy do spravneho intervalu
|
||||
#zarovname time prvniho baru podle timeframu kam patří (např. 5, 10, 15 ...) (ROUND)
|
||||
if self.align:
|
||||
if self.align == StartBarAlign.ROUND and self.bar_start == 0:
|
||||
t = datetime.fromtimestamp(data['t'])
|
||||
t = t - timedelta(seconds=t.second % self.timeframe,microseconds=t.microsecond)
|
||||
self.bar_start = datetime.timestamp(t)
|
||||
@ -284,8 +286,6 @@ class TradeAggregator:
|
||||
self.bar_start = int(data['t'])
|
||||
|
||||
|
||||
|
||||
|
||||
self.newBar['time'] = t
|
||||
self.newBar['resolution'] = self.timeframe
|
||||
self.newBar['confirmed'] = 0
|
||||
|
||||
@ -196,7 +196,7 @@ class Trade_Offline_Streamer(Thread):
|
||||
#homogenizace timestampu s online streamem
|
||||
t['t'] = Timestamp.from_unix(to_datetime(t['t']).timestamp())
|
||||
|
||||
print("PROGRESS ",cnt,"/",celkem)
|
||||
#print("PROGRESS ",cnt,"/",celkem)
|
||||
#print(t)
|
||||
#na rozdil od wwebsocketu zde nemame v zaznamu symbol ['S']
|
||||
#vsem streamum na tomto symbolu posilame data - tbd mozna udelat i per stream vlakno
|
||||
|
||||
@ -637,9 +637,11 @@ function chart_archived_run(archRecord, data, oneMinuteBars) {
|
||||
//displays (redraws) buy markers
|
||||
function display_buy_markers() {
|
||||
|
||||
if (profitLine) {
|
||||
chart.removeSeries(profitLine)
|
||||
}
|
||||
// if (profitLine) {
|
||||
// console.log(profitLine)
|
||||
// chart.removeSeries(profitLine)
|
||||
// console.log("nd")
|
||||
// }
|
||||
|
||||
if (avgBuyLine) {
|
||||
chart.removeSeries(avgBuyLine)
|
||||
|
||||
Binary file not shown.
@ -177,6 +177,13 @@ class Strategy:
|
||||
#bary updatujeme, pridavame jen prvni
|
||||
self.replace_prev_bar(self.state.bars,item)
|
||||
|
||||
#UPD
|
||||
#tady mozna u standardnich(barovych) identifikatoru updatnout cas na "updated" - aby nebyl
|
||||
#stale zarovnan s casem baru
|
||||
for key in self.state.indicators:
|
||||
if key == 'time':
|
||||
self.state.indicators['time'][-1] = item['updated']
|
||||
|
||||
#u cbar indikatoru, pridavame kazdou zmenu ceny, krome potvrzeneho baru
|
||||
|
||||
if item['confirmed'] == 0:
|
||||
@ -365,8 +372,8 @@ class Strategy:
|
||||
print(current_thread().name, "Paused.")
|
||||
continue
|
||||
#self.state.iter_log(event="INGEST",msg="New data ingested", item=item)
|
||||
print("New data ingested")
|
||||
|
||||
print("New data ingested", item)
|
||||
print("bars list - previous", self.state.bars)
|
||||
#TODO sem pridat ochranu kulometu
|
||||
#pokud je updatetime aktualniho baru mensi nez LIMIT a nejde o potvrzovaci bar
|
||||
#tak jej vyhodit
|
||||
|
||||
Reference in New Issue
Block a user