Jasper Pivot Reversal 1.0

jdockery511 · strategy · 66 行 · 点赞 45 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
strategy("Pivot reversal strategy", overlay=true)
 
leftBars = input(4, "Pivot Lookback Left")
rightBars = input(2, "Pivot Lookback Right")
 
tradeWindow = not na(time(timeframe.period, "0915-1100:1234567", "America/New_York"))
 
slPoints = 50.0
 
swh = ta.pivothigh(leftBars, rightBars)
swl = ta.pivotlow(leftBars, rightBars)
 
swh_cond = not na(swh)
hprice = 0.0
hprice := swh_cond ? swh : hprice[1]
le = swh_cond
 
if le and tradeWindow
    strategy.entry("Buy", strategy.long, comment="Buy", stop=hprice + syminfo.mintick)
 
swl_cond = not na(swl)
lprice = 0.0
lprice := swl_cond ? swl : lprice[1]
se = swl_cond
 
if se and tradeWindow
    strategy.entry("Sell", strategy.short, comment="Sell", stop=lprice - syminfo.mintick)
 
if not tradeWindow
    strategy.cancel("Buy")
    strategy.cancel("Sell")
 
// 50-point stop losses
longSL = strategy.position_avg_price - slPoints
shortSL = strategy.position_avg_price + slPoints
 
if strategy.position_size > 0
    strategy.exit("Buy SL", from_entry="Buy", stop=longSL)
 
if strategy.position_size < 0
    strategy.exit("Sell SL", from_entry="Sell", stop=shortSL)
 
if strategy.position_size > 0 and se
    strategy.close("Buy", comment="Pivot Reversal Exit", immediately=true)
 
if strategy.position_size < 0 and le
    strategy.close("Sell", comment="Pivot Reversal Exit", immediately=true)
 
// Stop loss plot
plot(
     strategy.position_size > 0 ? longSL : strategy.position_size < 0 ? shortSL : na,
     title="STOP LOSS - 50 POINTS",
     color=color.red,
     linewidth=3,
     style=plot.style_stepline
)
 
// Entry price plot
plot(
     strategy.position_size != 0 ? strategy.position_avg_price : na,
     title="ENTRY PRICE",
     color=color.yellow,
     linewidth=2,
     style=plot.style_stepline
)

← 返回列表