This strategy trades based on the crossover relationship between the VWAP (Volume Weighted Average Price) indicator and price. It opens a long position when the price crosses above the VWAP and a short position when the price crosses below the VWAP. Meanwhile, it utilizes the ATR (Average True Range) indicator to calculate dynamic stop loss and take profit levels to control risk and lock in profits.
This strategy focuses on VWAP, generating trading signals through crossovers with price while combining ATR for dynamic stop loss and take profit to control drawdown risk while capturing trends. The overall idea is simple and easy to understand. However, there is further room for optimization. By introducing auxiliary indicators, optimizing stop loss and take profit logic, adding money management, etc., the strategy can better adapt to changing market environments and improve its robustness and profitability.
/*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)template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6