1

It just seems that I can't figure out the correct script for my strategy, which is the following:

  • Buy signal when the ADX is above 46 and at the same time the RSI is oversold at or below 20

Works way better in Daily timeframe, get less signals but way more effective, the script is this:

//@version=5
strategy("Estrategia Long Only")
// Definir el indicador ADX
len = input(14, title="ADX Length")
th = input(44, title="ADX Threshold")
adx_val = ta.adx(high, low, close, len)
// Definir el indicador RSI
rsi_len = input(14, title="RSI Length")
rsi_buy = input(20, title="RSI Buy Threshold")
rsi_sell = input(35, title="RSI Sell Threshold")
rsi_val = ta.rsi(close, rsi_len)
// Generar seƱales de compra
adx_above_th = adx_val > th
rsi_above_buy = rsi_val >= rsi_buy and rsi_val < rsi_sell
buy_signal = adx_above_th and rsi_above_buy
// Entradas largas
if buy_signal
   strategy.entry("Long", strategy.long)
// Plotting
 plotshape(buy_signal, "Buy", shape.triangleup, location.belowbar, color.green, size=size.small)

But I Keep receiving this error:

Error at 10:11 Could not find function or function reference 'ta.adx'

I try importing values from other indicators because seems like the problem is in the ADX indicator, but doesn't seem to work out.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

2

There is no ta.adx() function as the error message tells you.

You should use the ta.dmi() to get the adx value.

len = input.int(17, minval=1, title="DI Length")
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
[diplus, diminus, adx] = ta.dmi(len, lensig)
plot(adx, color=color.red, title="ADX")
plot(diplus, color=color.blue, title="+DI")
plot(diminus, color=color.orange, title="-DI")
vitruvius
  • 15,740
  • 3
  • 16
  • 26