添加默认均线
This commit is contained in:
@@ -62,7 +62,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"3600": 0
|
||||
}
|
||||
can_short = True
|
||||
lev = 2.0
|
||||
lev = 1.0
|
||||
stoploss = -0.5
|
||||
use_custom_stoploss = True
|
||||
|
||||
@@ -72,14 +72,14 @@ class ChanLun_BTC_30(IStrategy):
|
||||
trailing_only_offset_is_reached = False
|
||||
|
||||
position_adjustment_enable = True
|
||||
startup_candle_count = 600
|
||||
startup_candle_count = 780
|
||||
|
||||
time5 = 5
|
||||
time15 = 15
|
||||
time30 = 30
|
||||
time60 = 60
|
||||
time4h = 240
|
||||
time30 = 60
|
||||
time30 = 15
|
||||
last_time = datetime.now()
|
||||
chan = ChanLun()
|
||||
chanpy = ChanPY()
|
||||
@@ -104,6 +104,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#dataframe_1m = resample_to_interval(dataframe, self.get_ticker_indicator() * 43200)
|
||||
dataframe = self.add_indicators(dataframe)
|
||||
dataframe_5 = self.add_indicators(dataframe_5)
|
||||
dataframe_15 = self.add_indicators(dataframe_15)
|
||||
dataframe_30 = self.add_indicators(dataframe_30)
|
||||
dataframe_60 = self.add_indicators(dataframe_60)
|
||||
dataframe_4h = self.add_indicators(dataframe_4h)
|
||||
@@ -111,9 +112,9 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#self.chan.plot_dual(dataframe_5, dataframe_30)
|
||||
chanpy_state = self.chanpy.get_bsp_state(dataframe_5)
|
||||
dataframe_5['chanpy_state'] = chanpy_state
|
||||
state_list = self.chan.get_klc_state_list(dataframe_60)
|
||||
dataframe_60['state'] = state_list
|
||||
dataframe_60['fx'] = state_list
|
||||
state_list = self.chan.get_klc_state_list(dataframe_15)
|
||||
dataframe_15['state'] = state_list
|
||||
dataframe_15['fx'] = state_list
|
||||
|
||||
#bi_list_1 = self.chan.get_bi_list(dataframe)
|
||||
#bi_list_5 = self.chan.get_bi_list(dataframe_5)
|
||||
@@ -130,7 +131,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
print("-------------------------------------------------------------------------------")
|
||||
self.last_time = datetime.now()
|
||||
dataframe = resampled_merge(dataframe, dataframe_5)
|
||||
dataframe = resampled_merge(dataframe, dataframe_60)
|
||||
dataframe = resampled_merge(dataframe, dataframe_15)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_30)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_60)
|
||||
#dataframe = resampled_merge(dataframe, dataframe_4h)
|
||||
@@ -155,10 +156,10 @@ class ChanLun_BTC_30(IStrategy):
|
||||
df['macd'] = macd['macd']
|
||||
df['macdsignal'] = macd['macdsignal']
|
||||
df['macdhist'] = macd['macdhist']
|
||||
df['ma5'] = ta.MA(df, timeperiod=5)
|
||||
df['ma10'] = ta.MA(df, timeperiod=10)
|
||||
df['ma30'] = ta.EMA(df, timeperiod=30)
|
||||
df['ma250'] = ta.MA(df, timeperiod=250)
|
||||
df['ema5'] = ta.EMA(df, timeperiod=5)
|
||||
df['ema10'] = ta.EMA(df, timeperiod=10)
|
||||
df['ema26'] = ta.EMA(df, timeperiod=26)
|
||||
df['ema52'] = ta.EMA(df, timeperiod=52)
|
||||
df['rsi'] = ta.RSI(df, timeperiod=14)
|
||||
df['volume_ratio'] = self.cal_volume_ratio(df)
|
||||
return df
|
||||
@@ -266,7 +267,13 @@ class ChanLun_BTC_30(IStrategy):
|
||||
"""
|
||||
# Obtain pair dataframe (just to show how to access it)
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
|
||||
#last_candle = dataframe.iloc[-1].squeeze()
|
||||
last_candle = dataframe.iloc[-1].squeeze()
|
||||
ema5 = 'resample_{}_ema5'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema10 = 'resample_{}_ema10'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema26 = 'resample_{}_ema26'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema52 = 'resample_{}_ema52'.format(self.get_ticker_indicator()*self.time30)
|
||||
print(last_candle[ema5], last_candle[ema10], last_candle[ema26], last_candle[ema52])
|
||||
print(last_candle['close'])
|
||||
klc_list = self.chan.get_klc_list(resample_to_interval(dataframe, self.get_ticker_indicator() * self.time30))
|
||||
bi_list = self.chan.cal_bi_list(klc_list)
|
||||
if self.last_order is None:
|
||||
@@ -295,10 +302,18 @@ class ChanLun_BTC_30(IStrategy):
|
||||
#chanpy_state_str = 'resample_{}_chanpy_state'.format(self.get_ticker_indicator()*self.time5)
|
||||
shift_time = self.time30
|
||||
strength = 0.9
|
||||
ema5 = 'resample_{}_ema5'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema10 = 'resample_{}_ema10'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema26 = 'resample_{}_ema26'.format(self.get_ticker_indicator()*self.time30)
|
||||
ema52 = 'resample_{}_ema52'.format(self.get_ticker_indicator()*self.time30)
|
||||
dataframe.loc[
|
||||
(
|
||||
(
|
||||
(dataframe[ema5] > dataframe[ema10]) &
|
||||
(dataframe[ema10] > dataframe[ema26]) &
|
||||
(dataframe[ema26] > dataframe[ema52]) &
|
||||
(dataframe[ema52] > 0)
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) == "-10")
|
||||
#(dataframe[state_str].shift(shift_time) == "-10")
|
||||
#(dataframe[fx_str].shift(shift_time) == -1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == 1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") &
|
||||
@@ -310,7 +325,7 @@ class ChanLun_BTC_30(IStrategy):
|
||||
dataframe.loc[
|
||||
(
|
||||
#(dataframe['state'] == "-30")
|
||||
(dataframe[state_str].shift(shift_time) == "10")
|
||||
(dataframe[state_str].shift(shift_time) == "101")
|
||||
#(dataframe[fx_str].shift(shift_time) == 1)
|
||||
#(dataframe[chanpy_state_str].shift(shift_time+30) == -1)
|
||||
#(dataframe['resample_{}_state'.format(self.get_ticker_indicator()*self.time5)].shift(self.time5) == "-10") &
|
||||
|
||||
@@ -3939,9 +3939,45 @@
|
||||
tvWidget.macdChart = macdChart;
|
||||
tvWidget.state.isInitialized = true;
|
||||
|
||||
// 初始化默认EMA配置(仅在首次初始化时)
|
||||
if (movingAverages.length === 0) {
|
||||
console.log('初始化默认EMA指标');
|
||||
|
||||
// 添加默认EMA配置
|
||||
const defaultEMAs = [
|
||||
{ type: 'EMA', length: 5, color: '#FF0000', name: 'EMA5' }, // 红色
|
||||
{ type: 'EMA', length: 10, color: '#0000FF', name: 'EMA10' }, // 蓝色
|
||||
{ type: 'EMA', length: 26, color: '#00FF00', name: 'EMA26' }, // 绿色
|
||||
{ type: 'EMA', length: 52, color: '#800080', name: 'EMA52' } // 紫色
|
||||
];
|
||||
|
||||
defaultEMAs.forEach(ema => {
|
||||
const config = {
|
||||
id: ++maIdCounter,
|
||||
type: ema.type,
|
||||
length: ema.length,
|
||||
source: 'close',
|
||||
smoothType: 'none',
|
||||
smoothLength: 3,
|
||||
lineWidth: 1, // 1px线宽
|
||||
lineStyle: 0, // 实线
|
||||
color: ema.color,
|
||||
visible: true
|
||||
};
|
||||
|
||||
movingAverages.push(config);
|
||||
console.log(`添加默认${ema.name}:`, ema.color);
|
||||
});
|
||||
|
||||
console.log('默认EMA配置完成,共添加', movingAverages.length, '个指标');
|
||||
}
|
||||
|
||||
// 添加均线到图表
|
||||
addMovingAveragesToChart(candles);
|
||||
|
||||
// 更新均线面板显示
|
||||
updateMAPanel();
|
||||
|
||||
// 绑定同步事件
|
||||
bindSyncEvents(mainChartContainer, volumeChartContainer, atrChartContainer, macdChartContainer, mainChart, volumeChart, atrChart, macdChart, showMacd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user