本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
study("Turtles Modified Alert", shorttitle="TurtlesV2", overlay=true)
// === BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1)
FromDay = input(defval = 1, title = "From Day", minval = 1)
FromYear = input(defval = 2019, title = "From Year", minval = 2019)
ToMonth = input(defval = 1, title = "To Month", minval = 1)
ToDay = input(defval = 1, title = "To Day", minval = 1)
ToYear = input(defval = 9999, title = "To Year", minval = 9999)
enter_fast = input(20, minval=1)
exit_fast = input(10, minval=1)
enter_slow = input(55, minval=1)
exit_slow = input(20, minval=1)
fastL = highest(enter_fast)
fastLC = lowest(exit_fast)
fastS = lowest(enter_fast)
fastSC = highest(exit_fast)
slowL = highest(enter_slow)
slowLC = lowest(exit_slow)
slowS = lowest(enter_slow)
slowSC = highest(exit_slow)
enterL1 = high > fastL[1] and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
exitL1 = low <= fastLC[1] and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
enterL1_filt = enterL1 and not exitL1
exitL1_filt = exitL1 and not enterL1
prevL1 = 0
prevL1 := exitL1_filt ? 1 : enterL1_filt ? -1 : prevL1[1]
enterL1_final = enterL1_filt and prevL1[1] == 1
exitL1_final = exitL1_filt and prevL1[1] == -1
enterS1 = low < fastS[1] and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
exitS1 = high >= fastSC[1] and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
enterS1_filt = enterS1 and not exitS1
exitS1_filt = exitS1 and not enterS1
prevS1 = 0
prevS1 := exitS1_filt ? 1 : enterS1_filt ? -1 : prevS1[1]
enterS1_final = enterS1_filt and prevS1[1] == 1
exitS1_final = exitS1_filt and prevS1[1] == -1
enterL2 = high > slowL[1] and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
exitL2 = low <= slowLC[1] and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
enterL2_filt = enterL2 and not exitL2
exitL2_filt = exitL2 and not enterL2
prevL2 = 0
prevL2 := exitL2_filt ? 1 : enterL2_filt ? -1 : prevL2[1]
enterL2_final = enterL2_filt and prevL2[1] == 1
exitL2_final = exitL2_filt and prevL2[1] == -1
enterS2 = low < slowS[1] and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
exitS2 = high >= slowSC[1] and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59))
enterS2_filt = enterS2 and not exitS2
exitS2_filt = exitS2 and not enterS2
prevS2 = 0
prevS2 := exitS2_filt ? 1 : enterS2_filt ? -1 : prevS2[1]
enterS2_final = enterS2_filt and prevS2[1] == 1
exitS2_final = exitS2_filt and prevS2[1] == -1
//bgcolor(exitL1 or exitL2? red: enterL1 or enterL2? navy:white)
// Plotting
// fast L
plotshape(enterL1_final, color = blue, text = "fL", style=shape.arrowup)
plotshape(exitL1_final, color = fuchsia, text = "fLc", style=shape.arrowdown)
// fast S
plotshape(enterS1_final, color = red, text = "fS", style=shape.arrowdown)
plotshape(exitS1_final, color = fuchsia, text = "fSc", style=shape.arrowup)
// slow L
plotshape(enterL2_final, color = blue, text = "sL", style=shape.arrowup)
plotshape(exitL2_final, color = fuchsia, text = "sLc", style=shape.arrowdown)
// slow S
plotshape(enterS2_final, color = red, text = "sS", style=shape.arrowdown)
plotshape(exitS2_final, color = fuchsia, text = "sSc", style=shape.arrowup)
// Alerts
// fast L
alertcondition(enterL1_final, "Enter fast L", "Enter fast L")
alertcondition(exitL1_final, "Exit fast L", "Exit fast L")
// fast S
alertcondition(enterS1_final, "Enter fast S", "Enter fast S")
alertcondition(exitS1_final, "Exit fast S", "Exit fast S")
// slow L
alertcondition(enterL2_final, "Enter slow L", "Enter slow L")
alertcondition(exitL2_final, "Exit slow L", "Exit slow L")
// slow S
alertcondition(enterS2_final, "Enter slow S", "Enter slow S")
alertcondition(exitS2_final, "Exit slow S", "Exit slow S")
// Original code from strategy
//strategy.entry("fast L", strategy.long, when = enterL1 and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.entry("fast S", strategy.short, when = enterS1 and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.close("fast L", when = exitL1 and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.close("fast S", when = exitS1 and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.entry("slow L", strategy.long, when = enterL2 and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.entry("slow S", strategy.short, when = enterS2 and (time > timestamp(FromYear, FromMonth, FromDay, 00, 00)) and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.close("slow L", when = exitL2 and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))
//strategy.close("slow S", when = exitS2 and (time < timestamp(ToYear, ToMonth, ToDay, 23, 59)))