了解如何对此进行编码。 一直在尝试从书本中获取策略,并尝试对其进行编码和重新测试。
一种策略是:如果一天的收盘价低于前几天的低点(绿色柱),那么如果未来价格超过高点(蓝色线),则打开多头头寸。
我似乎不知道该怎么做。一旦价格超过高点(可能是几天),就进入。
//@version=3
// Created by Leon Ross
strategy(title = "SmashDay", shorttitle = "SD", overlay = true,
pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
calc_on_every_tick=false, initial_capital=100000)
//Window of time
start = timestamp(2018, 08, 01, 00, 00) // backtest start window
finish = timestamp(2018, 12, 31, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
//Conditions
closeBelowLow = close < low[1]
highOnNextDay = valuewhen(closeBelowLow, high, 0)
allConditions = closeBelowLow
//Plots
bgcolor(closeBelowLow ==1 ? lime : na, transp=70)
plot(entry, color=blue, style=linebr, linewidth=2)
//Entires/Exits
if(window())
if(close>highOnNextDay)
//strategy.entry(id = "Long", long = true, when = entry) // use function or simple condition to decide when to get in
//strategy.exit("Exit Long", from_entry = "Long", limit = useTakeProfit, stop = useStopLoss)