超级趋势策略

Author: 扫地僧, Date: 2022-04-25 21:07:09
Tags: 趋势Pine

应平台用户要求, 平台正在兼容TradingView的Pine语言函数库,现已完成工作

语法完全兼容到v5版本 ta库指标完全实现 math库完全实现 input输入参数自动识别到界面 request.security对heikinashi的支持 strategy库实现简单入场退场(暂不支持条件单) plot/plotchar/alert/alertcondition 兼容 strategy函数pyramiding参数控制仓位的实现 对语言的函数完全支持是一个持续努力的过程, 此公开版本为方便用户测试提前公开

后期FMZ会进行持续不段的增加完善对TradingView的Pine语言的函数库支持, 有需求可以本策略留言

注: 如果遇到变量未定义证明尚不支持此属性可删除相关调用(比如颜色画线相关)后续后逐渐完善支持

img


/*backtest
start: 2021-04-27 00:00:00
end: 2022-04-26 23:59:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/
strategy("SuperTrend", overlay=true)

[supertrend, direction] = ta.supertrend(input(3, "factor"), input.int(2, "atrPeriod"))

plot(direction < 0 ? supertrend : na, "Up direction", color = color.green, style=plot.style_linebr)
plot(direction > 0 ? supertrend : na, "Down direction", color = color.red, style=plot.style_linebr)

var qty = math.floor(5 * strategy.equity / close / syminfo.pointvalue)

if direction < 0
    if supertrend > supertrend[2]
        strategy.entry("BUY", strategy.long, qty=qty)
    else if strategy.position_size < 0
        strategy.close_all()
else if direction > 0
    if supertrend < supertrend[3]
        strategy.entry("SHORT", strategy.short, qty=qty)
    else if strategy.position_size > 0
        strategy.close_all()


相关内容

更多内容