Professional Documents
Culture Documents
RSI - VWAP - strategy 只做多 牛市最牛逼策略
RSI - VWAP - strategy 只做多 牛市最牛逼策略
//
===================================================================================
===================================================================================
==========
// VARIABLES
//
===================================================================================
===================================================================================
==========
//
===================================================================================
===================================================================================
==========
// RSI VWAP INDICATOR
//
===================================================================================
===================================================================================
==========
// Initial inputs
RSI_VWAP_length = input(17, "RSI-VWAP LENGTH", minval = 1, maxval = 99)
RSI_VWAP_overSold = input(19, "OVERSOLD (LONG)", type=input.float, minval = 1,
maxval = 99)
RSI_VWAP_overBought = input(70, "OVERBOUGHT (XLONG)", type=input.float, minval = 1,
maxval = 99)
RSI_VWAP_overSold2 = input(33, "OVERSOLD 2 (LONG)", type=input.float, minval = 1,
maxval = 99)
Short_only = false
RSI_VWAP_length_short = 17
RSI_VWAP_overSold_short = 19
RSI_VWAP_overBought_short = 80
RSI_VWAP_overBought_short2 = 59
RSI_VWAP_short = rsi(vwap(close), RSI_VWAP_length_short)
//
===================================================================================
===================================================================================
==========
// STRATEGY
//
===================================================================================
===================================================================================
==========
// In long/short conditions
in_longCondition := last_longCondition > last_shortCondition
in_shortCondition := last_shortCondition > last_longCondition
//
===================================================================================
===================================================================================
==========
// PRICE AVERAGE / PYRAMIDING
//
===================================================================================
===================================================================================
==========
// Pyramiding
pyr := input(10, "MAX. PYRAMIDING 🎢" , minval = 1, maxval = 10)
// Longs Counter
if longCondition or (Final_Long_sl and not Act_sl)
nLongs := nLongs + 1
nShorts := 0
// Shorts Counter
if shortCondition or (Final_Short_sl and not Act_sl)
nLongs := 0
nShorts := nShorts + 1
// Quantity Factor
QF_l = Quantity+(Increase*(nLongs-1))
QF_s = Quantity+(Increase*(nShorts-1))
if shortCondition
sum_short := nz(last_open_shortCondition)*QF_s + nz(sum_short[1])
sum_long := 0.0
sum_qty_s := QF_s + nz(sum_qty_s[1])
sum_qty_l := na
//
===================================================================================
===================================================================================
==========
// STOP LOSS / RE-ENTRY
//
===================================================================================
===================================================================================
==========
// SL initial inputs
Act_sl := input(false, "ACTIVATE SL / DEACTIVATE RE-ENTRY")
sl := input(10, "STOP LOSS / RE-ENTRY %", type = input.float, minval = 0, step =
0.5)
// Initial SL conditions
long_sl = crossunder(low, (1-(sl/100))*last_open_longCondition) and
in_longCondition and not longCondition
short_sl = crossover(high, (1+(sl/100))*last_open_shortCondition) and
in_shortCondition and not shortCondition
// Sl counter
CondIni_long_sl := long_sl or XlongCondition ? 1 : longCondition ? -1 :
nz(CondIni_long_sl[1])
CondIni_short_sl := short_sl or XshortCondition ? 1 : shortCondition ? -1 :
nz(CondIni_short_sl[1])
// Final SL conditions
Final_Long_sl := long_sl and nz(CondIni_long_sl[1]) == -1 and in_longCondition and
not longCondition
Final_Short_sl := short_sl and nz(CondIni_short_sl[1]) == -1 and in_shortCondition
and not shortCondition
//
===================================================================================
===================================================================================
==========
// TAKE PROFIT
//
===================================================================================
===================================================================================
==========
// Initial TP conditions
long_tp = crossover(high, (1+(tp/100))*fixnan(Position_Price)) and in_longCondition
and not longCondition and not Final_Long_sl and Act_tp
short_tp = crossunder(low, (1-(tp/100))*fixnan(Position_Price)) and
in_shortCondition and not shortCondition and not Final_Short_sl and Act_tp
// Tp signal ordering
CondIni_long_tp := (Final_Long_sl and Act_sl) or XlongCondition ? 1 : longCondition
? -1 : nz(CondIni_long_tp[1])
CondIni_short_tp := Final_Short_sl and Act_sl ? 1 : shortCondition ? -1 :
nz(CondIni_short_tp[1])
// Final tp condition
Final_Long_tp = long_tp and last_longCondition > nz(last_long_tp[1]) and
nz(CondIni_long_tp[1]) == -1
Final_Short_tp = short_tp and last_shortCondition > nz(last_short_tp[1]) and
nz(CondIni_short_tp[1]) == -1
//
===================================================================================
===================================================================================
==========
// BACKTEST
//
===================================================================================
===================================================================================
==========
// Backtest inputs
Act_BT = input(true, "BACKTEST 💹")
contracts_or_cash = input("CASH", "CONTRACTS ₿ / CASH $", options =
["CONTRACTS","CASH"])
cc_factor = (contracts_or_cash == "CASH") ? close : 1
Quantity := input(1000, "$ QUANTITY 1ST ENTRY", minval = 0)/cc_factor
Increase := input(500, "$ INCREASE NEXT ENTRY", minval = 0)/cc_factor
// Backtest Condition
testPeriod = time >= testPeriodStart and time <= testPeriodStop ? true : false
// Backtest entries
if (Act_BT and testPeriod)
strategy.entry("Long", strategy.long, qty = QF_l, when = longCondition or
(Final_Long_sl and not Act_sl))
strategy.close("Long", when = XlongCondition)
strategy.exit("TPl", "Long", qty_percent = qty_TP, limit = Act_tp ?
(fixnan(Position_Price)*(1+(tp/100))) : na)
strategy.close("Long", when = Act_sl and Final_Long_sl)
//
===================================================================================
===================================================================================
==========
// ALERTS
//
===================================================================================
===================================================================================
==========
// LONGS
// SHORTS