指標變策略,快速回測! 代碼及課件

pine速成视频 / 3645人浏览 / 2人评论
## 指標快速回測 代碼 >相關的視頻學習資料在大陸版抖音,tiktok,blibli,油管,上搜索'量化金城武'即可找到 - **pine V4版本 指標變策略代碼(固定止盈止損)** ``` strategy(......) //首先修改腳本屬性 // 开仓信号 if (做漲條件) strategy.entry("Long", strategy.long) if (做空條件) strategy.entry("Short", strategy.short) // 固定止盈止損設置 stop_loss_pct = input(title="止損 (%)", type=input.float, defval=2.0, step=0.1) take_profit_pct = input(title="止盈 (%)", type=input.float, defval=2.0, step=0.1) long_stop_loss = strategy.position_avg_price*(1-stop_loss_pct/100) long_take_profit = strategy.position_avg_price*(1+take_profit_pct/100) short_stop_loss = strategy.position_avg_price*(1+stop_loss_pct/100) short_take_profit = strategy.position_avg_price*(1-take_profit_pct/100) strategy.exit("Exit Long", "Long", stop=long_stop_loss, limit=long_take_profit) strategy.exit("Exit Short", "Short", stop=short_stop_loss, limit=short_take_profit) ``` ### pine V5版本指標變策略代碼(固定止盈止損) ``` strategy(......) //首先修改腳本屬性 //止盈止損設置 take_profit_pct = input.float(defval = 2.0,title = '止盈', step=0.1) stop_loss_pct = input.float(defval = 1.0,title = '止損', step=0.1) //设定出场条件,算出買漲時候的止盈止損的價格 long_stop_loss = strategy.position_avg_price*(1-stop_loss_pct/100) long_take_profit = strategy.position_avg_price*(1+take_profit_pct/100) //當做空的時候,止盈止損的價格是不一樣的 short_stop_loss = strategy.position_avg_price*(1+stop_loss_pct/100) short_take_profit = strategy.position_avg_price*(1-take_profit_pct/100) //第八步逻辑执行 if 做漲條件 strategy.entry('long',strategy.long,comment = '做多') //進場做多 strategy.exit('exit','long',limit = long_take_profit, stop = long_stop_loss, comment_profit = '盈',comment_loss = '损') //設定做多的止盈止損 if 做空條件 strategy.entry('short',strategy.short,comment = '做空') //進場做空 strategy.exit('exit','short',limit = short_take_profit, stop = short_stop_loss, comment_profit = '盈',comment_loss = '损') //設定做空的止盈止損 ```

2 条评论

old_zest
4月前
老师好,非常感谢,已经使用您的框架回测了几个指标了。但是有一个问题,为什么在止盈止损里面老师要使用limit和stop关键词并且前置一个平均持仓计算止盈止损点位而不用loss和profit关键词呢?exit函数里自带的和老师使用的这个在执行上会有什么区别吗?
六月郑婷
1年前
怎么加您微信呢老师

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我