添加macd周期参数设置
This commit is contained in:
+38
-8
@@ -33,8 +33,11 @@ class TRADE_POINT_TYPE:
|
||||
SELL3 = -3 # 三类卖点
|
||||
|
||||
app = Flask(__name__)
|
||||
macd_factor = 2 *6
|
||||
macd_factor = 2
|
||||
smooth_factor = 1
|
||||
macd_fast_period = 12 * macd_factor
|
||||
macd_slow_period = 26 * macd_factor
|
||||
macd_signal_period = 9 * smooth_factor
|
||||
# 初始化交易所
|
||||
exchange = ccxt.binance({
|
||||
'enableRateLimit': True,
|
||||
@@ -422,10 +425,8 @@ def get_a_stock_kl_data(symbol, timeframe, limit=100000, start_time=None, end_ti
|
||||
return None
|
||||
|
||||
def add_indicators(df):
|
||||
fast = 12 * macd_factor
|
||||
slow = 26 * macd_factor
|
||||
period = 9 * smooth_factor
|
||||
macd = ta.MACD(df, fastperiod=fast, slowperiod=slow, signalperiod=period)
|
||||
global macd_fast_period, macd_slow_period, macd_signal_period
|
||||
macd = ta.MACD(df, fastperiod=macd_fast_period, slowperiod=macd_slow_period, signalperiod=macd_signal_period)
|
||||
|
||||
df['macd'] = macd['macd']
|
||||
df['macdsignal'] = macd['macdsignal']
|
||||
@@ -510,10 +511,11 @@ def add_indicators(df):
|
||||
|
||||
def calculate_macd(df):
|
||||
"""计算MACD指标"""
|
||||
exp1 = df['close'].ewm(span=12*macd_factor, adjust=False).mean()
|
||||
exp2 = df['close'].ewm(span=26*macd_factor, adjust=False).mean()
|
||||
global macd_fast_period, macd_slow_period, macd_signal_period
|
||||
exp1 = df['close'].ewm(span=macd_fast_period, adjust=False).mean()
|
||||
exp2 = df['close'].ewm(span=macd_slow_period, adjust=False).mean()
|
||||
macd = exp1 - exp2
|
||||
signal = macd.ewm(span=9 * smooth_factor, adjust=False).mean()
|
||||
signal = macd.ewm(span=macd_signal_period, adjust=False).mean()
|
||||
histogram = macd - signal
|
||||
|
||||
return {
|
||||
@@ -1845,6 +1847,34 @@ def search_stock():
|
||||
return jsonify({'error': str(e)})
|
||||
|
||||
|
||||
@app.route('/api/macd_config', methods=['GET', 'POST'])
|
||||
def macd_config():
|
||||
"""获取或设置MACD参数"""
|
||||
global macd_fast_period, macd_slow_period, macd_signal_period
|
||||
if request.method == 'GET':
|
||||
return jsonify({
|
||||
'fast': macd_fast_period,
|
||||
'slow': macd_slow_period,
|
||||
'signal': macd_signal_period
|
||||
})
|
||||
else:
|
||||
data = request.get_json(silent=True) or {}
|
||||
fast = data.get('fast')
|
||||
slow = data.get('slow')
|
||||
signal = data.get('signal')
|
||||
if fast is not None:
|
||||
macd_fast_period = int(fast)
|
||||
if slow is not None:
|
||||
macd_slow_period = int(slow)
|
||||
if signal is not None:
|
||||
macd_signal_period = int(signal)
|
||||
return jsonify({
|
||||
'fast': macd_fast_period,
|
||||
'slow': macd_slow_period,
|
||||
'signal': macd_signal_period
|
||||
})
|
||||
|
||||
|
||||
def get_uncompleted_seg_list(seg_list, client_tz):
|
||||
"""获取未完成线段列表,正确处理倒数第二个和最后一个未完成线段"""
|
||||
uncompleted_segs = [seg for seg in seg_list if not seg.is_sure]
|
||||
|
||||
Reference in New Issue
Block a user