如果有室外酒吧,该脚本将(开放交易)购买。目前,takeProfit为2%,stopLoss在外侧栏的低点。 (我只是在学习编码,不是有效的策略)
问题1:需要考虑何时入场价低于外部柱线的低点(这将进入并立即退出该仓位)。如果入口低于外部柱线低点,我试图使其止损为1%。
问题2:如果我处于未退出的多头头寸中,并且找到了新的外线,则我不希望它更新止损或当前头寸。
//@version=3
// Created by Leon Ross
//study(title="OutsideBar", shorttitle="ODOL", overlay=true)
strategy(title = "Outside", shorttitle = "OB", overlay = true,
pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
calc_on_every_tick=false, initial_capital=100000)
//Conditions
outsideBar = low < low[1] and high > high[1] and close < open
allConditions = outsideBar
//Stop as last bars low and profit as percentage
entry = strategy.position_avg_price
inpTakeProfit = input(2.0, title='Take Profit %', type=float)/100
takeProfitValue = strategy.position_avg_price * (1 + inpTakeProfit)
useTakeProfit = inpTakeProfit > 0 ? takeProfitValue : na
inpStopLoss = valuewhen(allConditions, low, 0)
stopLossValue = inpStopLoss
useStopLoss = inpStopLoss > 0 ? stopLossValue : na
//Plots
bgcolor(allConditions ==1 ? aqua : na, transp=70)
plot(entry, color=blue, style=linebr, linewidth=2)
plot(useStopLoss, color=red, style=linebr, linewidth=2)
plot(useTakeProfit, color=green, style=linebr, linewidth=2)
//Entires
strategy.entry(id = "Long", long = true, when = allConditions) // use function or simple condition to decide when to get in
//Exits
//if (barssince(allConditions) == 2)
//strategy.close("Long")
//else
strategy.exit("Exit Long", from_entry = "Long", stop = useStopLoss)