
Es handelt sich um eine automatisierte Handelsstrategie, die eine Kombination aus Moving Averages, MACD-Indikatoren und Transaktionsvolumen-Filterung verwendet, um die Richtung von Trends zu bestimmen und das Handelsrisiko durch mehrere technische Indikatoren zu verwalten. Die Strategie beurteilt die Marktentwicklung anhand von kurz- und langfristigen Moving Averages, verwendet MACD-Bestätigungssignale für Trendsignale und kombiniert Transaktionsvolumen-Filterung und eine dynamische Risikomanagement-Mechanik, um die Genauigkeit und Stabilität des Handels zu verbessern.
Die Strategie umfasst vier Kerntechnologien:
Es handelt sich um eine automatisierte Handelsstrategie, bei der mehrere technische Analyse-Tools kombiniert werden, die durch strenge Risikomanagement und Multiple-Meter-Verifizierung eine relativ stabile und zuverlässige Handelsmethode bieten soll. Der Kern der Strategie liegt in der Balance von Trendfangfähigkeit und Risikokontrolle, die einen flexiblen und optimierbaren Rahmen für quantifizierte Geschäfte bietet.
/*backtest
start: 2024-04-02 00:00:00
end: 2025-04-02 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Strategia Semmoncino", shorttitle="semmoncino", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
// Inputs
useVolumeFilter = input.bool(true, title="Usa Filtro di Volume")
volumeThreshold = input.float(1.5, title="Soglia Volume (x Media)", minval=1)
atrPeriod = input.int(14, title="ATR Period", minval=1)
atrMultiplier = input.float(2.0, title="ATR Multiplier", minval=0.1)
takeProfitMultiplier = input.float(6.0, title="Take Profit Multiplier", minval=1.0) // Aumentato per ottimizzare
riskPerTrade = input.float(2.0, title="Rischio per Trade (%)", minval=0.1) / 100
maxDailyLoss = input.float(2.0, title="Perdita Massima Giornaliera (%)", minval=0.1) / 100
maxDrawdown = input.float(10.0, title="Drawdown Massimo (%)", minval=0.1) / 100
shortMAPeriod = input.int(20, title="MA Breve Termine", minval=1)
longMAPeriod = input.int(100, title="MA Lungo Termine", minval=1)
// MACD Inputs
macdFastLength = input.int(12, title="MACD Fast Length")
macdSlowLength = input.int(26, title="MACD Slow Length")
macdSignalLength = input.int(9, title="MACD Signal Length")
showSignals = input.bool(true, title="Mostra Segnali di Entrata")
// Prezzi di Apertura e Chiusura delle Candele Precedenti (senza repainting)
prevOpen = ta.valuewhen(1, open, 0)
prevClose = ta.valuewhen(1, close, 0)
// Calculate ATR
atr = ta.atr(atrPeriod)
// Calculate Volume Filter
volumeAvg = ta.sma(volume, 20)
volumeFilter = useVolumeFilter ? volume > (volumeAvg * volumeThreshold) : true
// Calculate Moving Averages
shortMA = ta.sma(close, shortMAPeriod)
longMA = ta.sma(close, longMAPeriod)
// Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, macdFastLength, macdSlowLength, macdSignalLength)
macdConditionLong = macdLine > signalLine
macdConditionShort = macdLine < signalLine
// Determine Trend Direction
uptrend = shortMA > longMA
downtrend = shortMA < longMA
// Determine Order Conditions
longCondition = prevClose > prevOpen and volumeFilter and uptrend and macdConditionLong
shortCondition = prevClose < prevOpen and volumeFilter and downtrend and macdConditionShort
// Calcola la dimensione della posizione basata sul capitale iniziale
initialCapital = strategy.initial_capital
positionSize = (initialCapital * riskPerTrade) / (atr * atrMultiplier)
// Calculate Take Profit and Stop Loss Levels dynamically using ATR
takeProfitLong = close + (atr * takeProfitMultiplier)
stopLossLong = close - (atr * 1.5) // Ridotto per ottimizzare
takeProfitShort = close - (atr * takeProfitMultiplier)
stopLossShort = close + (atr * 1.5) // Ridotto per ottimizzare
// Limite di Perdita Giornaliera
var float dailyLossLimit = na
if na(dailyLossLimit) or (time - time) > 86400000 // Se è un nuovo giorno
dailyLossLimit := strategy.equity * (1 - maxDailyLoss)
// Drawdown Massimo
var float drawdownLimit = na
if na(drawdownLimit)
drawdownLimit := strategy.equity * (1 - maxDrawdown)
// Controllo delle Perdite
if strategy.equity < dailyLossLimit
strategy.cancel_all()
strategy.close_all()
label.new(bar_index, high, text="Perdita Giornaliera Massima Raggiunta", color=color.red)
if strategy.equity < drawdownLimit
strategy.cancel_all()
strategy.close_all()
label.new(bar_index, high, text="Drawdown Massimo Raggiunto", color=color.red)
// Strategy Entries
if (longCondition)
strategy.entry("Long", strategy.long, qty=positionSize)
strategy.exit("Take Profit/Stop Loss Long", from_entry="Long", limit=takeProfitLong, stop=stopLossLong)
if (shortCondition)
strategy.entry("Short", strategy.short, qty=positionSize)
strategy.exit("Take Profit/Stop Loss Short", from_entry="Short", limit=takeProfitShort, stop=stopLossShort)
// Plot Entry Signals
plotshape(series=longCondition and showSignals ? close : na, location=location.belowbar, color=color.green, style=shape.labelup, text="LONG")
plotshape(series=shortCondition and showSignals ? close : na, location=location.abovebar, color=color.red, style=shape.labeldown, text="SHORT")
// Plot Moving Averages
plot(shortMA, color=color.blue, title="MA Breve Termine", linewidth=2)
plot(longMA, color=color.orange, title="MA Lungo Termine", linewidth=2)
// Plot MACD
hline(0, "Zero Line", color=color.gray)
plot(macdLine - signalLine, title="MACD Histogram", color=color.red, style=plot.style_histogram)