
Эта стратегия основана на перекрестной связи показателя VWAP с ценой. Открытие позиции, когда цена пересекает VWAP вверх, и открытие позиции, когда она пересекает VWAP вниз. В то же время, использование ATR (средняя реальная величина колебаний) показатель рассчитывает динамические уровни остановки и остановки, чтобы контролировать риск и блокировать прибыль.
В основе стратегии лежит VWAP, которая генерирует торговые сигналы путем перекрестного взаимодействия с ценами, одновременно в сочетании с ATR реализует динамический стоп-лосс, контролирует риск отмены, одновременно удерживая тенденцию, и в целом концепция проста и понятна. Однако в стратегии есть еще больше возможностей для оптимизации, чтобы лучше адаптироваться к изменяющейся рыночной среде, повысить устойчивость стратегии и ее прибыльность, путем введения вспомогательных показателей, оптимизации логики стоп-лосс и управления капиталом.
/*backtest
start: 2023-03-26 00:00:00
end: 2024-03-31 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("Hannah Strategy Stop Loss and Take Profit", overlay=true)
// Inputs
cumulativePeriod = input(40, "VWAP Period")
atrPeriod = input(14, "ATR Period")
multiplier = input(1.5, "ATR Multiplier for Stop Loss")
targetMultiplier = input(3, "ATR Multiplier for Take Profit")
// Calculations for VWAP
typicalPrice = (high + low + close) / 3
typicalPriceVolume = typicalPrice * volume
cumulativeTypicalPriceVolume = sum(typicalPriceVolume, cumulativePeriod)
cumulativeVolume = sum(volume, cumulativePeriod)
vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume
// Plot VWAP on the chart
plot(vwapValue, color=color.blue, title="VWAP")
// Entry Conditions based on price crossing over/under VWAP
longCondition = crossover(close, vwapValue)
shortCondition = crossunder(close, vwapValue)
// ATR Calculation for setting dynamic stop loss and take profit
atr = atr(atrPeriod)
// Execute Trades with Dynamic Stop Loss and Take Profit based on ATR
if (longCondition)
strategy.entry("Long", strategy.long)
// Setting stop loss and take profit for long positions
strategy.exit("Long Exit", "Long", stop=close - atr * multiplier, limit=close + atr * targetMultiplier)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Setting stop loss and take profit for short positions
strategy.exit("Short Exit", "Short", stop=close + atr * multiplier, limit=close - atr * targetMultiplier)