2020-07-26 16:43:19 +08:00
|
|
|
//@version=3
|
|
|
|
strategy("Hammer-L RSI-S Strategy", overlay=true, initial_capital = 12000, default_qty_type = strategy.cash, default_qty_value = 4000)
|
2020-07-26 15:32:54 +08:00
|
|
|
|
|
|
|
// Buy when hammer is observed in a downtrend
|
2020-07-26 16:43:19 +08:00
|
|
|
// Detect downtrend
|
|
|
|
is_DownTrend = false
|
|
|
|
// sma100 = sma(close, 100)
|
|
|
|
sma50 = sma(close, 50)
|
|
|
|
// is_DownTrend := close < sma50 and sma50 < sma100
|
|
|
|
is_DownTrend := close < sma50
|
2020-07-26 15:32:54 +08:00
|
|
|
|
2020-07-26 16:43:19 +08:00
|
|
|
// Detect hammer
|
|
|
|
len_upShadow = high - max(open,close)
|
|
|
|
len_downShadow = min(open,close) - low
|
|
|
|
len_body = abs(open - close)
|
|
|
|
if is_DownTrend and len_downShadow > 0
|
|
|
|
if len_upShadow < len_downShadow / 5 and len_body < len_downShadow / 3
|
|
|
|
strategy.entry("HammerL", strategy.long, comment="HammerL")
|
|
|
|
|
2020-07-26 15:32:54 +08:00
|
|
|
// Sell when RSI exceeds 75
|
2020-07-26 16:43:19 +08:00
|
|
|
length = input( 14 )
|
|
|
|
overSold = input( 30 )
|
|
|
|
overBought = input( 75 )
|
2020-07-26 15:32:54 +08:00
|
|
|
price = close
|
2020-07-26 16:43:19 +08:00
|
|
|
|
2020-07-26 15:32:54 +08:00
|
|
|
vrsi = rsi(price, length)
|
|
|
|
co = crossover(vrsi, overSold)
|
|
|
|
cu = crossunder(vrsi, overBought)
|
|
|
|
|
2020-07-26 16:43:19 +08:00
|
|
|
if (not na(vrsi))
|
|
|
|
if (cu)
|
|
|
|
strategy.close_all(when = open < close)
|
2020-07-26 15:32:54 +08:00
|
|
|
// strategy.exit(id = "MacdCU", qty_percent = 80, comment = "RsiC80")
|
|
|
|
// strategy.entry("Rsi75", strategy.short, comment="Rsi75")
|
2020-07-26 16:43:19 +08:00
|
|
|
|
2020-07-26 15:32:54 +08:00
|
|
|
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)
|
|
|
|
|