Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def indicator():
# We can start MACD EMAs once we have max period candles
if len(ldb.price_list) >= max(gc.MACD.LongPeriod, gc.MACD.ShortPeriod):
storage.writelist('MACD_Short_list', Helpers.EMA(
ldb.price_list, storage.getlist('MACD_Short_list'), gc.MACD.ShortPeriod))
storage.writelist('MACD_Long_list', Helpers.EMA(
ldb.price_list, storage.getlist('MACD_Long_list'), gc.MACD.LongPeriod))
storage.writelist('MACD_ind_list', storage.getlist(
'MACD_Short_list')[-1] - storage.getlist('MACD_Long_list')[-1])
# We need SignalPeriod MACDs before generating MACDSignal
if len(storage.getlist('MACD_Long_list')) >= gc.MACD.SignalPeriod:
storage.writelist('MACD_Signal_list', Helpers.EMA(storage.getlist(
'MACD_ind_list'), storage.getlist('MACD_Signal_list'), gc.MACD.SignalPeriod))
storage.writelist('MACD_Histogram_list', storage.getlist(
'MACD_ind_list')[-1] - storage.getlist('MACD_Signal_list')[-1])
if 'MACD' in gc.Trader.VerboseIndicators:
if not storage.getlist('MACD_Signal_list'):
print('MACD: Not yet enough data to determine trend')
else:
gu.PrintIndicatorTrend('MACD', storage.getlist('MACD_ind_list'), storage.getlist(
'MACD_Signal_list'), storage.getlist('MACD_ind_list'), gc.MACD.DiffDown, gc.MACD.DiffUp)
print('MACD Hist:', storage.getlist('MACD_Histogram_list')[-1])
elif UpMove < DownMove:
storage.writelist('DMI_PosDM_list', 0)
storage.writelist('DMI_NegDM_list', DownMove)
if len(storage.getlist('DMI_PosDM_list')) >= gc.ATR.Period and len(storage.getlist('ATR_TR_list')) >= gc.ATR.Period:
storage.writelist('DMI_PosDMWMA_list',
Helpers.WMA(storage.getlist('DMI_PosDM_list'),
storage.getlist('DMI_PosDMWMA_list'), gc.ATR.Period))
storage.writelist('DMI_NegDMWMA_list',
Helpers.WMA(storage.getlist('DMI_NegDM_list'),
storage.getlist('DMI_NegDMWMA_list'), gc.ATR.Period))
storage.writelist('DMI_PosDI_list',
storage.getlist('DMI_PosDMWMA_list')[-1]
/ storage.getlist('ATR_ind_list')[-1])
storage.writelist('DMI_NegDI_list',
storage.getlist('DMI_NegDMWMA_list')[-1]
/ storage.getlist('ATR_ind_list')[-1])
DIDiff = abs(storage.getlist('DMI_PosDI_list')[-1]
- storage.getlist('DMI_NegDI_list')[-1])
try:
storage.writelist('DMI_DX_list', DIDiff
/ (storage.getlist('DMI_PosDI_list')[-1]
+ storage.getlist('DMI_NegDI_list')[-1]))
# ADX
if len(storage.getlist('DMI_DX_list')) >= (gc.ATR.Period * 2):
storage.writelist('DMI_ind_list',
Helpers.WMA(storage.getlist('DMI_DX_list'),
storage.getlist('DMI_ind_list'), gc.ATR.Period))
except ZeroDivisionError:
pass
def indicator():
# We can start SMA calculations once we have max period candles
if len(ldb.price_list) >= max(gc.SMA.LongPeriod, gc.SMA.ShortPeriod):
storage.writelist(
'SMA_Short_list', Helpers.SMA(ldb.price_list, gc.SMA.ShortPeriod))
storage.writelist(
'SMA_Long_list', Helpers.SMA(ldb.price_list, gc.SMA.LongPeriod))
storage.writelist('SMA_Diff_list', Helpers.ListDiff(
storage.getlist('SMA_Short_list'), storage.getlist('SMA_Long_list')))
if 'SMA' in gc.Trader.VerboseIndicators:
if not storage.getlist('SMA_Long_list'):
print('SMA: Not yet enough data to determine trend')
else:
gu.PrintIndicatorTrend('SMA', storage.getlist('SMA_Short_list'), storage.getlist(
'SMA_Long_list'), storage.getlist('SMA_Diff_list'), gc.SMA.DiffDown, gc.SMA.DiffUp)
def indicator():
# We can start FastStochRSIK calculations once we have
# FastStochRSIKPeriod candles, otherwise we append None until met
if len(storage.getlist('RSI_ind_list')) >= gc.FastStochRSIK.Period:
try:
storage.writelist('FastStochRSIK_ind_list', Helpers.FastStochK(
storage.getlist('RSI_ind_list'), gc.FastStochRSIK.Period))
except ZeroDivisionError:
pass
if 'FastStochRSIK' in gc.Trader.VerboseIndicators:
if not storage.getlist('FastStochRSIK_ind_list'):
print('FastStochRSIK: Not yet enough data to calculate')
else:
print('FastStochRSIK:', storage.getlist('FastStochRSIK_ind_list')[-1])
def indicator():
# We can start BollBand calculations once we have BollBandPeriod candles
if len(ldb.price_list) >= gc.BollBands.Period:
storage.writelist(
'BollBands_Middle_list', Helpers.SMA(ldb.price_list, gc.BollBands.Period))
storage.writelist('BollBands_Upper_list', storage.getlist(
'BollBands_Middle_list')[-1] + (Helpers.StdDev(ldb.price_list, gc.BollBands.Period) * 2))
storage.writelist('BollBands_Lower_list', storage.getlist(
'BollBands_Middle_list')[-1] - (Helpers.StdDev(ldb.price_list, gc.BollBands.Period) * 2))
def indicator():
# We can start calculations once we have two periods
if len(ldb.price_list) >= (gc.ChandExit.Period * 2):
storage.writelist(
'ChandExit_TR_list', Helpers.TrueRange(ldb.price_list, gc.ChandExit.Period))
if len(storage.getlist('ChandExit_TR_list')) >= gc.ChandExit.Period:
try:
storage.writelist('ChandExit_ATR_list', Helpers.WMA(storage.getlist(
'ChandExit_TR_list'), storage.getlist('ChandExit_ATR_list'), gc.ChandExit.Period))
storage.writelist('ChandExit_Long_list', max(
ldb.price_list[-gc.ChandExit.Period:]) - storage.getlist('ChandExit_ATR_list')[-1] * gc.ChandExit.Multiplier)
storage.writelist('ChandExit_Short_list', min(
ldb.price_list[-gc.ChandExit.Period:]) + storage.getlist('ChandExit_ATR_list')[-1] * gc.ChandExit.Multiplier)
# For an empty sequence at low volatility or high frequency
except ValueError:
pass
# Use a hack for determining signals despite it's intended confirmation
# usage
cp = ldb.price_list[-1]
if cp < storage.getlist('ChandExit_Long_list')[-1]:
storage.writelist('ChandExit_signal_list', 1)
# We can start DEMAs once we have max period candles
if len(storage.getlist('MACD_Long_list')) >= max(gc.MACD.LongPeriod, gc.MACD.ShortPeriod):
storage.writelist('DMACD_Short_list', Helpers.DEMA(storage.getlist(
'MACD_Short_list'), storage.getlist('DMACD_Short_list'), gc.MACD.ShortPeriod))
storage.writelist('DMACD_Long_list', Helpers.DEMA(storage.getlist(
'MACD_Long_list'), storage.getlist('DMACD_Long_list'), gc.MACD.LongPeriod))
storage.writelist('DMACD_ind_list', storage.getlist(
'DMACD_Short_list')[-1] - storage.getlist('DMACD_Long_list')[-1])
# We need MACDSignal DMACDs before generating Signal
if len(storage.getlist('DMACD_Long_list')) >= (gc.MACD.SignalPeriod +
(abs(gc.MACD.SignalPeriod - gc.MACD.LongPeriod))):
storage.writelist('DMACD_Signal_list', Helpers.DEMA(storage.getlist(
'MACD_Signal_list'), storage.getlist('DMACD_Signal_list'), gc.MACD.SignalPeriod))
storage.writelist('DMACD_Histogram_list', storage.getlist(
'DMACD_ind_list')[-1] - storage.getlist('DMACD_Signal_list')[-1])
if 'DMACD' in gc.Trader.VerboseIndicators:
if not storage.getlist('DMACD_Signal_list'):
print('DMACD: Not yet enough data to determine trend')
else:
gu.PrintIndicatorTrend('DMACD', storage.getlist('DMACD_ind_list'), storage.getlist(
'DMACD_Signal_list'), storage.getlist('DMACD_ind_list'), gc.DMACD.DiffDown, gc.DMACD.DiffUp)
storage.writelist('DMACD_ind_list', storage.getlist(
'DMACD_Short_list')[-1] - storage.getlist('DMACD_Long_list')[-1])
# We need MACDSignal DMACDs before generating Signal
if len(storage.getlist('DMACD_Long_list')) >= (gc.MACD.SignalPeriod +
(abs(gc.MACD.SignalPeriod - gc.MACD.LongPeriod))):
storage.writelist('DMACD_Signal_list', Helpers.DEMA(storage.getlist(
'MACD_Signal_list'), storage.getlist('DMACD_Signal_list'), gc.MACD.SignalPeriod))
storage.writelist('DMACD_Histogram_list', storage.getlist(
'DMACD_ind_list')[-1] - storage.getlist('DMACD_Signal_list')[-1])
if 'DMACD' in gc.Trader.VerboseIndicators:
if not storage.getlist('DMACD_Signal_list'):
print('DMACD: Not yet enough data to determine trend')
else:
gu.PrintIndicatorTrend('DMACD', storage.getlist('DMACD_ind_list'), storage.getlist(
'DMACD_Signal_list'), storage.getlist('DMACD_ind_list'), gc.DMACD.DiffDown, gc.DMACD.DiffUp)
storage.writelist('DMI_PosDM_list', 0)
storage.writelist('DMI_NegDM_list', 0)
elif UpMove > DownMove:
storage.writelist('DMI_PosDM_list', UpMove)
storage.writelist('DMI_NegDM_list', 0)
elif UpMove < DownMove:
storage.writelist('DMI_PosDM_list', 0)
storage.writelist('DMI_NegDM_list', DownMove)
if len(storage.getlist('DMI_PosDM_list')) >= gc.ATR.Period and len(storage.getlist('ATR_TR_list')) >= gc.ATR.Period:
storage.writelist('DMI_PosDMWMA_list',
Helpers.WMA(storage.getlist('DMI_PosDM_list'),
storage.getlist('DMI_PosDMWMA_list'), gc.ATR.Period))
storage.writelist('DMI_NegDMWMA_list',
Helpers.WMA(storage.getlist('DMI_NegDM_list'),
storage.getlist('DMI_NegDMWMA_list'), gc.ATR.Period))
storage.writelist('DMI_PosDI_list',
storage.getlist('DMI_PosDMWMA_list')[-1]
/ storage.getlist('ATR_ind_list')[-1])
storage.writelist('DMI_NegDI_list',
storage.getlist('DMI_NegDMWMA_list')[-1]
/ storage.getlist('ATR_ind_list')[-1])
DIDiff = abs(storage.getlist('DMI_PosDI_list')[-1]
- storage.getlist('DMI_NegDI_list')[-1])
try:
storage.writelist('DMI_DX_list', DIDiff
/ (storage.getlist('DMI_PosDI_list')[-1]
+ storage.getlist('DMI_NegDI_list')[-1]))
# ADX
if len(storage.getlist('DMI_DX_list')) >= (gc.ATR.Period * 2):
storage.writelist('DMI_ind_list',
'DMACD_Short_list')[-1] - storage.getlist('DMACD_Long_list')[-1])
# We need MACDSignal DMACDs before generating Signal
if len(storage.getlist('DMACD_Long_list')) >= (gc.MACD.SignalPeriod +
(abs(gc.MACD.SignalPeriod - gc.MACD.LongPeriod))):
storage.writelist('DMACD_Signal_list', Helpers.DEMA(storage.getlist(
'MACD_Signal_list'), storage.getlist('DMACD_Signal_list'), gc.MACD.SignalPeriod))
storage.writelist('DMACD_Histogram_list', storage.getlist(
'DMACD_ind_list')[-1] - storage.getlist('DMACD_Signal_list')[-1])
if 'DMACD' in gc.Trader.VerboseIndicators:
if not storage.getlist('DMACD_Signal_list'):
print('DMACD: Not yet enough data to determine trend')
else:
gu.PrintIndicatorTrend('DMACD', storage.getlist('DMACD_ind_list'), storage.getlist(
'DMACD_Signal_list'), storage.getlist('DMACD_ind_list'), gc.DMACD.DiffDown, gc.DMACD.DiffUp)