Some quantitative strategies (will be updated)

In my previous article, I described how to backtest quantitative trading on the TradingView platform and today, I will share some strategies. I will separate them into sections and update one strategy each time. I will continue to update them, so you can look forward to it. Thank you for your support and encouragement. I hope you will subscribe to my YouTube channel @shousake

之前的文章中,我讲述了如何在TradingView平台进行量化交易的回测,今天我们来分享一些策略.我会分开来,每期更新一种策略,会持续更新,大家可以期待一下,感谢大家的支持和鼓励,希望大家多多订阅一下我的YouTube频道@shousake


The Moving Average/MA均线


The Moving Average (MA) is one of the most widely used technical indicators in financial markets. It smooths out price data by calculating the average price over a specific period, helping traders identify trends and reduce the impact of short-term price fluctuations. Common types include the Simple Moving Average (SMA) and the Exponential Moving Average (EMA). While the SMA gives equal weight to all data points, the EMA assigns more weight to recent prices, making it more responsive to market changes. Traders often use MA crossovers or the slope of the line to determine buy and sell signals.


移动平均线(MA)是金融市场中最常用的技术指标之一。它通过计算一段时间内的平均价格来平滑价格数据,帮助交易者识别趋势,并减少短期价格波动的影响。常见的类型有简单移动平均线(SMA)和指数移动平均线(EMA)。SMA对所有数据点赋予相同的权重,而EMA对最近的价格赋予更高的权重,使其对市场变化更敏感。交易者通常会利用均线的交叉或斜率来判断买入和卖出的时机。

The following code is a trading code based on the moving average (MA) and is written in Pine language.

以下代码是基于移动平均线(MA)的交易代码,用Pine语言编写。

//@version=5
strategy("MA80 Daily Strategy", overlay=true, margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=5,pyramiding=0)

// === 参数 ===
maLength = 80
src = close
ma = ta.sma(src, maLength)
startDate = input.time(timestamp("01 Jan 2023 00:00 +0000"), "Start Date", group="Time Filter")
endDate = input.time(timestamp("31 Dec 2024 23:59 +0000"), "End Date", group="Time Filter")
inDateRange = time >= startDate and time <= endDate
// 绘制 MA
plot(ma, color=color.orange, title="MA80")

// 判断每日最后一根K线
isNewDay = ta.change(time("D")) != 0  // 新的一天
isLastBarOfDay = not isNewDay[1] and isNewDay // 当天最后一根

// 策略逻辑
longCond = close < ma
shortCond = close > ma

// 每日最后一根K线时才操作
if isLastBarOfDay and inDateRange
    // 平掉所有仓位
    //strategy.close_all(comment="Daily Close")

    // 建仓
    if longCond
        strategy.entry("Long", strategy.long)
    if shortCond
        strategy.entry("Short", strategy.short)

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注