├── Pmax.pine ├── RSI-VWAP.pine ├── Super Guppy R1.0 by JustUncleL by JustUncleL copy.pine ├── TDIALT.pine ├── UMA-EMA-PSAR-ATR-TS[Numchuck]-v1.2.pine ├── Vortex Trend Tracker.pine ├── hash_ribbon.pine └── tradingview-strategy-backtester-boilerplate.pine /Pmax.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 3 | // © KivancOzbilgic 4 | //developer: @KivancOzbilgic 5 | //author: @KivancOzbilgic 6 | 7 | study("Profit Maximizer","PMax", overlay=true) 8 | src = input(hl2, title="Source") 9 | Periods = input(title="ATR Length", type=input.integer, defval=10) 10 | Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0) 11 | mav = input(title="Moving Average Type", defval="EMA", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"]) 12 | length =input(10, "Moving Average Length", minval=1) 13 | changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true) 14 | showsupport = input(title="Show Moving Average?", type=input.bool, defval=true) 15 | showsignalsk = input(title="Show Crossing Signals?", type=input.bool, defval=true) 16 | showsignalsc = input(title="Show Price/Pmax Crossing Signals?", type=input.bool, defval=false) 17 | highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true) 18 | atr2 = sma(tr, Periods) 19 | atr= changeATR ? atr(Periods) : atr2 20 | valpha=2/(length+1) 21 | vud1=src>src[1] ? src-src[1] : 0 22 | vdd1=src 39 | ma = 0.0 40 | if mav == "SMA" 41 | ma := sma(src, length) 42 | ma 43 | 44 | if mav == "EMA" 45 | ma := ema(src, length) 46 | ma 47 | 48 | if mav == "WMA" 49 | ma := wma(src, length) 50 | ma 51 | 52 | if mav == "TMA" 53 | ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1) 54 | ma 55 | 56 | if mav == "VAR" 57 | ma := VAR 58 | ma 59 | 60 | if mav == "WWMA" 61 | ma := WWMA 62 | ma 63 | 64 | if mav == "ZLEMA" 65 | ma := ZLEMA 66 | ma 67 | 68 | if mav == "TSF" 69 | ma := TSF 70 | ma 71 | ma 72 | 73 | MAvg=getMA(src, length) 74 | longStop = MAvg - Multiplier*atr 75 | longStopPrev = nz(longStop[1], longStop) 76 | longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop 77 | shortStop = MAvg + Multiplier*atr 78 | shortStopPrev = nz(shortStop[1], shortStop) 79 | shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop 80 | dir = 1 81 | dir := nz(dir[1], dir) 82 | dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir 83 | PMax = dir==1 ? longStop: shortStop 84 | plot(showsupport ? MAvg : na, color=#0585E1, linewidth=2, title="Moving Avg Line") 85 | pALL=plot(PMax, color=color.red, linewidth=2, title="PMax", transp=0) 86 | alertcondition(cross(MAvg, PMax), title="Cross Alert", message="PMax - Moving Avg Crossing!") 87 | alertcondition(crossover(MAvg, PMax), title="Crossover Alarm", message="Moving Avg BUY SIGNAL!") 88 | alertcondition(crossunder(MAvg, PMax), title="Crossunder Alarm", message="Moving Avg SELL SIGNAL!") 89 | alertcondition(cross(src, PMax), title="Price Cross Alert", message="PMax - Price Crossing!") 90 | alertcondition(crossover(src, PMax), title="Price Crossover Alarm", message="PRICE OVER PMax - BUY SIGNAL!") 91 | alertcondition(crossunder(src, PMax), title="Price Crossunder Alarm", message="PRICE UNDER PMax - SELL SIGNAL!") 92 | buySignalk = crossover(MAvg, PMax) 93 | plotshape(buySignalk and showsignalsk ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0) 94 | sellSignallk = crossunder(MAvg, PMax) 95 | plotshape(sellSignallk and showsignalsk ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0) 96 | buySignalc = crossover(src, PMax) 97 | plotshape(buySignalc and showsignalsc ? PMax*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0) 98 | sellSignallc = crossunder(src, PMax) 99 | plotshape(sellSignallc and showsignalsc ? PMax*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0) 100 | mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0,display=display.none) 101 | longFillColor = highlighting ? (MAvg>PMax ? color.green : na) : na 102 | shortFillColor = highlighting ? (MAvg leadLine2 ? #53b987 : #eb4d5c) 14 | 15 | // Initial inputs 16 | Act_RSI_VWAP_long = input(true, "RSI VOLUME WEIGHTED AVERAGE PRICE LONG") 17 | RSI_VWAP_length_long = input(15, "RSI-VWAP LENGTH LONG") 18 | RSI_VWAP_overSold_long = input(15, "RSI-VWAP OVERSOLD LONG", type=input.float) 19 | RSI_VWAP_overBought_long = input(72, "RSI-VWAP OVERBOUGHT LONG", type=input.float) 20 | 21 | Act_RSI_VWAP_short = input(true, "RSI VOLUME WEIGHTED AVERAGE PRICE SHORT") 22 | RSI_VWAP_length_short = input(14, "RSI-VWAP LENGTH SHORT") 23 | RSI_VWAP_overSold_short = input(8, "RSI-VWAP OVERSOLD SHORT", type=input.float) 24 | RSI_VWAP_overBought_short = input(72, "RSI-VWAP OVERBOUGHT SHORT", type=input.float) 25 | 26 | // RSI with VWAP as source 27 | RSI_VWAP_long = rsi(vwap(close), RSI_VWAP_length_long) 28 | RSI_VWAP_short = rsi(vwap(close), RSI_VWAP_length_short) 29 | 30 | // Plot Them Separately. 31 | //Plotting LONG, Put overlay=false 32 | r_long=plot(RSI_VWAP_long, color = RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : RSI_VWAP_long < RSI_VWAP_overSold_long ? color.lime : color.blue, title="rsi", linewidth=2, style=plot.style_line) 33 | h1_long=plot(RSI_VWAP_overBought_long, color = color.gray, style=plot.style_stepline) 34 | h2_long=plot(RSI_VWAP_overSold_long, color = color.gray, style=plot.style_stepline) 35 | fill(r_long,h1_long, color = RSI_VWAP_long > RSI_VWAP_overBought_long ? color.red : na, transp = 60) 36 | fill(r_long,h2_long, color = RSI_VWAP_long < RSI_VWAP_overSold_long ? color.lime : na, transp = 60) 37 | 38 | // Plotting SHORT, Put overlay=false 39 | r_short=plot(RSI_VWAP_short, color = RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : color.blue, title="rsi", linewidth=2, style=plot.style_line) 40 | h1_short=plot(RSI_VWAP_overBought_short, color = color.gray, style=plot.style_stepline) 41 | h2_short=plot(RSI_VWAP_overSold_short, color = color.gray, style=plot.style_stepline) 42 | fill(r_short,h1_short, color = RSI_VWAP_short > RSI_VWAP_overBought_short ? color.red : na, transp = 60) 43 | fill(r_short,h2_short, color = RSI_VWAP_short < RSI_VWAP_overSold_short ? color.lime : na, transp = 60) 44 | 45 | 46 | /////// STRATEGY Take Profit / Stop Loss //////// 47 | ////// LONG ////// 48 | long_tp_inp = input(100, title='Long Take Profit %', step=0.1)/100 49 | long_sl_inp = input(3.3, title='Long Stop Loss %', step=0.1)/100 50 | long_trailing = input(100, title='Trailing Stop Long', step=0.1) / 100 51 | 52 | long_take_level = strategy.position_avg_price * (1 + long_tp_inp) 53 | long_stop_level = strategy.position_avg_price * (1 - long_sl_inp) 54 | 55 | ////// SHORT ////// 56 | short_tp_inp = input(100, title='Short Take Profit %', step=0.1)/100 57 | short_sl_inp = input(4, title='Short Stop Loss %', step=0.1)/100 58 | short_trailing = input(100, title='Trailing Stop short', step=0.1) / 100 59 | 60 | short_take_level = strategy.position_avg_price * (1 - short_tp_inp) 61 | short_stop_level = strategy.position_avg_price * (1 + short_sl_inp) 62 | 63 | ///Strategy_Conditions 64 | /// LONG /// 65 | entry_long =crossover(RSI_VWAP_long, RSI_VWAP_overSold_long) and leadLine2leadLine1 72 | entry_price_short=valuewhen(entry_short,close,0) 73 | exit_short =crossover(RSI_VWAP_short, RSI_VWAP_overSold_short) 74 | 75 | ////// BACKTEST PERIOD /////// 76 | testStartYear = input(2019, "Backtest Start Year") 77 | testStartMonth = input(1, "Backtest Start Month") 78 | testStartDay = input(1, "Backtest Start Day") 79 | testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0) 80 | 81 | testStopYear = input(2020, "Backtest Stop Year") 82 | testStopMonth = input(12, "Backtest Stop Month") 83 | testStopDay = input(31, "Backtest Stop Day") 84 | testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0) 85 | 86 | testPeriod() => 87 | time >= testPeriodStart and time <= testPeriodStop ? true : false 88 | 89 | if testPeriod() 90 | if strategy.position_size == 0 or strategy.position_size > 0 91 | strategy.entry("long", true, when = entry_long, comment="*** INSERT OPEN LONG COMMENT FROM WBT ***") 92 | strategy.exit("long", stop=long_stop_level, limit=long_take_level, trail_points=entry_price_long * long_trailing / syminfo.mintick, trail_offset=entry_price_long * long_trailing / syminfo.mintick, comment="*** INSERT CLOSE LONG COMMENT FROM WBT ***") 93 | strategy.close("long", when=exit_long, comment = "*** INSERT CLOSE LONG COMMENT FROM WBT ***") 94 | 95 | if strategy.position_size == 0 or strategy.position_size < 0 96 | strategy.entry("short", false, when = entry_short, comment="*** INSERT OPEN SHORT COMMENT FROM WBT ***") 97 | strategy.exit("TP/SL/TRS_short","short", stop=short_stop_level, limit=short_take_level, trail_points=entry_price_short * short_trailing / syminfo.mintick, trail_offset=entry_price_short * short_trailing / syminfo.mintick, comment = "*** INSERT CLOSE SHORT COMMENT FROM WBT ***") 98 | strategy.close("short", when=exit_short, comment = "*** INSERT CLOSE SHORT COMMENT FROM WBT ***") -------------------------------------------------------------------------------- /Super Guppy R1.0 by JustUncleL by JustUncleL copy.pine: -------------------------------------------------------------------------------- 1 | //@version=3 2 | 3 | study(title="Super Guppy R1.2 by JustUncleL", shorttitle="SuperGuppy", overlay=true) 4 | 5 | // 6 | // Author: JustUncleL 7 | // Revision: R1.2 8 | // Date: 6-Jan-2018 9 | // 10 | // Description: 11 | // ============ 12 | // This indicator is a Super Guppy version of standard Guppy GMMA as used in 13 | // "CM_GUPPY_EMA Revised R2 by JustUncleL". Guppy is designed to capture the 14 | // inferred behaviour of traders and investors by using two groups of averages. 15 | // In this version of Super Guppy Traders Group of EMAs are: 16 | // EMA3 to EMA23 step 2 (Aqua=Uptrend, Blue=downtrend) 17 | // and Investors Group EMAs are: 18 | // EMA25 to EMA70 step 3 (Lime=Uptrend, Red=downtrend) 19 | // (Gray=Trend not established or in a Pull Back). 20 | // 21 | // The idea of Guppy EMAs is to use fractal repetitions to identify points of 22 | // agreement and disagreement which precede significant trend changes. 23 | // For further info on how Guppy/Super Guppy can be used in trading please refer to 24 | // http://www.guppytraders.com/gup329.shtml 25 | // and many other articles available on the subject. 26 | // 27 | // This indicator provides the following : 28 | // - Swing Arrow Alerts (Red for Sell and Green for Buy) to indicate PullBack entries 29 | // after new trend has been established. Also have option to wait for both fast and 30 | // slow to completely seperate (Confluence). Another option is to show alerts 31 | // when show arrows when Candle colour changes, this is handy when using Heikin Ashi 32 | // or Renko Charts. 33 | // - Trend Break Arrow Alerts (Blue for Sell and Aqua for Buy) to indicate entries 34 | // for agressive trend swing point and is calculated by cross over of the 35 | // average Traders EMA with the average Investors EMA. This was suggested option 36 | // by Guppy himself. 37 | // - Anchor time frame (0=current). This is the time frame that the Guppy MAs are 38 | // calculated for. This way 60 Guppy can be viewed on a 15 min chart to establish 39 | // tighter Stop Loss conditions. 40 | // - Alert conditions are also created for the TradingView Alarm subsystem. Only 41 | // alerts for the selected alert options are generated. 42 | // 43 | // References: 44 | // =========== 45 | // - Based on Daryl Guppy GMMA and 46 | // CM GMMA Original - https://www.tradingview.com/v/3rxOtFe0/ 47 | // - http://www.guppytraders.com/gup329.shtml 48 | // 49 | // 50 | // Revisions: 51 | // ========== 52 | // R1 - Original Version 53 | // 54 | // R1.1 - Some changes to limit the number of Alerts that occur close together. 55 | // 56 | // 13-Jan-2018 57 | // - Fix bug in Anchor calculations when chart Time frame not intraday. 58 | // - Fix bug in Break Arrow calculation, stop signal when Investor MAs 59 | // not change direction yet. 60 | // - Change Traders group to start colouring before Investors Group, 61 | // rather than together. 62 | // 63 | // R1.2 14-Feb-2018 64 | // - Fix bug in 1st pullback arrow calculation. 65 | // - Added option to display candle colours relative to Guppy Trend 66 | // indication. 67 | // 06-Apr-2018 68 | // - Change Anchor to be based purely on Minutes, so 1 month=30240mins 69 | // (21 trading days), 1 week=7200mins (5 trading days), 1 Day=1440mins. 70 | // This makes it more consistent across intraday and extraday chart Timeframes. 71 | // 72 | // 73 | // ----------------------------------------------------------------------------- 74 | // Copyright 2014 Chris Moody 75 | // Copyright 2018 JustUncleL 76 | // 77 | // This program is free software: you can redistribute it and/or modify 78 | // it under the terms of the GNU General Public License as published by 79 | // the Free Software Foundation, either version 3 of the License, or 80 | // any later version. 81 | // 82 | // This program is distributed in the hope that it will be useful, 83 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 84 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 85 | // GNU General Public License for more details. 86 | // 87 | // The GNU General Public License can be found here 88 | // . 89 | // 90 | // ----------------------------------------------------------------------------- 91 | // 92 | 93 | 94 | // 95 | // Use Alternate Anchor TF for MAs 96 | anchor = input(0,minval=0,maxval=1440,title="Use Alternate Anchor TimeFrame (0=none, max=1440 (mins,D,W)") 97 | // 98 | src = input(close, title="EMA Source") 99 | ShowBreak = input(true,title="Show Trend Break Arrow Alerts") 100 | ShowSwing = input(true,title="Show Swing Arrow Alerts") 101 | ShowCon = input(false,title="Give Only Fast+Slow Confluence Alerts") 102 | uOCCswing = input(false,title="Add Bar Colour Changes to Swing Alerts") 103 | Lookback = input(6,title="Alert Lookback Length") 104 | ShowAvgs = input(false,title="Show Average Fast and Slow Guppy Curves") 105 | show200 = input(false,title="Show 200 EMA Curve") 106 | emaFilter = input(false,title="Filter Alerts with 200ema") 107 | clrBars = input(false,title="Colour Candles to Guppy Trend state") 108 | 109 | // 110 | //Fast EMAs 111 | lenF1 = input(3, minval=1, title="Fast EMA 1") 112 | lenF2 = input(5, minval=1, title="Fast EMA 2") 113 | lenF3 = input(7, minval=1, title="Fast EMA 3") 114 | lenF4 = input(9, minval=1, title="Fast EMA 4") 115 | lenF5 = input(11, minval=1, title="Fast EMA 5") 116 | lenF6 = input(13, minval=1, title="Fast EMA 6") 117 | lenF7 = input(15, minval=1, title="Fast EMA 7") 118 | lenF8 = input(17, minval=1, title="Fast EMA 8") 119 | lenF9 = input(19, minval=1, title="Fast EMA 9") 120 | lenF10 = input(21, minval=1, title="Fast EMA 10") 121 | lenF11 = input(23, minval=1, title="Fast EMA 11") 122 | 123 | //Slow EMAs 124 | lenS1 = input(25, minval=1, title="Slow EMA 1") 125 | lenS2 = input(28, minval=1, title="Slow EMA 2") 126 | lenS3 = input(31, minval=1, title="Slow EMA 3") 127 | lenS4 = input(34, minval=1, title="Slow EMA 4") 128 | lenS5 = input(37, minval=1, title="Slow EMA 5") 129 | lenS6 = input(40, minval=1, title="Slow EMA 6") 130 | lenS7 = input(43, minval=1, title="Slow EMA 7") 131 | lenS8 = input(46, minval=1, title="Slow EMA 8") 132 | lenS9 = input(49, minval=1, title="Slow EMA 9") 133 | lenS10 = input(52, minval=1, title="Slow EMA 10") 134 | lenS11 = input(55, minval=1, title="Slow EMA 11") 135 | lenS12 = input(58, minval=1, title="Slow EMA 12") 136 | lenS13 = input(61, minval=1, title="Slow EMA 13") 137 | lenS14 = input(64, minval=1, title="Slow EMA 14") 138 | lenS15 = input(67, minval=1, title="Slow EMA 15") 139 | lenS16 = input(70, minval=1, title="Slow EMA 16") 140 | 141 | len = input(200, minval=1, title="EMA 200 Length") 142 | 143 | gold = #FFD700 144 | AQUA = #00FFFFFF 145 | BLUE = #0000FFFF 146 | GRAY = #808080FF 147 | 148 | // If have anchor specified, calculate the base multiplier. 149 | mult = isintraday ? anchor==0 or interval<=0 or interval>=anchor? 1 : round(anchor/interval) : 1 150 | mult := isdwm? isdaily ? (anchor==0 or interval<=0 or interval>=anchor or anchor<=1440 ? 1 : round(anchor/1440)) : 151 | isweekly ? (anchor==0 or interval<=0 or interval>=anchor or anchor<=7200 ? 1 : round(anchor/7200)) : 152 | ismonthly ? (anchor==0 or interval<=0 or interval>=anchor or anchor<=30240 ? 1 : round(anchor/30240)) : 1 : mult 153 | 154 | //adjust MA lengths with Anchor Multiplier 155 | 156 | //Fast EMA 157 | emaF1 = ema(src, lenF1*mult) 158 | emaF2 = ema(src, lenF2*mult) 159 | emaF3 = ema(src, lenF3*mult) 160 | emaF4 = ema(src, lenF4*mult) 161 | emaF5 = ema(src, lenF5*mult) 162 | emaF6 = ema(src, lenF6*mult) 163 | emaF7 = ema(src, lenF7*mult) 164 | emaF8 = ema(src, lenF8*mult) 165 | emaF9 = ema(src, lenF9*mult) 166 | emaF10 = ema(src, lenF10*mult) 167 | emaF11 = ema(src, lenF11*mult) 168 | //average 169 | emafast = (emaF1 + emaF2 + emaF3 + emaF4 + emaF5 + emaF6 + emaF7 + emaF8 + emaF9 + emaF10 + emaF11)/11 170 | // 171 | //Slow EMA 172 | emaS1 = ema(src, lenS1*mult) 173 | emaS2 = ema(src, lenS2*mult) 174 | emaS3 = ema(src, lenS3*mult) 175 | emaS4 = ema(src, lenS4*mult) 176 | emaS5 = ema(src, lenS5*mult) 177 | emaS6 = ema(src, lenS6*mult) 178 | emaS7 = ema(src, lenS7*mult) 179 | emaS8 = ema(src, lenS8*mult) 180 | emaS9 = ema(src, lenS9*mult) 181 | emaS10 = ema(src, lenS10*mult) 182 | emaS11 = ema(src, lenS11*mult) 183 | emaS12 = ema(src, lenS12*mult) 184 | emaS13 = ema(src, lenS13*mult) 185 | emaS14 = ema(src, lenS14*mult) 186 | emaS15 = ema(src, lenS15*mult) 187 | emaS16 = ema(src, lenS16*mult) 188 | // average 189 | emaslow = (emaS1 + emaS2 + emaS3 + emaS4 + emaS5 + emaS6 + emaS7 + emaS8 + 190 | emaS9 + emaS10 + emaS11 + emaS12 + emaS13 + emaS14 + emaS15 + emaS16)/16 191 | // 192 | //EMA 200 193 | ema200 = ema(src, len*mult) 194 | 195 | //Fast EMA Color Rules 196 | colfastL = (emaF1>emaF2 and emaF2>emaF3 and emaF3>emaF4 and emaF4>emaF5 and emaF5>emaF6 and emaF6>emaF7 and emaF7>emaF8 and emaF8>emaF9 and emaF9>emaF10 and emaF10>emaF11) 197 | colfastS = (emaF1emaS2 and emaS2>emaS3 and emaS3>emaS4 and emaS4>emaS5 and emaS5>emaS6 and emaS6>emaS7 and emaS7>emaS8) and 200 | (emaS8>emaS9 and emaS9>emaS10 and emaS10>emaS11 and emaS11>emaS12 and emaS12>emaS13 and emaS13>emaS14 and emaS14>emaS15 and emaS15>emaS16) 201 | colslowS = (emaS1emaS16 ? aqua : colfastS and emaS1emaS16 ? AQUA : colfastS and emaS1 emaslow and emaS1>emaS16 and not colslowS and colfastL and (not ShowCon or colslowL) and (not emaFilter or emafast>ema200)? nz(buy[1])>0?buy[1]+1:1 : 0 260 | sell := emafast < emaslow and emaS10?sell[1]+1:1 : 0 261 | buy := buy>1 and colfastL and (uOCCswing and ((close[1]open))) ? 1 : buy 262 | sell := sell>1 and colfastS and (uOCCswing and ((close[1]>open[1]) and (close emaslow and not colslowS and (not emaFilter or emafast>ema200) ? nz(buybreak[1])>0?buybreak[1]+1:1 : 0 265 | sellbreak := emafast < emaslow and not colslowL and (not emaFilter or emafast0?sellbreak[1]+1 :1 : 0 266 | // 267 | plotarrow(ShowSwing and buy==1 and barssince(nz(buy[1],1)==1)>Lookback?1:na, title="BUY Swing Arrow", colorup=lime, maxheight=60, minheight=50, transp=20) 268 | plotarrow(ShowSwing and sell==1 and barssince(nz(sell[1],1)==1)>Lookback?-1:na, title="SELL Swing Arrow", colordown=red, maxheight=60, minheight=50, transp=20) 269 | 270 | plotarrow(ShowBreak and buybreak==1 and barssince(nz(sellbreak[1],1)==1)>Lookback and barssince(nz(buybreak[1],1)==1)>Lookback?1:na, title="BUY Break Arrow", colorup=aqua, maxheight=60, minheight=50, transp=20) 271 | plotarrow(ShowBreak and sellbreak==1 and barssince(nz(buybreak[1],1)==1)>Lookback and barssince(nz(sellbreak[1],1)==1)>Lookback?-1:na, title="SELL Break Arrow", colordown=blue, maxheight=60, minheight=50, transp=20) 272 | 273 | // Generate only Alarms that are selected. 274 | gAlert = (ShowSwing and ((buy==1 and barssince(nz(buy[1],1)==1)>Lookback) or (sell==1 and barssince(nz(sell[1],1)==1)>Lookback))) or 275 | (ShowBreak and (buybreak==1 or sellbreak==1) and barssince(nz(buybreak[1],1)==1)>Lookback and barssince(nz(sellbreak[1],1)==1)>Lookback) 276 | alertcondition(gAlert,title="Guppy Alert Arrow",message="Guppy Alert") 277 | alertcondition((ShowSwing and buy==1 and barssince(nz(buy[1],1)==1)>Lookback) or 278 | (ShowBreak and buybreak==1 and barssince(nz(buybreak[1],1)==1)>Lookback and barssince(nz(sellbreak[1],1)==1)>Lookback),title="Buy Arrow",message="BUY") 279 | alertcondition((ShowSwing and sell==1 and barssince(nz(sell[1],1)==1)>Lookback) or 280 | (ShowBreak and sellbreak==1 and barssince(nz(buybreak[1],1)==1)>Lookback and barssince(nz(sellbreak[1],1)==1)>Lookback),title="Sell Arrow",message="SELL") 281 | 282 | // 283 | //eof -------------------------------------------------------------------------------- /TDIALT.pine: -------------------------------------------------------------------------------- 1 | //@version=3 2 | // 3 | 4 | study("Traders Dynamic Index Indicator Alert v1.3 by JustUncleL", shorttitle="TDIALT") 5 | 6 | // 7 | // author: JustUncleL 8 | // date: 1-Mar-2016 9 | // 10 | // Original code @author LazyBear for basic TDI indicator. 11 | // If you use this code in its orignal/modified form, do drop me a note. 12 | // 13 | // Description: 14 | // This is a Trend following system utilising the Traders Dynamic Index (TDI), 15 | // Price Action Channel (PAC) and Heikin Ashi candles. 16 | // About 6months ago I came across the use of TDI in "E.A.S.Y. Method" that I found in 17 | // forexfactory forums: http://www.forexfactory.com/attachment.php?attachmentid=686629&d=1303831008 18 | // and I was able to set up a chart based on the specifications by using Kurbelklaus scripts. 19 | // However, I found that the alerts were being generated one or two bars too late, 20 | // so I was not successful using it with Binary Options. Later I found a variation of the 21 | // method in the forums which generates alerts a bit earlier, so this indicator is a 22 | // variation of that early detection version. 23 | // The indicator can optionally use Heikin Ashi candles only for all it's calculations, 24 | // I would recommend viewing the chart with normal Heikin Ashi candles, these 25 | // smooth out the trends and makes them more visible. 26 | // 27 | // I found that this metod it works OK with currency pairs or commodities. 28 | // It also seems to work well with 5min+ timeframe charts, 29 | // and I would suggest expiry of 2 to 6 candles. 30 | // 31 | // ALERT GENERATION: 32 | // ================= 33 | // 34 | // The TDI (Traders Dynamic Index) 35 | // ------------------------------- 36 | // Volatility Band VB(34), color: Blue, buffer: UpZone, DnZone 37 | // Relative Strength Index RSI(13) 38 | // RSI PRICE LINE (2), color: Green, buffer: mab 39 | // RSI TRADE SIGNAL LINE (7), color: Red, buffer: mbb 40 | // MARKET BASE LINE MID VB(34), color: Orange, buffer: mid 41 | // 42 | // Indicator SignalLevels: 43 | // ----------------------- 44 | // RSI_OversoldLevel : 22 (normally: 32) 45 | // RSI_OverboughtLevel : 78 (normally: 68) 46 | // 47 | // Alert Conditions: 48 | // ----------------- 49 | // Strong Buy (yellow): HIGH>PAC upper && BULL Candle && Candle High>PAC High && RSI>TRADE SIGNAL LINE && RSI>RSI_OversoldLevel && 50 | // && RSI MARKET BASE LINE 51 | // Medium Buy (aqua): HIGH>PAC upper && BULL Candle && Candle High>PAC High && RSI>TRADE SIGNAL LINE && RSI>RSI_OversoldLevel 52 | // && RSI MARKET BASE LINE && TRADE SIGNAL LINE< MARKET BASE LINE 53 | // Weak Buy (blue): HIGH>PAC upper && BULL Candle && Candle High>PAC High && RSI>TRADE SIGNAL LINE && RSI>RSI_OversoldLevel 54 | // && RSIPAC Low && RSIRSI_OversoldLevel 57 | // && RSIPAC Low && RSIRSI_OversoldLevel 59 | // && RSI MARKET BASE LINE 60 | // Weak Sell (black): LOWPAC Low && RSIRSI_OversoldLevel 61 | // && RSI MARKET BASE LINE && RSI> MARKET BASE LINE 62 | // 63 | // HIGH LEVEL FILTER (Overbought): RSI>=RSI_OverboughtLevel or MACD Histogram not green 64 | // LOW LEVEL FILTER (Oversold): RSI<=RSI_OversoldLevel or MACD Histogram not red 65 | // 66 | // Hints on How to use: 67 | // -------------------- 68 | // - When a Medium or Strong alert is generated and MACD histogram colour matches the direction 69 | // of the alert, then place trade in direction of alert candle and MACD. 70 | // - Use the multi-Hull MA's for trend direction confirmation. 71 | // - Best positions occur near the MACD(8,16,1) Histogram crossing the zero line. 72 | // - The optional coloured Dots along the bottom of the indicator represent the first alert 73 | // of this type that was generated in this sequence. 74 | // - It is advisable to trade in the direction of the main trend as indicated the HULL MA red cloud: 75 | // if red cloud underneath PAC then BULLISH trend, if red cloud above PAC then BEARISH trend. 76 | // - Selecting the HeiKin Ashi candles does affect the MACD and MA caculations, so if you select 77 | // normal candles the result chart will change. Although the TDI calculations and alerts will stay the 78 | // same. 79 | // - When using the Heikin Ashi candles, a good buy entry is indicated by long top wick and no bottom wick 80 | // for bull (green) candles and good sell entry is indicated by long bottom wick and no top wick for 81 | // bear (red) candles. 82 | // - When the MACD histogram is flat and close to zero line, 83 | // this indicates a ranging market, do NOT trade when this occurs. 84 | // - When the PAC channel on the main chart is spread apart widely, this is an indication 85 | // of extreme volitity and choppy chart, do NOT try to trade during these periods. 86 | // A choppy chart is also indicated by Heikin Ashi candles with long wicks on both sides 87 | // of the candles. 88 | // - You can specify what strength level Alerts are generated (default 2): 89 | // Level (1) means only generate Strong Alerts only. 90 | // Level (2) means generate Strong and Medium Alerts. 91 | // Level (3) means generate Strong, Medium and Weak Alerts. 92 | // 93 | // Modifications: 94 | // -------------- 95 | // 1.3 7-Aug-2017 96 | // - Modified Alertcondition code so that it only signals on the last completed alerted 97 | // candle. This should prevent some false alerts and multiple alerts being generated. 98 | // When setting alarms I suggest using Frequency "Once per bar (on condition)" to get 99 | // the earliest signal possible. 100 | // - Added optional alert long/short spikes that only occur on the first Long or Short 101 | // signals. 102 | // 1.2 5-Aug-2017: 103 | // - Added new alerts for Buy and Sell (Long and Short) signals seperately. 104 | // - Upgraded to version 3 Pinescript. 105 | // - Added work around patch for opaque bar colouring issue. 106 | // 107 | // 1.1 - Modified code so when viewing Top chart with Heikin Ashi candles, calculations 108 | // are still based on standard candles, unless Heikin Ashi calculation option selected. 109 | // 110 | // 0.2 - Simplified MACD direction calculation to use just rising/falling. 111 | // 0.1 - Oroginal Version 112 | // References: 113 | // ----------- 114 | // Traders Dynamic Index [LazyBear] 115 | // KK_Traders Dynamic Index_Bar Highlighting by Kurbelklaus 116 | // KK_Price Action Channel (TDI BH) by Kurbelklaus 117 | // http://www.forexfactory.com/attachment.php?attachmentid=686629&d=1303831008 118 | // http://www.forexstrategiesresources.com/trading-system-metatrader-4-iv/504-traders-dynamic-index-how-to-use/ 119 | // http://www.forexfactory.com/showthread.php?t=460148 120 | // http://www.forexstrategiesresources.com/scalping-forex-strategies-ii/205-scalping-with-tdi-real-macd-stochrainbow/ 121 | // 122 | lengthrsi=input(13) 123 | lengthband=input(34) 124 | lengthrsipl=input(2) 125 | lengthtradesl=input(7) 126 | lenH = input(5, minval=1, title="Price Action Channel Length") 127 | lenL = lenH 128 | rsiOSL= input(22, minval=0,maxval=49,title="RSI Oversold Level") 129 | rsiOBL= input(78, minval=51,maxval=100,title="RSI Overbought Level") 130 | strength = input(2,minval=1,maxval=3,step=1,title="Strength Level: (1)Strong (2)Medium (3)All") 131 | sgb = input(false, title="Check Box To Turn Bars Gray") 132 | sbr = input(true, title="Highlight TDI Alert Bars") 133 | sal = input(true, title="Show Alert Condition Status") 134 | uha = input(false, title="Use Heikin Ashi Candles for Calculations") 135 | sspikes = input(false, title="Show Spike LONG and SHORT Signals") 136 | // 137 | 138 | // Constants colours that include fully non-transparent option. 139 | blue100 = #0000FFFF 140 | aqua100 = #00FFFFFF 141 | fuchsia100 = #FF00FFFF 142 | purple100 = #800080FF 143 | gray100 = #808080FF 144 | gold100 = #FFD700FF 145 | white100 = #FFFFFFFF 146 | black100 = #000000FF 147 | gold = #FFD700 148 | 149 | 150 | // Use only Heikinashi Candles for all calculations or use Standard Candles for calculations. 151 | srcClose = uha ? security(heikinashi(tickerid), period, close) : security(ticker, period, close) 152 | srcOpen = uha ? security(heikinashi(tickerid), period, open) : security(ticker, period, open) 153 | srcHigh = uha ? security(heikinashi(tickerid), period, high) : security(ticker, period, high) 154 | srcLow = uha ?security(heikinashi(tickerid), period, low) : security(ticker, period, low) 155 | // 156 | r=rsi(srcClose, lengthrsi) 157 | ma=sma(r,lengthband) 158 | offs=(1.6185 * stdev(r, lengthband)) 159 | upZone=ma+offs 160 | dnZone=ma-offs 161 | mid=(upZone+dnZone)/2 162 | mab=sma(r, lengthrsipl) 163 | mbb=sma(r, lengthtradesl) 164 | // 165 | hline(rsiOSL, color=red, linewidth=1) 166 | hline(50, color=black, linewidth=1) 167 | hline(rsiOBL, color=lime, linewidth=1) 168 | // Plot the TDI 169 | upl=plot(upZone, color=blue, title="VB Channel High",linewidth=2) 170 | dnl=plot(dnZone, color=blue, title="VB Channel Low",linewidth=2) 171 | midl=plot(mid, color=orange, linewidth=2, title="MBL") 172 | mabl=plot(mab, color=green, linewidth=2, title="RSI PL") 173 | mbbl=plot(mbb, color=red, linewidth=2, title="TSL Signal") 174 | // 175 | //create RSI TSL cloud to indicate trend direction. 176 | fill(mabl,mbbl, color=mab>mbb?green:red,transp=90) 177 | 178 | // Calculate Price Action Channel (PAC) 179 | smmaH = 0.0 180 | smmaL = 0.0 181 | smmaH := na(smmaH[1]) ? sma(srcHigh, lenH) : (smmaH[1] * (lenH - 1) + srcHigh) / lenH 182 | smmaL := na(smmaL[1]) ? sma(srcLow, lenL) : (smmaL[1] * (lenL - 1) + srcLow) / lenL 183 | // 184 | umacd = input(false,title="Use MACD Filtering") 185 | fastMA = input(title="MACD Fast MA Length", type = integer, defval = 8, minval = 2) 186 | slowMA = input(title="MACD Slow MA Length", type = integer, defval = 16, minval = 7) 187 | signal = input(title="MACD Signal Length",type=integer,defval=1,minval=1) 188 | // 189 | // 190 | [currMacd,_,_] = macd(srcClose[0], fastMA, slowMA, signal) 191 | macdH = currMacd > 0 ? rising(currMacd,2) ? green : red : falling(currMacd, 2) ? red : green 192 | 193 | // 194 | // Bar - Highlighting based on indication strength 195 | long= (not umacd or macdH==green) and mab > mbb and mab < rsiOBL and mab > rsiOSL and srcHigh > smmaH and srcClose > srcOpen ? 196 | mbb > mid ? 1 : mab>mid and mbb rsiOSL and srcLow < smmaL and srcClose < srcOpen ? 198 | mbb < mid ? 1 : mabmid ? 2 :mab>mid and mbb>mid ? 3 : 0 : 0 199 | // 200 | // Find the right Bar colour if enabled. 201 | bcolor = not sbr? na : long==1? gold100: long==2 and strength>1? aqua100:long==3 and strength>2? blue100: 202 | short==1? fuchsia100: short==2 and strength>1? purple100:short==3 and strength>2? black100 : 203 | sgb ? gray100 : na 204 | // 205 | barcolor(color=bcolor,title="Bars Colours") 206 | // 207 | // 208 | // create alerts only once per sequence type. 209 | // 210 | long_ = (long>0 and long!=long[1] and long<=strength) 211 | short_ = (short>0 and short!=short[1] and short<=strength) 212 | c_alert = long_ or short_ 213 | alertcondition(c_alert[1] and barstate.isnew, title="TDIALT Alert", message="TDIALT Alert") 214 | alertcondition(long_[1] and barstate.isnew, title="TDIALT Long Alert", message="TDIALT Long") 215 | alertcondition(short_[1] and barstate.isnew, title="TDIALT Short Alert", message="TDIALT Short") 216 | 217 | // Single Alert Strategy 218 | stateLong = 0 219 | stateShort = 0 220 | stateLong_ = nz(stateLong[1]) 221 | stateShort_ = nz(stateShort[1]) 222 | 223 | //Count the long signals before next short 224 | if (long[1]>0 and long[1]<=strength) 225 | stateLong_ := stateLong_>0 ? stateLong_+1 : 1 226 | stateShort_:= 0 227 | 228 | //Count the short signals before next long. 229 | if (short[1]>0 and short[1]<=strength) 230 | stateShort_ := stateShort_>0 ? stateShort_+1 : 1 231 | stateLong_ := 0 232 | 233 | //create spikes, hide them by setting transp=100 234 | plot( sspikes?stateLong_==1? 100 : 0:na, color=blue, title="LONG",transp=50) 235 | plot( sspikes?stateShort_==1? 100 :0:na, color=red, title="SHORT",transp=50) 236 | 237 | //keep current state counts. 238 | stateLong := stateLong_>0? stateLong_+1 : 0 239 | stateShort := stateShort_>0? stateShort_+1 : 0 240 | 241 | 242 | // 243 | // show dot only when alert condition is met and bar closed. 244 | plotshape(sal and c_alert[1],title= "Alert Indicator", location=location.bottom, 245 | color=long[1]==1? gold: long[1]==2?aqua:long[1]==3?blue:short[1]==1?fuchsia: 246 | short[1]==2?purple:short[1]==3? black : na, transp=0, style=shape.circle,offset=-1) 247 | // 248 | //EOF -------------------------------------------------------------------------------- /UMA-EMA-PSAR-ATR-TS[Numchuck]-v1.2.pine: -------------------------------------------------------------------------------- 1 | // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ 2 | // Thisfile contains a combination of code from Simple Moving Averages, PSAR, ATR stop loss, Trailing stop loss and Chris Moody MA indicator. 3 | // All credit is due to the authors of the pieces of code below. 4 | 5 | // Version 1.2 - jan 2020 - Bas Willemstijn 6 | study(title="UMA-SMA-PSAR-ATR-TS-MM", shorttitle="UMA-SMA-PSAR-ATR-TS-MM", overlay=true) 7 | 8 | 9 | // Chris Moody Ultimate Moving Average 10 | //inputs 11 | src = close 12 | useCurrentRes = input(true, title="Use Current Chart Resolution?") 13 | resCustom = input(title="Use Different Timeframe? Uncheck Box Above", type=resolution, defval="D") 14 | len = input(14, title="Moving Average Length - LookBack Period") 15 | //periodT3 = input(defval=7, title="Tilson T3 Period", minval=1) 16 | factorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0) 17 | atype = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3") 18 | spc=input(false, title="Show Price Crossing 1st Mov Avg - Highlight Bar?") 19 | cc = input(true,title="Change Color Based On Direction?") 20 | smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - Setting 1 = No Smoothing") 21 | doma2 = input(false, title="Optional 2nd Moving Average") 22 | spc2=input(false, title="Show Price Crossing 2nd Mov Avg?") 23 | len2 = input(50, title="Moving Average Length - Optional 2nd MA") 24 | sfactorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.", minval=0) 25 | atype2 = input(1,minval=1,maxval=8,title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA, 6=RMA, 7=TEMA, 8=Tilson T3") 26 | cc2 = input(true,title="Change Color Based On Direction 2nd MA?") 27 | warn = input(false, title="***You Can Turn On The Show Dots Parameter Below Without Plotting 2nd MA to See Crosses***") 28 | warn2 = input(false, title="***If Using Cross Feature W/O Plotting 2ndMA - Make Sure 2ndMA Parameters are Set Correctly***") 29 | sd = input(false, title="Show Dots on Cross of Both MA's") 30 | 31 | res = useCurrentRes ? period : resCustom 32 | //hull ma definition 33 | hullma = wma(2*wma(src, len/2)-wma(src, len), round(sqrt(len))) 34 | //TEMA definition 35 | ema1 = ema(src, len) 36 | ema2 = ema(ema1, len) 37 | ema3 = ema(ema2, len) 38 | tema = 3 * (ema1 - ema2) + ema3 39 | 40 | //Tilson T3 41 | factor = factorT3 *.10 42 | gd(src, len, factor) => ema(src, len) * (1 + factor) - ema(ema(src, len), len) * factor 43 | t3(src, len, factor) => gd(gd(gd(src, len, factor), len, factor), len, factor) 44 | tilT3 = t3(src, len, factor) 45 | 46 | 47 | avg = atype == 1 ? sma(src,len) : atype == 2 ? ema(src,len) : atype == 3 ? wma(src,len) : atype == 4 ? hullma : atype == 5 ? vwma(src, len) : atype == 6 ? rma(src,len) : atype == 7 ? 3 * (ema1 - ema2) + ema3 : tilT3 48 | //2nd Ma - hull ma definition 49 | hullma2 = wma(2*wma(src, len2/2)-wma(src, len2), round(sqrt(len2))) 50 | //2nd MA TEMA definition 51 | sema1 = ema(src, len2) 52 | sema2 = ema(sema1, len2) 53 | sema3 = ema(sema2, len2) 54 | stema = 3 * (sema1 - sema2) + sema3 55 | 56 | //2nd MA Tilson T3 57 | sfactor = sfactorT3 *.10 58 | sgd(src, len2, sfactor) => ema(src, len2) * (1 + sfactor) - ema(ema(src, len2), len2) * sfactor 59 | st3(src, len2, sfactor) => sgd(sgd(gd(src, len2, sfactor), len2, sfactor), len2, sfactor) 60 | stilT3 = st3(src, len2, sfactor) 61 | 62 | avg2 = atype2 == 1 ? sma(src,len2) : atype2 == 2 ? ema(src,len2) : atype2 == 3 ? wma(src,len2) : atype2 == 4 ? hullma2 : atype2 == 5 ? vwma(src, len2) : atype2 == 6 ? rma(src,len2) : atype2 == 7 ? 3 * (ema1 - ema2) + ema3 : stilT3 63 | 64 | out = avg 65 | out_two = avg2 66 | 67 | out1 = security(tickerid, res, out) 68 | out2 = security(tickerid, res, out_two) 69 | 70 | //Formula for Price Crossing Moving Average #1 71 | cr_up = open < out1 and close > out1 72 | cr_Down = open > out1 and close < out1 73 | //Formula for Price Crossing Moving Average #2 74 | cr_up2 = open < out2 and close > out2 75 | cr_Down2 = open > out2 and close < out2 76 | //barcolor Criteria for Price Crossing Moving Average #1 77 | iscrossUp() => cr_up 78 | iscrossDown() => cr_Down 79 | //barcolor Criteria for Price Crossing Moving Average #2 80 | iscrossUp2() => cr_up2 81 | iscrossDown2() => cr_Down2 82 | 83 | ma_up = out1 >= out1[smoothe] 84 | ma_down = out1 < out1[smoothe] 85 | 86 | col = cc ? ma_up ? lime : ma_down ? red : aqua : aqua 87 | col2 = cc2 ? ma_up ? lime : ma_down ? red : aqua : white 88 | 89 | circleYPosition = out2 90 | 91 | plot(out1, title="Multi-Timeframe Moving Avg", style=line, linewidth=4, color = col) 92 | plot(doma2 and out2 ? out2 : na, title="2nd Multi-TimeFrame Moving Average", style=circles, linewidth=4, color=col2) 93 | plot(sd and cross(out1, out2) ? circleYPosition : na,style=cross, linewidth=15, color=aqua) 94 | //barcolor Plot for Price Crossing Moving Average #1 95 | barcolor(spc and iscrossUp() ? (iscrossUp() ? yellow : na) : na) 96 | barcolor(spc and iscrossDown() ? (iscrossDown() ? yellow : na) : na) 97 | //barcolor Plot for Price Crossing Moving Average #2 98 | barcolor(spc2 and iscrossUp2() ? (iscrossUp2() ? yellow : na) : na) 99 | barcolor(spc2 and iscrossDown2() ? (iscrossDown2() ? yellow : na) : na) 100 | 101 | // PSAR 102 | //Simply Enhances Default Parabolic SAR by creating Two Color Options, One for UpTrend, Other for DownTrend 103 | //Ability To Turn On/Off The Up Trending Parabolic SAR, And The Down Trending Parabolic SAR 104 | start = input(2, minval=0, maxval=10, title="Start - Default = 2 - Multiplied by .01") 105 | increment = input(2, minval=0, maxval=10, title="Step Setting (Sensitivity) - Default = 2 - Multiplied by .01" ) 106 | maximum = input(2, minval=1, maxval=10, title="Maximum Step (Sensitivity) - Default = 2 - Multiplied by .10") 107 | sus = input(true, "Show Up Trending Parabolic Sar") 108 | sds = input(true, "Show Down Trending Parabolic Sar") 109 | disc = input(false, title="Start and Step settings are *.01 so 2 = .02 etc, Maximum Step is *.10 so 2 = .2") 110 | //"------Step Setting Definition------" 111 | //"A higher step moves SAR closer to the price action, which makes a reversal more likely." 112 | //"The indicator will reverse too often if the step is set too high." 113 | 114 | //"------Maximum Step Definition-----") 115 | //"The sensitivity of the indicator can also be adjusted using the Maximum Step." 116 | //"While the Maximum Step can influence sensitivity, the Step carries more weight" 117 | //"because it sets the incremental rate-of-increase as the trend develops" 118 | 119 | startCalc = start * .01 120 | incrementCalc = increment * .01 121 | maximumCalc = maximum * .10 122 | 123 | sarUp = sar(startCalc, incrementCalc, maximumCalc) 124 | sarDown = sar(startCalc, incrementCalc, maximumCalc) 125 | 126 | colUp = close >= sarDown ? lime : na 127 | colDown = close <= sarUp ? red : na 128 | 129 | plot(sus and sarUp ? sarUp : na, title="Up Trending SAR", style=circles, linewidth=4,color=colUp) 130 | plot(sds and sarDown ? sarDown : na, title="Up Trending SAR", style=circles, linewidth=4,color=colDown) 131 | 132 | // ATR indicator 133 | length = input(7, minval=1) 134 | src1 = input(close, title="Source") 135 | mult = input(2.0, minval=0.001, maxval=50) 136 | maLen=input(7,title="maLength") 137 | basis = sma(src1, length) 138 | dev = mult * atr(length) 139 | upper = basis + dev 140 | lower = basis - dev 141 | bbr = (src1 - lower)/(upper - lower) 142 | bbe= ema(bbr,maLen) 143 | up = bbe[1]>bbe and bbe[2]bbe[1]?bbe:na 145 | 146 | topH=na(up)==0?highest(3):na 147 | bottomL=na(bt)==0?lowest(3):na 148 | 149 | tf= fixnan(topH) 150 | bf =fixnan(bottomL) 151 | 152 | btop=close>open?close:open 153 | bbot=close>open?open:close 154 | 155 | plot(tf,color=blue,style=circles,linewidth=1,offset=-1,title="Bearish SL") 156 | plot(bf,color=blue,style=circles,linewidth=1,offset=-1,title="Bullish SL") 157 | 158 | // Some important simple moving averages 159 | // 21 day/week moving average is an indicator of a bullish or bearish trend. 160 | // 200 day is also used as an indicator for bullish or bearish price action. 161 | // crossing of the 50 and 200 SMA signals golden (bullish) or death (bearish) trend. 162 | 163 | smalen21 = input(21, minval=1, title="Fast Length") 164 | src21 = input(close, title="Source") 165 | out21 = sma(src21, smalen21) 166 | smalen50 = input(50, minval=1, title="Slow Length") 167 | src50 = input(close, title="Source") 168 | out50 = sma(src50, smalen50) 169 | smalen200 = input(200, minval=1, title="Extreme Slow Length") 170 | src200 = input(close, title="Source") 171 | out200 = sma(src200, smalen200) 172 | 173 | plot(out21,title="21 day SMA", color=#095256, transp=0, linewidth=1) 174 | plot(out50, title="50 day SMA", color=#d7263d, transp=0, linewidth=2) 175 | plot(out200, title="200 day SMA", color=#fbaa29, transp=0, linewidth=2) 176 | 177 | // ATR Trailing stop loss 178 | nATRPeriod = input(14) 179 | nATRMultip = input(3) // take 3x atr as safe stop loss indicator, prevents hunter wicks 180 | xATR = atr(nATRPeriod) 181 | nLoss = nATRMultip * xATR 182 | xATRTrailingStop = iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss), 183 | iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss), 184 | iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss))) 185 | pos = iff(close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0), 1, 186 | iff(close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) 187 | color = pos == -1 ? red: pos == 1 ? green : blue 188 | plot(xATRTrailingStop, color=color, title="ATR Trailing Stop") 189 | 190 | // Mayer Multiple signal 191 | // When price extends over this line, be warned for a pullback. 192 | 193 | sma_len = input(200, minval=1, title="SMA 200 Length") 194 | amm = input(2.4, minval=1, title="Average Mayer Multiple") 195 | out_mm = sma(close, sma_len) 196 | out_mm1 = security(tickerid, 'D', out_mm) 197 | 198 | plot(out_mm1 * amm, color=blue, title="Mayer Multiple Buy Price") -------------------------------------------------------------------------------- /Vortex Trend Tracker.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | 3 | // Added Alerting to @ProfitProgrammers Vortex Trend Tracker 2.0 + RSI Script 4 | 5 | study("Vortex Trend Tracker 2.0 + RSI") 6 | 7 | // INPUT VARIABLES FOR VORTEX: 8 | vortexLen = input(30, title="Length for Vortex", minval=1) 9 | emaLen = input(10, title="Length of Positive and Negative EMA's", type=input.integer, minval=1) 10 | colorBars = input(true, title="Color Price Bars Based on Vortex?") 11 | plotVLines = input(true, title="Plot VI+ and VI- Lines?") 12 | // RSI INPUTS: 13 | rsiSrc = input(close, title="RSI Source") 14 | lenSlowRSI = input(29, title="Length of Slow RSI", type=input.integer, minval=1) 15 | lenFastRSI = input(9, title="Length of Fast RSI", type=input.integer, minval=1) 16 | plotRSI = input(false, title="Plot RSI Lines?") 17 | // VORTEX CALCULATION: 18 | //Returns positive and negative trendlines. 19 | vortex(posSum, negSum, vLen)=> 20 | tRange = sum(atr(1), vLen) 21 | vmPlus = posSum / tRange 22 | vmNeg = negSum / tRange 23 | [vmPlus, vmNeg] 24 | 25 | [vPlus, vNeg] = vortex(sum(abs(high - low[1]), vortexLen), sum(abs(low - high[1]), vortexLen), vortexLen) 26 | plusEMA = ema(vPlus, emaLen) 27 | negEMA = ema(vNeg, emaLen) 28 | vDiff = abs(plusEMA - negEMA) 29 | 30 | // RSI CALCULATION: 31 | fastSlow(fastLen, slowLen, s0, s1)=> 32 | fast = rsi(s0, fastLen) 33 | slow = rsi(s1, slowLen) 34 | [fast, slow] 35 | 36 | [fastRSI, slowRSI] = fastSlow(lenFastRSI, lenSlowRSI, rsiSrc, rsiSrc) 37 | [fastRSI1, slowRSI1] = fastSlow(round(lenFastRSI/2), round(lenSlowRSI/2), rsiSrc, rsiSrc) 38 | 39 | 40 | // PLOTTING: 41 | var color vColor = na 42 | vColor := plusEMA > negEMA and plusEMA >= plusEMA[1] ? #1b5e20 : plusEMA > negEMA and plusEMA < plusEMA[1] ? #a5d6a7 : negEMA >= plusEMA and negEMA > negEMA[1] ? #b71c1c : negEMA > plusEMA and negEMA < negEMA[1] ? #c76a72 : nz(vColor[1]) 43 | v0 = plot(vDiff, style=plot.style_histogram, color=vColor, linewidth=2, transp=0) 44 | plot(plotVLines ? plusEMA : na, title="VI +", color=color.green, linewidth=2) 45 | plot(plotVLines ? negEMA : na, title="VI -", color=color.red, linewidth=2) 46 | barcolor(colorBars ? vColor : na) 47 | // Use conditional in transp param. instead of plot to prevent loss of background fill. 48 | r0 = plot(fastRSI/100, color=fastRSI > 50 ? color.teal : color.maroon, title="Fast RSI", linewidth=1, transp=plotRSI ? 25 : 100) 49 | r1 = plot(slowRSI/100, color=slowRSI > 50? color.green : color.red, title="Slow RSI", linewidth=1, transp = plotRSI ? 25 : 100) 50 | r2 = plot(fastRSI1/100, color=fastRSI1 > 50 ? color.lime : color.fuchsia, title="Fast RSI 2", linewidth=1, transp=plotRSI ? 25 : 100) 51 | r3 = plot(slowRSI1/100, color=slowRSI1 > 50 ? color.lime : color.red, title="Slow RSI 2", linewidth=1, transp = plotRSI ? 25 : 100) 52 | fill(r0, v0, color=fastRSI >= 50 ? color.green : color.red, title="Fill 0") 53 | fill(r1, v0, color=slowRSI >= 50 ? color.teal : color.fuchsia) 54 | fill(r0, r1, color=fastRSI > slowRSI ? color.lime : fastRSI < slowRSI ? color.maroon : na, transp=80,title="Intra-RSI Fill") 55 | fill(r2, v0, color=fastRSI1 > slowRSI1 ? #00ff00 : #ec407a, transp=90) 56 | 57 | //Alerts 58 | long = cross(plusEMA, negEMA) and (plusEMA > negEMA) 59 | short = cross(plusEMA, negEMA) and (plusEMA < negEMA) 60 | 61 | //plotshape(long ? 1:0, "BUY NOW", color=color.lime, transp=0, size=size.tiny, style=shape.triangleup, location=location.belowbar) 62 | //plotshape(short ? 1:0, "SELL NOW", color=color.red, transp=0, size=size.tiny, style=shape.triangledown, location=location.abovebar) 63 | 64 | bgcolor(long==1 ? color.lime : na, title="BUY NOW", transp=30) 65 | bgcolor(short==1 ? color.red : na, title="SELL NOW", transp=30) 66 | 67 | alertcondition(condition=cross(plusEMA, negEMA) and (plusEMA > negEMA), title="BUY ALERT", message="BUY ALERT") 68 | alertcondition(condition=cross(plusEMA, negEMA) and (plusEMA < negEMA), title="SELL ALERT", message="SELL ALERT") 69 | -------------------------------------------------------------------------------- /hash_ribbon.pine: -------------------------------------------------------------------------------- 1 | //@version=4 2 | study("Hash Ribbons",overlay= false) 3 | 4 | // NOTES 5 | 6 | // The "Spring" is the confirmed Miner capitulation period: 7 | // - The 1st "gray" circle is the start of Capitulation (1 month Hash Rate crosses UNDER 2 month Hash Rate) 8 | // - Last "green" circle is the end of Capitulation (1 month Hash Rate crosses OVER 2 month Hash Rate) 9 | // - The "greener" the spring gets (up until blue) represents Hash Rate recovery (it is increasing) 10 | // - The "blue" circle is the first instance of positive momentum following recovery of Hash Rate (1m HR > 2m HR). This is historically a rewarding place to buy with limited downside. 11 | 12 | // INPUTS 13 | 14 | type = input('Ribbons',options=['Ribbons','Oscillator'],title="Plot Type") 15 | len_s = input(30,"Hash Rate Short SMA (days).") 16 | len_l = input(60,"Hash Rate Long SMA (days).") 17 | signals = input(true, "Plot Signals") 18 | plot_halvings = input(true,"Plot Halvings") 19 | raw = input(false, "Plot Raw Hash Rate") 20 | 21 | // HASH RATE MA 22 | 23 | // HR on TV only has "yesterday's" value --> use "lookahead_on" when running live (on current bar), to pull forward yesterdays data 24 | live_HR_raw = security("QUANDL:BCHAIN/HRATE", "D", close,gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) 25 | live_HR_short = security("QUANDL:BCHAIN/HRATE", "D", sma(close,len_s),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) 26 | live_HR_long = security("QUANDL:BCHAIN/HRATE", "D", sma(close,len_l),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) 27 | 28 | hist_HR_raw = security("QUANDL:BCHAIN/HRATE", "D", close,gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) 29 | hist_HR_short = security("QUANDL:BCHAIN/HRATE", "D", sma(close,len_s),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) 30 | hist_HR_long = security("QUANDL:BCHAIN/HRATE", "D", sma(close,len_l),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) 31 | 32 | daily_s10 = security(syminfo.tickerid, "D", sma(close,10),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) 33 | daily_s20 = security(syminfo.tickerid, "D", sma(close,20),gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off) 34 | 35 | 36 | // DAILY TIMEFRAME MGMT 37 | 38 | is_newbar(res) => 39 | t = time(res) // res calculated below \/ 40 | change(t) != 0 ? true : false 41 | 42 | // Check how many bars are in our upper (otf) timeframe 43 | since_new_bar = barssince(is_newbar("D")) //1-360 for minutes, D = Daily, W = Weekly, M = Monthly 44 | D_total_bars = int(na) 45 | D_total_bars := since_new_bar == 0 ? since_new_bar[1] : D_total_bars[1] // calculates the total number of current time frame bars in the OTF 46 | 47 | // INDICATORS 48 | 49 | HR_short = float(na) 50 | HR_long = float(na) 51 | HR_raw = float(na) 52 | s10 = float(na) 53 | s20 = float(na) 54 | 55 | HR_short := barstate.isrealtime ? live_HR_short : hist_HR_short 56 | HR_long := barstate.isrealtime ? live_HR_long : hist_HR_long 57 | HR_raw := barstate.isrealtime ? live_HR_raw : hist_HR_raw 58 | 59 | s10 := barstate.isrealtime ? (since_new_bar == D_total_bars ? daily_s10 : s10[1]) : daily_s10 60 | s20 := barstate.isrealtime ? (since_new_bar == D_total_bars ? daily_s20 : s20[1]) : daily_s20 61 | 62 | capitulation = crossunder(HR_short,HR_long) 63 | miner_capitulation = HR_short HR_short[1] and HR_short > HR_short[2] and HR_short > HR_short[3] and miner_capitulation 65 | recovered = crossover(HR_short,HR_long) 66 | 67 | // HASH BOTTOM + PA SIGNAL 68 | 69 | buy = false 70 | buy := ( 71 | (crossover(s10,s20) and barssince(recovered) < barssince(crossunder(s10,s20)) and barssince(recovered) < barssince(capitulation)) 72 | or 73 | (s10>s20 and crossover(HR_short,HR_long)) 74 | ) 75 | 76 | buy_plot = buy 77 | 78 | 79 | // OSCILLATOR 80 | 81 | delta = HR_short-HR_long 82 | diff = (delta/HR_short)*100 83 | 84 | // PLOT - DEFAULT 85 | 86 | plot(raw ? HR_raw : na, color = color.green, linewidth = 1, style = plot.style_line, title='HR Raw') 87 | p1=plot(type=='Ribbons'? HR_long : na, color = color.gray, linewidth = 2, style = plot.style_line,title='HR SMA Long') 88 | p2=plot(type=='Ribbons'? HR_short : na, color = (HR_short= halving_1 - band*(24*60*60*1000) and time <= halving_1 + band*(24*60*60*1000) //adds 3 day either side for chart visibility 110 | h2_range = time >= halving_2 - band*(24*60*60*1000) and time <= halving_2 + band*(24*60*60*1000) //adds 3 day either side for chart visibility 111 | h3_range = time >= halving_3 - band*(24*60*60*1000) and time <= halving_3 + band*(24*60*60*1000) //adds 3 day either side for chart visibility 112 | bgcolor(h1_range and plot_halvings? color.red : na, transp = 20) 113 | bgcolor(h2_range and plot_halvings? color.red : na, transp = 20) 114 | bgcolor(h3_range and plot_halvings? color.red : na, transp = 20) 115 | 116 | //ALERTS 117 | 118 | alertcondition(capitulation, title='Alert - Capitulation') 119 | alertcondition(recovered, title='Alert - Recovered') 120 | alertcondition(buy and not(buy[1]), title='Alert - Buy') -------------------------------------------------------------------------------- /tradingview-strategy-backtester-boilerplate.pine: -------------------------------------------------------------------------------- 1 | //@version=3 2 | // TODO: update strategy name 3 | strategy("{STRATEGY NAME}", overlay=true) 4 | 5 | // === TA LOGIC === 6 | 7 | // 8 | // 9 | // TODO: PUT YOUR TA LOGIC HERE 10 | LONG_SIGNAL_BOOLEAN = crossover(sma(close, 13), sma(close, 34)) 11 | SHORT_SIGNAL_BOOLEAN = crossunder(sma(close, 12), sma(close, 21)) 12 | 13 | // === INPUT BACKTEST DATE RANGE === 14 | strategyType = input(defval="Long Only", options=["Long & Short", "Long Only", "Short Only"]) 15 | enableShorts = input(false, title="Enable short entries?") 16 | 17 | FromMonth = input(defval = 5, title = "From Month", minval = 1, maxval = 12) 18 | FromDay = input(defval = 18, title = "From Day", minval = 1, maxval = 31) 19 | FromYear = input(defval = 2018, title = "From Year", minval = 2017) 20 | ToMonth = input(defval = 9, title = "To Month", minval = 1, maxval = 12) 21 | ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31) 22 | ToYear = input(defval = 2018, title = "To Year", minval = 2017) 23 | 24 | start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window 25 | finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window 26 | window() => time >= start and time <= finish ? true : false // create function "within window of time" 27 | 28 | // === STRATEGY BUY / SELL ENTRIES === 29 | 30 | // TODO: update the placeholder LONG_SIGNAL_BOOLEAN and SHORT_SIGNAL_BOOLEAN to signal 31 | // long and short entries 32 | buy() => window() and LONG_SIGNAL_BOOLEAN 33 | sell() => window() and SHORT_SIGNAL_BOOLEAN 34 | 35 | if buy() 36 | if (strategyType == "Short Only") 37 | strategy.close("Short") 38 | else 39 | strategy.entry("Long", strategy.long, comment="Long") 40 | 41 | if sell() 42 | if (strategyType == "Long Only") 43 | strategy.close("Long") 44 | else 45 | strategy.entry("Short", strategy.short, comment="Short") 46 | 47 | 48 | // === BACKTESTING: EXIT strategy === 49 | sl_inp = input(10, title='Stop Loss %', type=float)/100 50 | tp_inp = input(30, title='Take Profit %', type=float)/100 51 | 52 | stop_level = strategy.position_avg_price * (1 - sl_inp) 53 | take_level = strategy.position_avg_price * (1 + tp_inp) 54 | 55 | strategy.exit("Stop Loss/Profit", "Long", stop=stop_level, limit=take_level) --------------------------------------------------------------------------------