// "Mystery Strategy" / "Holy Grail for ETH" // // Preconfigured for ETH 30m on Bitget // // (c) Stefan Reich //@version=5 strategy(shorttitle="Stefan Reich's Mystery Strategy v198", title="Stefan Reich's Mystery Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.07, initial_capital = 100, default_qty_type=strategy.cash, default_qty_value=1000, calc_on_every_tick = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500) // commission_value is an approximately correct estimate for fees+spread on ETH on typical exchanges (Bitget, Bybit) // This strategy opens few positions though, so fees+spread are not a big deal anyway. shrouded = input.bool(false) startingDate = input.time(timestamp("8 Dec 2022")) doLongs=input.bool(true, "Do longs") doShorts=input.bool(false, "Do shorts") minMoveLong = input.float(1.6, step=0.1) minMoveShort = input.float(1.6, step=0.1) arrowOffset = input.float(10) initialOffset = input.float(10) equityOffset = input.float(10) topOffset = input.float(1, step=0.25) filesSlanted = input.bool(true) ieBoxColor = input.color(color.black) ieTextColor = input.color(color.blue) positionSize = input.float(1000, "Position size in $", tooltip="After leverage") // UTILITY FUNCTIONS drift() => sumDrift = 0.0 for tradeNo = 0 to strategy.opentrades - 1 sumDrift += strategy.opentrades.size(tradeNo) result = sumDrift // macro logFloat(value, title) { plotchar(value, title, "", location.top) } // MACD inputs fast_length = input(title="Fast Length", defval=25) slow_length = input(title="Slow Length", defval=100) macd_src = input(title="Source", defval=close) signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9) sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"]) sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"]) // MACD calculation fast_ma = sma_source == "SMA" ? ta.sma(macd_src, fast_length) : ta.ema(macd_src, fast_length) slow_ma = sma_source == "SMA" ? ta.sma(macd_src, slow_length) : ta.ema(macd_src, slow_length) macd = fast_ma - slow_ma signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) hist = macd - signal // Relative MACD values factor = 10000 / slow_ma relMACD = macd * factor relSignal = signal * factor relHist = (macd - signal) * factor plotchar(hist, "MACD", "", location.top) // logFloat plotchar(relHist, "Relative MACD", "", location.top) // logFloat if barstate.isconfirmed and time >= startingDate qty = positionSize/close if hist >= minMoveLong if doLongs strategy.entry("Long", strategy.long, qty=qty) else strategy.close_all(shrouded ? "Exit" : "MACD Green") if hist <= -minMoveShort if doShorts strategy.entry("Short", strategy.short, qty=qty) else strategy.close_all(shrouded ? "Exit" : "MACD Red") // PAINT TRADES & INITIAL EQUITY plusMinusFix(s) => currency = " $" str.startswith(s, "-") ? "-" + currency + str.substring(s, 1) : "+" + currency + s formatProfit(profit) => plusMinusFix(str.tostring(profit, "#,##0.00")) var int tradesPainted = 0 var label initialEquityLabel = na if na(initialEquityLabel) and time >= startingDate ieText = "?\nWe invest\n$" + str.tostring(strategy.initial_capital, "#,##0") + "\nand start\nthe strategy!" ieTime = startingDate-2*24*60*60*1000 // 2 days back //ieY = close*(1-arrowOffset/100) // for style_label_center //style=label.style_label_center ieY = close*(1-initialOffset/100) // for style_label_up //boxColor = color.black //textColor = color.white style = label.style_label_up //style = label.style_triangleup initialEquityLabel := label.new(ieTime, ieY, ieText, xloc=xloc.bar_time, color=ieBoxColor, textcolor=ieTextColor, tooltip="Initial equity", size=size.huge, style=style) type PaintedTrade array lines array