Я новичок в Pinescript и не могу обернуть голову вокруг этого. Я просто пытаюсь создать простую стратегию открытого ценового разрыва, которая гласит: Логика c, лежащая в основе этой стратегии, говорит о том, что, когда существует большой разрыв в ценах между закрытием рынка и открытием рынка, разрыв имеет тенденцию заполняться. Другим фактором является объем, когда для этой свечи большое количество, стратегия менее успешна.
Логика c выглядит так (я не хочу коротких позиций):
Когда% разрыва находится между -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)