如何将指标转化为策略?

时间:2021-06-21 02:36:37

标签: pine-script

我知道它需要以 strategy("title", overlay=true) 开头。

我为多头或空头头寸设置了以下条件:

LongSignal = not Short and (close>high[25]) and CP>BP and (close>LL2[25] and close>LL1[25]) and (low>LL2[25] and low>LL1[25])
ShortSignal = not Long and (close<high[25]) and CP<BP and (close<LL2[25] and close<LL1[25]) and (high<LL2[25] and high<LL1[25])

我如何让 TradingView 上的策略测试器正确识别这些,因为现在我希望它在绘制多头信号标签时输入多头,然后在绘制空头信号时输入空头信号。

>

1 个答案:

答案 0 :(得分:0)


//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100, process_orders_on_close = true)


LongSignal = not Short and (close>high[25]) and CP>BP and (close>LL2[25] and close>LL1[25]) and (low>LL2[25] and low>LL1[25])
ShortSignal = not Long and (close<high[25]) and CP<BP and (close<LL2[25] and close<LL1[25]) and (high<LL2[25] and high<LL1[25])

if (LongSignal)
    strategy.entry("My Long Entry Id", strategy.long)

if (ShortSignal)
    strategy.entry("My Short Entry Id", strategy.short)