资源加载中... loading...

移植Pine语言单品种成为多品种策略

Author: ianzeng123, Date: 2023-09-01 19:41:27
Tags:

“Bottom and top hunter”,"顶部和底部猎人"指标。它结合了两个流行的技术分析工具,斐波那契回撤水平和相对强度指数(RSI),用来识别市场的潜在交易机会。


/*backtest
start: 2023-05-08 09:00:00
end: 2023-08-01 15:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES","depthDeep":20}]
args: [["symbol","i888,rb888,hc888"]]
*/

function main() {
    $.CTA(symbol, function(st) {
        var r = st.records
        if (r.length < rsi_length) {
            return
        }
        var fib_range = TA.Highest(r, range, 'High') - TA.Lowest(r, range, 'Low')
        var fib_level_0 = TA.Highest(r, range, 'High') - (fib_range * fib_0)
        var fib_level_1 = TA.Highest(r, range, 'High') - (fib_range * fib_1)
        var rsi_value = TA.RSI(r, rsi_length)
        $.PlotMultRecords("期货合约" + st.symbol, "k线", r, {layout: 'single', col: 12, height: '600px'})
        $.PlotMultLine("期货合约" + st.symbol, "斐波那契顶部", fib_level_0, r[r.length - 2].Time)
        $.PlotMultLine("期货合约" + st.symbol, "斐波那契底部", fib_level_1, r[r.length - 2].Time)

        var buy_condition = r[r.length-2].Close > fib_level_1 && rsi_value[rsi_value.length - 3] < rsi_oversold && rsi_value[rsi_value.length - 2] > rsi_oversold;
        var sell_condition = r[r.length-2].Close < fib_level_0 && rsi_value[rsi_value.length - 3] > rsi_overbought && rsi_value[rsi_value.length - 2] < rsi_overbought;
        if (st.position.amount <= 0 && buy_condition) {
            Log("当前持仓", st.position);
            return st.position.amount < 0 ? 2 : 1
        } else if (st.position.amount >= 0 && sell_condition) {
            Log("当前持仓", st.position);
            return st.position.amount > 0 ? -2 : -1
        }
    
    });
}
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6