// MACD plus 4 user-defined levels (horizontal lines) // Indicator for the Mystery Strategy //@version=5 indicator(title="Mystery Indicator", shorttitle="Mystery Indicator", timeframe="", timeframe_gaps=true) // Getting inputs fast_length = input(title="Fast Length", defval=25) slow_length = input(title="Slow Length", defval=100) 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"]) // Levels to mark minMoveLong = input.float(0) minMoveShort = input.float(0) switchOnLongsAbove = input.float(-100, step=0.1, tooltip="Allow longs only if MACD is above this level") switchOnShortsBelow = input.float(100, step=0.1, tooltip="Allow shorts only if MACD is below this level") // Scaling down the MACD to make a nice picture macdScale = 0.5 // Plot colors col_macd = input(#000000, "MACD Line ", group="Color Settings", inline="MACD") col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal") col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above") col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above") col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below") col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below") // Calculating fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length) slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(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 plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below))) macdPlot = plot(macd*macdScale, title="MACD (scaled)", color=col_macd) //plot(signal, title="Signal", color=col_signal) level1Plot = plot(minMoveLong, title="minMoveLong", color=color.blue) level2Plot = plot(-minMoveShort, title="minMoveShort", color=color.blue) fill(level1Plot, level2Plot, title="Level 1 to level 2", color=color.new(color.blue, 50)) level3Plot = plot(switchOnLongsAbove == -100 ? na : switchOnLongsAbove*macdScale, title="switchOnLongsAbove (scaled)", color=na) level4Plot = plot(switchOnShortsBelow == 100 ? na : switchOnShortsBelow*macdScale, title="switchOnShortsBelow (scaled)", color=na) fill(level3Plot, macdPlot, color=color.new(color.lime, macd >= switchOnLongsAbove ? 75 : 100)) fill(level4Plot, macdPlot, color=color.new(color.red, macd <= switchOnShortsBelow ? 75 : 100))
Travelled to 1 computer(s): mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036602 |
Snippet name: | Mystery Indicator |
Eternal ID of this version: | #1036602/1 |
Text MD5: | 935de6518e3fcd72ca24446e8cccf6d6 |
Author: | stefan |
Category: | pine script |
Type: | Document |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-04-23 16:23:01 |
Source code size: | 2870 bytes / 49 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 140 / 40 |
Referenced in: | [show references] |