SMA
定义
public static IEnumerable<SmaResult> GetSma( int lookbackPeriods)
参数
| 参数名 |
类型 |
描述 |
| lookbackPeriods |
Int |
回溯周期 |
返回值
| 返回值 |
类型 |
描述 |
| Date |
DateTime |
时间戳 |
| Sma |
decimal? |
简单移动平均值 |
///清洗股票数据 天数据
QuoteHistoryDay(10, (dic) =>
{
if (dic.Count > 0)
{
foreach (var item in dic.Keys)
{
///获取指标结果
var resp = dic[item].GetSma(2);
Console.WriteLine(resp.ToJson());
}
}
});
def init(self):
#初始化T+1 取消时间为120秒
self.SetConfig(1,120)
self.art = {}
self.invested = {}
logger.info("进入MyTestAlgorithm init方法:")
#添加单个指数 分钟为Resolution.Minute
self.index300 = self.AddIndex("000300.XSHG", Resolution.Daily).symbol
#添加指数下的所有 分钟为Resolution.Minute
stock_list=self.FillStocks(["000001.XSHE","000004.XSHE"],"",Resolution.Daily)
self.set_benchmark(self.index300)
# 创建布林带指标(20期,2个标准差)
self.bb = self.BB(stock_list[0].Symbol, 20, 2, MovingAverageType.Simple)
# 创建SMA指标
self.sma_fast = self.SMA(stock_list[0].Symbol, 20, Resolution.Daily) # 快速SMA
self.sma_slow = self.SMA(stock_list[0].Symbol, 50, Resolution.Daily) # 慢速SMA
# 注册指标更新
self.RegisterIndicator(stock_list[0].Symbol, self.sma_fast, Resolution.Daily)
self.RegisterIndicator(stock_list[0].Symbol, self.sma_slow, Resolution.Daily)
#数据来了触发事件
def ondata(self,slice):
logger.info(fr"Symbol:{self.Time} ")
fast_sma = self.sma_fast.Current.Value
slow_sma = self.sma_slow.Current.Value
logger.info(f"fast_sma:{fast_sma}:slow_sma={slow_sma} ")