1 | // MACD plus 4 user-defined levels (horizontal lines) |
2 | // Indicator for the Mystery Strategy |
3 | |
4 | //@version=5 |
5 | indicator(title="Mystery Indicator", shorttitle="Mystery Indicator", timeframe="", timeframe_gaps=true) |
6 | // Getting inputs |
7 | fast_length = input(title="Fast Length", defval=25) |
8 | slow_length = input(title="Slow Length", defval=100) |
9 | src = input(title="Source", defval=close) |
10 | signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9) |
11 | sma_source = input.string(title="Oscillator MA Type", defval="EMA", options=["SMA", "EMA"]) |
12 | sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"]) |
13 | |
14 | // Levels to mark |
15 | minMoveLong = input.float(0) |
16 | minMoveShort = input.float(0) |
17 | switchOnLongsAbove = input.float(-100, step=0.1, tooltip="Allow longs only if MACD is above this level") |
18 | switchOnShortsBelow = input.float(100, step=0.1, tooltip="Allow shorts only if MACD is below this level") |
19 | |
20 | // Scaling down the MACD to make a nice picture |
21 | macdScale = 0.5 |
22 | |
23 | // Plot colors |
24 | col_macd = input(#000000, "MACD Line ", group="Color Settings", inline="MACD") |
25 | col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal") |
26 | col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above") |
27 | col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above") |
28 | col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below") |
29 | col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below") |
30 | // Calculating |
31 | fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length) |
32 | slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length) |
33 | macd = fast_ma - slow_ma |
34 | signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length) |
35 | hist = macd - signal |
36 | |
37 | 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))) |
38 | macdPlot = plot(macd*macdScale, title="MACD (scaled)", color=col_macd) |
39 | //plot(signal, title="Signal", color=col_signal) |
40 | |
41 | level1Plot = plot(minMoveLong, title="minMoveLong", color=color.blue) |
42 | level2Plot = plot(-minMoveShort, title="minMoveShort", color=color.blue) |
43 | fill(level1Plot, level2Plot, title="Level 1 to level 2", color=color.new(color.blue, 50)) |
44 | |
45 | level3Plot = plot(switchOnLongsAbove == -100 ? na : switchOnLongsAbove*macdScale, title="switchOnLongsAbove (scaled)", color=na) |
46 | level4Plot = plot(switchOnShortsBelow == 100 ? na : switchOnShortsBelow*macdScale, title="switchOnShortsBelow (scaled)", color=na) |
47 | |
48 | fill(level3Plot, macdPlot, color=color.new(color.lime, macd >= switchOnLongsAbove ? 75 : 100)) |
49 | 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: | 142 / 41 |
Referenced in: | [show references] |