为什么我的pinescript策略在一天后执行?

问题描述 投票:0回答:1

我是pinescript的新手,无法绕过这个主题。我只是试图创建一个简单的公开价格缺口战略,即说。该策略背后的逻辑是,当市场收盘价与市场开盘价之间存在较大的价格差距时,这种差距就会趋于填补。另一个因素是数量,当该蜡烛的数量很多时,该策略将不太成功。

逻辑如此(我不希望空缺):

当间隙%在-2到-8之间并且没有不规则的体积时,输入位置。当预期缺口大于80%时,则卖出或止损卖出。

我不明白为什么我的订单在满足差价条件标准后为什么要在下一个蜡烛(天)填充。我的代码如下:非常感谢任何帮助。

//@version=4
strategy(title = "Open Price Gap - Long", shorttitle = "OPG - Long", overlay = true, pyramiding = 0, calc_on_order_fills = false, calc_on_every_tick = true, max_bars_back = 14, default_qty_type = strategy.percent_of_equity, default_qty_value = 2, currency = "CAD", commission_type = strategy.commission.cash_per_order, commission_value = 4.95)

//Inputs
startYear = input(2019, "Start Year")
startMonth = input(01, "Start Month")
startDay = input (01, "Start Day")
endYear = input (2021, "End Year")
endMonth = input (01, "End Month")
endDay = input (01, "End Day")
backTestStart = timestamp(startYear, startMonth, startDay, 00, 00)
backTestEnd = timestamp(endYear, endMonth, endDay, 00, 00)
volSMADays = input (14, "Volume SMA Length")
minGapPercent = input (-8.0, "Min Gap (%)")
maxGapPercent = input (-2.0, "Max Gap (%)")
irrVolThresh = input (3.0, "Irregular Volume Threshold")
takeProfitLimit = input(80.0, "Profit Limit (% of Gap)")/100
stopLossLimit = input(20.0, "Loss Limit (% of Gap)")/100

//Gap % = (Open-Close/Close)
gapDollar = open[0] - close[1]
gapPercent = (gapDollar/close[2])*100
gapPalette = gapDollar > 0? color.yellow : gapDollar < 0? color.blue : na
offsetGapPercent = offset(gapPercent, 1)
plot(gapDollar, "Gap Dollar ($)", color = gapPalette)
plot(gapPercent, "Gap Percent (%)", color = gapPalette)


//Volume
dyn_avg(price, length) =>
    sum = price
    for i = 1 to length-1
        sum := sum + price[i]
    sum / length
volSMA = dyn_avg(volume, volSMADays)
volDiff = abs(volSMA-volume)
irrVol = volDiff/volSMA

//can_trade = (time >= backTestStart) and (time <= backTestEnd)
//if (can_trade)
//Entry
stopLossPrice = open - (abs(gapDollar) * stopLossLimit)
plot(stopLossPrice, "Stop Loss Price ($)")
entrySignal = gapPercent >= minGapPercent and gapPercent < maxGapPercent and irrVol < irrVolThresh
strategy.entry("Long Entry", strategy.long, stop = stopLossPrice, when = entrySignal)

//Exit
takeProfitPrice = (abs(gapDollar) * takeProfitLimit) + open
plot(takeProfitPrice, "Take Profit Price ($)")
strategy.exit("Long Exit", "Long Entry", qty_percent = 100, limit = takeProfitPrice, stop = stopLossPrice)

pine-script algorithmic-trading trading
1个回答
0
投票

欢迎来到松树!这是开始您的旅程的最佳地点:https://www.pinecoders.com/

下一个栏上的执行是默认设置,但可以更改。参见:Why are my orders executed on the bar following my triggers?

© www.soinside.com 2019 - 2024. All rights reserved.