This is a systematic approach designed to capitalize on the volatility of crude oil futures markets. It measures the average range of candlesticks. If the fast moving average is above the slow one, it means the candles are bigger. If the slow moving average is above the fast one, it means the candles are smaller.
According to this principle, it identifies potential long and short entry points. The position is only held for a fixed number of candles, controlled by the “Exit after bars” input.
This strategy utilizes breakout and regression to determine short-term trends, belonging to volatility strategies. By optimizing parameters and adding volatility metrics to determine false breakout probability, it can increase profitability. Also the fast exit mechanism locks in some profit and controls risk effectively. It can serve as an auxiliary tool for short-term trading, and can also generate longer-term trading signals through parameter tuning.
/*backtest start: 2024-02-01 00:00:00 end: 2024-02-29 23:59:59 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Celestial_Logic //@version=5 strategy("Crudeoil Breakout strategy", overlay = true, initial_capital = 20000, default_qty_type = strategy.fixed, default_qty_value = 1) highestCloseLookback = input(9 , title = 'Highest Close lookback') lowestCloseLookback = input(50, title = 'Lowest Close lookback' ) exitAfter = input(10, title = 'Exit after bars') hc = ta.highest(close,highestCloseLookback) lc = ta.lowest(close,lowestCloseLookback) rangeFilter = (ta.sma( (high - low), 5 ) > ta.sma((high-low), 20) ) // Candles getting bigger. longCondition = (close == hc ) and not rangeFilter shortCondition = (close == lc ) and not rangeFilter if longCondition strategy.entry(id = 'long', direction = strategy.long) if shortCondition strategy.entry(id = 'short', direction = strategy.short) var int longsince = 0 var int shortsince = 0 if strategy.position_size > 0 longsince += 1 else longsince := 0 if strategy.position_size < 0 shortsince += 1 else shortsince := 0 if longsince >= exitAfter strategy.close(id = 'long', comment = 'long close') if shortsince >= exitAfter strategy.close(id = 'short', comment = 'short close')