
等级: 专业版
- 注册:
- 2021-5-20
- 曾用名:
|
前面我问了这个问题,链接如下:https://www.weistock.com/bbs/for ... mp;page=1#pid148537
我已经写好代码了,都编译成功了,但是想在k线图上看 好像显示不出来,反显的问题详见截图
python代码如下:
from PythonApi import *
import numpy as np
import pandas as pd
import talib as ta
def init(context):
# 初始化全局变量
context.s1 = "SZ000001" # 平安银行股票
context.window_short = 5 # 短期均线窗口
context.window_long = 10 # 长期均线窗口
def handle_bar(context):
# 获取最近10天的收盘价(确保能计算10日均线)
close_prices = history_bars(context.s1, context.window_long, '1d', 'close')
# 检查数据是否足够
if len(close_prices) < context.window_long:
print(f'获取数据不足{context.window_long}天,当前仅{len(close_prices)}条')
return
# 转换为pandas Series便于计算
close_series = pd.Series(close_prices)
# 计算均线(使用numpy的滑动窗口函数)
context.ma5 = np.convolve(close_prices, np.ones(context.window_short)/context.window_short, 'valid')[-1]
context.ma10 = np.convolve(close_prices, np.ones(context.window_long)/context.window_long, 'valid')[-1]
pel代码如下:
RUNMODE:0;
Py_Import testma;
//触发Python中的Handle_bar方法
FIREPYHANDLEBAR;
//得到2个返回值,注意变量名大小写敏感
Ma5:GETPYTHONVAL('ma5');
Ma10:GETPYTHONVAL('ma10');
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?
x
|