Pine Script (TradingView)
Este es un ejemplo de estrategia Pine Script de TradingView para el concepto de esta pagina. Pegalo en el Editor Pine de TradingView, agregalo al grafico y ejecutalo en Strategy Tester.
//@version=6
// Note: Full grid trading requires broker-integration; this script demonstrates
// grid level detection and signals for manual or semi-automated grid execution.
strategy("Grid Trading Strategy", overlay=true)
gridCount = input.int(5, "Grid Levels", minval=2, maxval=20)
rangeLow = input.float(0.0, "Range Low (0=auto)")
rangeHigh = input.float(0.0, "Range High (0=auto)")
lookback = input.int(50, "Auto-Range Lookback")
lo = rangeLow > 0 ? rangeLow : ta.lowest(low, lookback)
hi = rangeHigh > 0 ? rangeHigh : ta.highest(high, lookback)
step = (hi - lo) / gridCount
level = math.round((close - lo) / step) * step + lo
buySignal = ta.crossover(close, level - step * 0.1)
sellSignal = ta.crossunder(close, level + step * 0.1)
if buySignal
strategy.entry("GridBuy", strategy.long)
if sellSignal
strategy.close("GridBuy")
for i = 0 to gridCount
line.new(bar_index - 1, lo + i * step, bar_index, lo + i * step, extend=extend.right, color=color.new(color.teal, 50))