White Night
Senior Member
- Nov 29, 2013
- 827
- 293
Lately, I’ve developed a keen interest in crypto futures trading — not just manually, but using automated bots. What makes it more exciting is that I’m building these strategies from scratch using ChatGPT as my coding assistant.
I’ve decided to document this journey here, partly to track my own progress, but also to see what ideas might emerge along the way. Who knows? Maybe we’ll crack something that actually works.
Here’s how things are currently set up:
It’s a pretty straightforward loop — but of course, nothing is ever perfect in trading.
Here is the code:
//@version=6
strategy("Range Expansion Strategy - 5min Enhanced", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
//-------------------------------------------------------
// 1. Higher Timeframe Directional Bias (15min)
htfRes = input.timeframe("15", "Higher Timeframe")
[HTF_high, HTF_low, HTF_close, HTF_open] = request.security(syminfo.tickerid, htfRes, [high, low, close, open], lookahead=barmerge.lookahead_on)
bullishBias = HTF_close > HTF_open
bearishBias = HTF_close < HTF_open
//-------------------------------------------------------
// 2. Lower Timeframe Swing Calculations (for 5min)
// Use a short lookback so that swing highs/lows appear more frequently.
lookback = input.int(5, "Swing Lookback", minval=3, maxval=20)
swingHigh = ta.highest(high, lookback)
swingLow = ta.lowest(low, lookback)
//-------------------------------------------------------
// 3. Liquidity Sweep & Rejection Conditions
// We define a "rejection" fraction indicating that the bar recovers
// a certain portion above its swing extreme.
// For a long, if the bar’s low is at or near the swing low and then closes sufficiently higher,
// that signals a bullish liquidity sweep and rejection.
// For a short, the reverse applies.
rejectionFrac = input.float(0.2, "Rejection Fraction", minval=0.1, maxval=0.5, step=0.05)
longCondition = bullishBias and (low <= swingLow) and (close > swingLow + ((high - low) * rejectionFrac))
shortCondition = bearishBias and (high >= swingHigh) and (close < swingHigh - ((high - low) * rejectionFrac))
//-------------------------------------------------------
// 4. Risk–Reward Exit Calculations
// The stop for longs is the swing low and for shorts is the swing high,
// with target computed using a risk–reward multiplier.
rr = input.float(3.0, "Risk Reward Ratio", minval=1.0, step=0.1)
longStop = swingLow
shortStop = swingHigh
longRisk = close - longStop
shortRisk = shortStop - close
longTarget = close + longRisk * rr
shortTarget = close - shortRisk * rr
//-------------------------------------------------------
// 5. Strategy Execution: Enter and exit trades when conditions trigger.
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=longStop, limit=longTarget)
if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=shortStop, limit=shortTarget)
//-------------------------------------------------------
// 6. Visual Components for clarity:
plot(HTF_high, title="HTF High", color=color.blue)
plot(HTF_low, title="HTF Low", color=color.orange)
plot(swingHigh, title="Swing High", color=color.red)
plot(swingLow, title="Swing Low", color=color.green)
plotshape(longCondition, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.normal)
plotshape(shortCondition, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)
Identify and trade reversal points caused by liquidity sweeps near recent swing highs/lows, aligned with higher timeframe bias, on the 5-minute chart.
Long Entry:
Long Exit:
Currently Earning: $0
I will load it with a small budget like $50 to test the flow after fixing some issue. I still don't know why but the signal is quite messy
I’ve decided to document this journey here, partly to track my own progress, but also to see what ideas might emerge along the way. Who knows? Maybe we’ll crack something that actually works.
Tools I’m Using
- TradingView – to design and test strategies via Pine Script v6
- 3Commas – to execute trades automatically via webhook-based signal bots
- ChatGPT – my go-to for coding support and brainstorming strategy logic
- Binance – the exchange where I trade crypto futures
The Flow (So Far)
Here’s how things are currently set up:
- I come up with a strategy idea.
- I work with ChatGPT to write the code in Pine Script v6.
- I test and fine-tune it inside TradingView.
- Once it’s ready, I use webhook alerts to trigger buy/sell signals via 3Commas, which then executes trades on Binance.
It’s a pretty straightforward loop — but of course, nothing is ever perfect in trading.
Where I’m At
Right now, I’m testing a new strategy. I’ve already written the code (with ChatGPT’s help), but something feels off. Still, instead of getting discouraged, I figured… why not log it here and iterate? Every mistake is a chance to learn — and maybe even uncover a better approach.Here is the code:
//@version=6
strategy("Range Expansion Strategy - 5min Enhanced", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
//-------------------------------------------------------
// 1. Higher Timeframe Directional Bias (15min)
htfRes = input.timeframe("15", "Higher Timeframe")
[HTF_high, HTF_low, HTF_close, HTF_open] = request.security(syminfo.tickerid, htfRes, [high, low, close, open], lookahead=barmerge.lookahead_on)
bullishBias = HTF_close > HTF_open
bearishBias = HTF_close < HTF_open
//-------------------------------------------------------
// 2. Lower Timeframe Swing Calculations (for 5min)
// Use a short lookback so that swing highs/lows appear more frequently.
lookback = input.int(5, "Swing Lookback", minval=3, maxval=20)
swingHigh = ta.highest(high, lookback)
swingLow = ta.lowest(low, lookback)
//-------------------------------------------------------
// 3. Liquidity Sweep & Rejection Conditions
// We define a "rejection" fraction indicating that the bar recovers
// a certain portion above its swing extreme.
// For a long, if the bar’s low is at or near the swing low and then closes sufficiently higher,
// that signals a bullish liquidity sweep and rejection.
// For a short, the reverse applies.
rejectionFrac = input.float(0.2, "Rejection Fraction", minval=0.1, maxval=0.5, step=0.05)
longCondition = bullishBias and (low <= swingLow) and (close > swingLow + ((high - low) * rejectionFrac))
shortCondition = bearishBias and (high >= swingHigh) and (close < swingHigh - ((high - low) * rejectionFrac))
//-------------------------------------------------------
// 4. Risk–Reward Exit Calculations
// The stop for longs is the swing low and for shorts is the swing high,
// with target computed using a risk–reward multiplier.
rr = input.float(3.0, "Risk Reward Ratio", minval=1.0, step=0.1)
longStop = swingLow
shortStop = swingHigh
longRisk = close - longStop
shortRisk = shortStop - close
longTarget = close + longRisk * rr
shortTarget = close - shortRisk * rr
//-------------------------------------------------------
// 5. Strategy Execution: Enter and exit trades when conditions trigger.
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=longStop, limit=longTarget)
if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=shortStop, limit=shortTarget)
//-------------------------------------------------------
// 6. Visual Components for clarity:
plot(HTF_high, title="HTF High", color=color.blue)
plot(HTF_low, title="HTF Low", color=color.orange)
plot(swingHigh, title="Swing High", color=color.red)
plot(swingLow, title="Swing Low", color=color.green)
plotshape(longCondition, title="Long Signal", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.normal)
plotshape(shortCondition, title="Short Signal", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.normal)
Summary Strategy:
Identify and trade reversal points caused by liquidity sweeps near recent swing highs/lows, aligned with higher timeframe bias, on the 5-minute chart.
ENTRY
Long Entry:- 15-minute candle is bullish (close > open)
- Current bar's low touches or breaks swing low
- Current bar closes above swingLow + (rejectionFrac × (high - low))
- 15-minute candle is bearish (close < open)
- Current bar's high touches or breaks swing high
- Current bar closes below swingHigh - (rejectionFrac × (high - low))
EXIT:
Long Exit:- Stop Loss: At swing low
- Take Profit: At entry price + (entry price - swingLow) × RR
- Stop Loss: At swing high
- Take Profit: At entry price - (swingHigh - entry price) × RR
Currently Earning: $0
I will load it with a small budget like $50 to test the flow after fixing some issue. I still don't know why but the signal is quite messy