NicoloMastronardi

MomentumBreak#1

13
//condicion de compra: k>80
buycondition=crossover(k,oversold)


calculo de tamaño de la posicion segun el ultimo low dentro de lo n periodos anteriores, tambien usado como stop

salida por trailing stop

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
//descripcion: 
//entrada en saturacion oscilador estocastico
//salida por trailing
strategy("MomentumBreak#1", overlay=true,calc_on_every_tick=true,
     default_qty_type=strategy.fixed,currency="USD")
//entradas y variables de indicadores
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
lengthRSI = input(14, minval=1)
lengthStoch = input(14, minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
overbought=input(80)
oversold=input(20)
//entradas de stop , trail, profit
stop=input(1500)
stop_dentro_de_los_ultimos_lows=input(20)
trail_points=input(500)
trail_offset=input(100)
profit=input(1000)
riesgo_en_dolares=input(15)

//condicion de compra: k>80
buycondition=crossover(k,oversold)
//entrada a la posicion
posicionabierta=0
if year>2015
    if buycondition 
        stoplow=lowest(stop_dentro_de_los_ultimos_lows)   
        riesgo_en_pips = (close - stoplow)   
        valor_del_pip = (riesgo_en_dolares / riesgo_en_pips)
        tamanio_de_la_posicion= ( valor_del_pip)              //la posicion la esta calculando bien
        strategy.entry("buy",strategy.long,qty=tamanio_de_la_posicion)
        strategy.exit("salida","buy",trail_points=trail_points,trail_offset=trail_offset,stop=stoplow,comment=tostring(stoplow))

//////////////////////////////////condicion de stop por drodown 10% equity
//strategy.risk.max_drawdown(15,strategy.cash)
// condicion de stop por perdida mayor a $15 en op abierta
//strategy.risk.max_intraday_loss(15,strategy.cash)
//formas de tomar stop:
// cuando llega a una media movil: strategy.close o strategyentry o strategy.exit o strategy.order
// determinado por un numero de pips strategy.exit
// determinado por el calculo de la posicion:
//tomar el minimo minimo de los ultimos 20 periodos, guardarlo como nivel de stop
//calcular la posicion en base a ese stop:
//prcio de entrada - precio de stop = pips_en-reisgo
//riesgo_e_dolares / pips_en_riesgo = pip_value
//position_size=10000 * pip_value