passaro.mail

ReversalBreakout Strategy

BITFINEX:BTCUSD   Bitcoin
//@version=2
strategy("ReversalBreakout Strategy", overlay=true)


testStartYear = input(2018, "Backtest Start Year")
testStartMonth = input(03, "Backtest Start Month")
testStartDay = input(01, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)


len = input(24,minval=1, title = "Periodo")
ShFL = input(true, type=bool, title = "Show Fractal lines?")

lowline = lowest(close, len)
plot(ShFL ? lowline : na, style=line, linewidth=1, color=green)

highline=highest(close, len)
plot(ShFL ? highline : na, style=line, linewidth=1, color=red)

MidLine = (highline+lowline)/2
plot(ShFL ? MidLine : na, style=line, linewidth=1)

//----------------------------------------------------------------------------------

// === INPUTS RISK MANAGEMENT===
inpTakeProfit = input(defval = 1000, title = "Take Profit", minval = 0)
inpStopLoss = input(defval = 200, title = "Stop Loss", minval = 0)
inpTrailStop = input(defval = 200, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)

// === RISK MANAGEMENT VALUE PREP ===
//Se l'input è <1 viene disabilitato
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na

// === CONDIZIONI LOGICHE ===
aboveHLine = (close>highline and time >= testPeriodStart) ? true : false
belowLLine = (close<lowline and time >= testPeriodStart) ? true : false


// === STRATEGY - LONG POSITION===
strategy.entry(id = "Long", long = true, when = aboveHLine)

// === STRATEGY - SHORT POSITION===
strategy.entry(id = "Short", long = false, when = belowLLine)


// === STRATEGY RISK MANAGEMENT EXECUTION ===
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.