Gap Filling Strategy

alexgrover · strategy · 33 行 · 点赞 1,416 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alexgrover
 
//@version=4
strategy("Gap Filling Strategy",overlay=true)
invert = input(false),clw = input("New Session","Close When:",
  options=["New Session","New Gap","Reverse Position"])
//----
ses = change(time("D")) 
o = open,c = close
//----
upgap = o > high[1] and min(c,o) > max(c[1],o[1])
dngap = o < low[1] and min(c[1],o[1]) > max(c,o)
//----
val = upgap ? max(c[1],o[1]) : min(c[1],o[1])
lim = valuewhen(ses and (upgap or dngap),val,0)
//----
strategy.close_all(clw == "New Session" ? ses :
  clw == "New Gap" ? ses and (upgap or dngap) : false)
if invert
    strategy.entry("Buy", strategy.long, when=ses and upgap)
    strategy.entry("Sell", strategy.short, when=ses and dngap)
else
    strategy.entry("Buy", strategy.long, when=ses and dngap)
    strategy.entry("Sell", strategy.short, when=ses and upgap)
if invert
    strategy.exit("ExitBuy","Buy",stop=lim)
    strategy.exit("ExitSell","Sell",stop=lim)
else
    strategy.exit("ExitBuy","Buy",limit=lim)
    strategy.exit("ExitSell","Sell",limit=lim)
//----
plot(lim,"Limit/Stop",#ff1100,2)

← 返回列表