OPEN-SOURCE SCRIPT

daniel

//version=5
strategy("Estrategia ADX con Stop Loss y Objetivo", overlay=true)

// Configuración de parámetros
adxLength = input.int(14, title="Periodo ADX")
adxThreshold = input.int(25, title="Umbral ADX")
stopLossPerc = input.float(1, title="Stop Loss (%)", step=0.1) / 100
takeProfitPerc = input.float(3, title="Take Profit (%)", step=0.1) / 100 // Cambiado a 3%

// Cálculo de TR (True Range) manualmente
highLow = high - low
highClosePrev = math.abs(high - close[1])
lowClosePrev = math.abs(low - close[1])
tr = math.max(highLow, math.max(highClosePrev, lowClosePrev))
atr = ta.sma(tr, adxLength)

// Cálculo de +DM y -DM
plusDM = (high - high[1] > low[1] - low) ? math.max(high - high[1], 0) : 0
minusDM = (low[1] - low > high - high[1]) ? math.max(low[1] - low, 0) : 0

// Suavizado de +DM y -DM
smoothedPlusDM = ta.sma(plusDM, adxLength)
smoothedMinusDM = ta.sma(minusDM, adxLength)

// Cálculo de +DI y -DI
plusDI = (smoothedPlusDM / atr) * 100
minusDI = (smoothedMinusDM / atr) * 100

// Cálculo del DX y ADX
dx = math.abs(plusDI - minusDI) / (plusDI + minusDI) * 100
adx = ta.sma(dx, adxLength)

// Condiciones de entrada
longCondition = ta.crossover(plusDI, minusDI) and adx > adxThreshold
shortCondition = ta.crossover(minusDI, plusDI) and adx > adxThreshold

// Ejecución de operaciones
if (longCondition)
strategy.entry("Compra", strategy.long)

if (shortCondition)
strategy.entry("Venta", strategy.short)

// Stop Loss y Take Profit
strategy.exit("Cerrar Compra", from_entry="Compra", loss=stopLossPerc, profit=takeProfitPerc)
strategy.exit("Cerrar Venta", from_entry="Venta", loss=stopLossPerc, profit=takeProfitPerc)
Bands and ChannelsCandlestick analysisChart patterns

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明