Stoch RSI : How to send buy signal when my k crossover d but only when k goes to 10 before going up

Viewed 23

For now I'm just buying when my k crossover d and they are both in the [20-25] zone. I would like to add one other condition for the buy signal which is when the k goes under 10 for example before crossing the [20-25] zone. Thx for your help !

Here's my Stoch RSI strategy script :

// Input data to configure on chart
smoothK = input.int (defval=3, title = "Stochastic %K", minval=1, step=1)
smoothD = input.int (defval=3, title = "Stochastic %D", minval=1, step=1)
lengthRSI = input.int (defval=14, title = "RSI Length", minval=1, step=1)
lengthStoch = input.int (defval=8, title = "Stochastic Length", minval=1, step=1)
src4 = input(close, title="RSI Source")

// Calculate indicator
rsi1 = ta.rsi(src4, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// Drawing - plot on chart
plot(k, color=color.blue)
plot(d, color=color.red)
h0 = hline(80, linestyle=hline.style_dotted)
h1 = hline(20, linestyle=hline.style_dotted)
band1 = hline(20)
band0 = hline(80)
fill(band1, band0, color.new(color.purple, 90))
mink = input.float(20, title = 'mink')
mink2 = input.float(30, title = 'mink2')
maxk = input.float(80, title = 'maxk')
//BUY SELL
longCondition=ta.crossover(k, d) and k > mink and k > mink2
closeCondition=ta.crossunder(k, d) and k > maxk
longLossPerc = input.float(10, title = 'Stop Loss', group = 'Take Profit and Stop Loss')/100
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
if (longCondition)
    strategy.entry("long", strategy.long)

if (closeCondition)
    strategy.close("long")
if (strategy.position_size > 0)
    strategy.exit(id="XL STP", stop=longStopPrice)
0 Answers
Related