Pine语言调用新增投资者人数宏观数据进行反指交易

Author: 扫地僧, Date: 2024-02-02 11:24:40
Tags:


/*backtest
start: 2022-01-26 09:00:00
end: 2024-02-01 15:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/

// 图表地址https://www.datadata.cn/queries/a10ea45c-1674-48ef-b414-cc17a7e4a548
var chart_data = "https://www.datadata.cn/api/v1/query/a10ea45c-1674-48ef-b414-cc17a7e4a548/data"
add_investor = request.data(chart_data, "$.add_investor")
idx_price = request.data(chart_data, "$.close_price")

plot(add_investor, "股市新增人口")
plot(idx_price, "股指价格")
// 反指交易
avg_investor = ta.ema(add_investor[1], 30)
if strategy.position_size == 0
    if add_investor > avg_investor*1.1
        runtime.log("新增人口:", add_investor, "近30天平均:", avg_investor, "#ff0000")
        strategy.entry("Enter Short", strategy.short)
    else if add_investor < avg_investor*0.9
        runtime.log("新增人口:", add_investor, "近30天平均:", avg_investor, "#ff0000")
        strategy.entry("Enter Long", strategy.long)
        

更多内容