Skip to content

Commit

Permalink
+ fixed NtimestrueOk
Browse files Browse the repository at this point in the history
  • Loading branch information
WISEPLAT committed Sep 13, 2022
1 parent 11ec57b commit fdf5264
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions Strategy2_ROC_KC_UpDownTrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def next(self):
class And3(bt.Indicator):
lines = ('and3',)
params = dict(data2=1, data3=1)
plotinfo = dict(plot=True)

def __init__(self):
self.l.and3 = bt.And(self.data, self.p.data2, self.p.data3)
Expand All @@ -47,6 +48,7 @@ def __init__(self):
class OverUnder(bt.Indicator):
lines = ('overunder',)
params = dict(data2=20)
plotinfo = dict(plot=True)

def __init__(self):
self.l.overunder = self.data > self.p.data2 # данные над data2 == 1
Expand All @@ -55,6 +57,7 @@ def __init__(self):
class UnderOver(bt.Indicator):
lines = ('underover',)
params = dict(data2=20)
plotinfo = dict(plot=True)

def __init__(self):
self.l.underover = self.data < self.p.data2 # данные под data2 == 1
Expand All @@ -63,6 +66,7 @@ def __init__(self):
class UpDownTrend(bt.Indicator):
lines = ('trend',)
params = dict(period=20, )
plotinfo = dict(plot=True)

def __init__(self):
y1 = self.data
Expand Down Expand Up @@ -214,10 +218,14 @@ def __init__(self):
data2=self.roc_over_0[ticker].lines.overunder,
data3=self.close_over_kc_top[ticker].lines.overunder)

self.enter_long[ticker] = NtimestrueOk(self.datas[i], self.and3[ticker].lines.and3, period=50)
self.enter_long[ticker] = NtimestrueOk(self.datas[i], self.and3[ticker].lines.and3, period=10)
# self.enter_long[ticker] = bt.indicators.CrossUp(self.ema_all1[ticker].lines.ema,
# self.kc[ticker].lines.bot)

#self.close_long[ticker] = UnderOver(self.datas[i].close, data2=self.kc[ticker].lines.bot)
self.close_long[ticker] = UnderOver(self.ema_all1[ticker].lines.ema, data2=self.kc[ticker].lines.mid)
# self.close_long[ticker] = bt.indicators.CrossDown(self.ema_all1[ticker].lines.ema,
# self.kc[ticker].lines.top)

# self.sma_all1[ticker] = bt.indicators.SMA(self.datas[i], period=64)
# self.sma_all2[ticker] = bt.indicators.SMA(self.datas[i], period=128)
Expand Down Expand Up @@ -340,21 +348,21 @@ def next(self):

profit_percent = 1
ratio_profit = 5 # 1/3 => 1%*3=3%
stop_loss_percent = 1
stop_loss_percent = 5
# условие на продажу
if self.orders[ticker] and self.price_buy[ticker]:
# print(f"_close={_close} self.price_buy[ticker]={self.price_buy[ticker]} take_profit={self.price_buy[ticker]*(1+profit_percent*ratio_profit/100)} stop-loss={self.price_buy[ticker]*(1-profit_percent/100)}")
size = self.size_buy[ticker]
# # условие на продажу stop-loss %
# if _close <= self.price_buy[ticker] * (1 - stop_loss_percent / 100):
# self.log(f"SELL STOP LOSS CREATE [{ticker}] {self.data.close[0]:.2f}")
# self.log_csv(ticker=ticker, signal='STOP LOSS', signal_price=_close, size=size)
# self.sell(data=data, exectype=bt.Order.Market, size=size)
# self.orders[ticker] = False
# self.first_buy[ticker] = True
# условие на продажу stop-loss %
if _close <= self.price_buy[ticker] * (1 - stop_loss_percent / 100):
self.log(f"SELL STOP LOSS CREATE [{ticker}] {self.data.close[0]:.2f}")
self.log_csv(ticker=ticker, signal='STOP LOSS', signal_price=_close, size=size)
self.sell(data=data, exectype=bt.Order.Market, size=size)
self.orders[ticker] = False
self.first_buy[ticker] = True

# условие на продажу take-profit
if self.close_long[ticker]: #
if self.close_long[ticker] and self.orders[ticker]: #
self.log(f"SELL CREATE [{ticker}] {self.data.close[0]:.2f}")
self.log_csv(ticker=ticker, signal='SELL', signal_price=_close, size=size)

Expand Down
2 changes: 1 addition & 1 deletion main2_ROC_KC_UpDownTrend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'TQBR.AKRN', 'TQBR.SIBN', 'TQBR.LSRG', 'TQBR.RASP', 'TQBR.BSPB', 'TQBR.MTLRP', 'TQBR.RTKMP',)
symbols = ('TQBR.SBER', 'TQBR.GAZP', 'TQBR.LKOH', 'TQBR.GMKN',) # Кортеж тикеров
symbols = ('TQBR.SBER', 'TQBR.LKOH', ) # Кортеж тикеров
symbols = ('TQBR.SBER', )
#symbols = ('TQBR.GAZP', )

all_lots = {}

Expand Down

0 comments on commit fdf5264

Please sign in to comment.