// © www.EinfachOptionen.de strategy(title="EO Vola Short Strategy", overlay=true, default_qty_value=100, default_qty_type=strategy.percent_of_equity, initial_capital=100000000) //@version=5 //indicator("Volatility Stop", "VStop", overlay=true, timeframe="", timeframe_gaps=true) length = input.int(20, "Length", minval = 2) src = input.source(close, "Source") factor = input.float(5, "Multiplier", minval = 0.25, step = 0.25) volStop(src, atrlen, atrfactor) => var max = src var min = src var uptrend = true var stop = 0.0 atrM = nz(ta.atr(atrlen) * atrfactor, ta.tr) max := math.max(max, src) min := math.min(min, src) stop := nz(uptrend ? math.max(stop, max - atrM) : math.min(stop, min + atrM), src) uptrend := src - stop >= 0.0 if uptrend != nz(uptrend[1], true) max := src min := src stop := uptrend ? max - atrM : min + atrM [stop, uptrend] [vStop, uptrend] = volStop(src, length, factor) plot(vStop, "Volatility Stop", style=plot.style_circles, color= uptrend ? #008000 : #ff0000, linewidth=2) //end vStop code //date input fields startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31) startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12) startYear = input.int(title="Start Year", defval=2010, minval=1900, maxval=2100) endDate = input.int(title="End Date", defval=31, minval=1, maxval=31) endMonth = input.int(title="End Month", defval=12, minval=1, maxval=12) endYear = input.int(title="End Year", defval=2025, minval=1900, maxval=2100) //check if after startdate + before enddate afterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) beforeEndDate = (time <= timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)) // Make input option to configure trade direction //tradeDirection = input.string(title="Trade Direction", options=["Long", "Short", "Both"], defval="Both") // Translate input into trading conditions string tradeDirection = "Short" longOK = (tradeDirection == "Long") or (tradeDirection == "Both") shortOK = (tradeDirection == "Short") or (tradeDirection == "Both") // long or short longCondition = uptrend == true and afterStartDate == true and beforeEndDate == true and uptrend[2] == false shortCondition = uptrend == false and afterStartDate == true and beforeEndDate == true and uptrend[2] //Falls grds. nur short erlaubt werden soll: //strategy.risk.allow_entry_in(strategy.direction.short) //Stop loss and take profit values SLvalShort = input.float(title="Stop Loss % Short-Trade", defval=10.0, minval=1, maxval=100, step=0.5) TPvalShort = input.float(title="Take Profit % Short-Trade", defval=12.0, minval=1, maxval=100,step=0.5) //SLvalLong = input.float(title="Stop Loss % Long-Trade", defval=10.0, minval=1, maxval=100, step=0.1) //TPvalLong = input.float(title="Take Profit % Long-Trade", defval=12.0, minval=1, maxval=100,step=0.5) //orders strategy.close(id="Short", when=uptrend == true, comment="exit short") strategy.close(id="Long", when=uptrend == false, comment="exit long") if (longOK and longCondition) strategy.entry("Long", strategy.long, when = longCondition, qty=(strategy.equity/close)/1) //oca_type = strategy.oca.cancel, oca_name = "longEntry") if (shortOK and shortCondition) strategy.entry("Short", strategy.short, when=shortCondition, qty=(strategy.equity/close)/1) // oca_type = strategy.oca.cancel, oca_name = "shortEntry") //plot trade while open plot(strategy.position_avg_price, "Laufender Trade", color.green, 1, plot.style_linebr) //LET RUN script idea //Notiz, wenn VXX nicht größer LetrunPerct // input-möglichkeit ausgeblendet - daher zus. Zeile "float letRunPerct = 100" //LetRunPerct = -input.float(title="Kein TakeProfit, wenn VXX nicht >x% gegen uns läuft", defval=2.5, step=0.1, minval=0, maxval=100) float LetRunPerct = 100 LetRunPrice = strategy.position_avg_price - strategy.position_avg_price*(LetRunPerct/100) //plot (LetRunPrice, "Limit Laufen lassen", color.white, 1, plot.style_cross) //Equite before trade + plot drawdown during trade float equityBeforeTrade = strategy.initial_capital + strategy.netprofit float maxDDduringTrade = (-strategy.opentrades.max_drawdown(0)/equityBeforeTrade)*100 //plot (maxDDduringTrade, color=color.green) //plot (LetRunPerct) //plotshape (maxDDduringTrade > LetRunPerct ? maxDDduringTrade : na, style=shape.triangledown, color=color.green) //() Plot the curent trade's drawdown //plot(strategy.opentrades.max_drawdown(0), linewidth=1) //VAR LRTRIGGERED: 0 = not / 1 = triggered var LRTriggered = maxDDduringTrade>=LetRunPerct ? 0 : 1 if maxDDduringTrade < LetRunPerct LRTriggered := 1 else if maxDDduringTrade > LetRunPerct LRTriggered := 0 //plot (LRTriggered, color=color.purple) //Stop-Kurs zeichnen //NEU: check ob long oder short //float SLshort = 0 //if longCondition == true // SLshort := strategy.position_avg_price + strategy.position_avg_price*(SLvalShort/100) //else if shortCondition == true // SLshort := strategy.position_avg_price + strategy.position_avg_price*(SLvalLong/100) //ALT: SLshort = strategy.position_avg_price + strategy.position_avg_price*(SLvalShort/100) plot (SLshort, "StopLoss-Kurs lfd. Trade", color.red, 1, plot.style_linebr) TPshort = strategy.position_avg_price - strategy.position_avg_price*(TPvalShort/100) plot (TPshort, "TakeProfit-Kurs lfd. Trade", color.green, 1, plot.style_linebr) //Stoploss- und Takeprofit-Orders bei LAUFEN LASSEN //if LRTriggered == 0 // vermutlich redundant, immer ausgeblendet lassen float TriggeredLimit = LRTriggered ? strategy.position_avg_price - strategy.position_avg_price*(TPvalShort/100) : strategy.position_avg_price - strategy.position_avg_price*(TPvalShort/100)-50 //plot (TriggeredLimit, "TriggeredLimit bei Laufen lassen", color.yellow, 1, plot.style_linebr) strategy.exit(id="> SL/TP <", stop = strategy.position_avg_price + strategy.position_avg_price*(SLvalShort/100), limit = TriggeredLimit) //strategy.exit(id="Nicht LL = SL+TP", when = LRTriggered[1] == 0, // stop = strategy.position_avg_price + strategy.position_avg_price*(SLval/100), // limit = strategy.position_avg_price - strategy.position_avg_price*(TPval/100)) //Stoploss- und Takeprofit-Orders ohne Laufen lassen // vermutlich redundant, ausgeblendet lassen //strategy.exit(id="SL/TP", when = checkLRP == true, // stop=strategy.position_avg_price + strategy.position_avg_price*(SLval/100), // limit=strategy.position_avg_price - strategy.position_avg_price*(TPval/100)) //NACHLEGEN bei -x% TurboPerct = input.float(title="Anzeige: Nachlegen bei -x% Short Trade", defval=4, step=0.25, minval=0, maxval=100) TurboPerctPrice = strategy.position_avg_price + strategy.position_avg_price*(TurboPerct/100) plot (TurboPerctPrice, "Nachlegen-Preis", color.white, 1, plot.style_cross)