1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
53 lines of Pine Script v4 from BlackSwan strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
BlackSwan strategy.pine
//@version=4
//适合1分钟-3分钟的k线,发生波动超过百分之二时,自动报警
strategy("BlackSwan strategy", overlay=true,
initial_capital=10000, currency='USD', default_qty_type=strategy.percent_of_equity,
default_qty_value=100, commission_type= strategy.commission.percent, commission_value=0.075,pyramiding=3)
//-------------------------------------------
//-------------------------------------------
timecondition = timeframe.period =="480" or timeframe.period =="240" or timeframe.period =="D" or timeframe.period =="720"
// Make input options that configure backtest date range
startDate = input(title="Start Date", type=input.integer,
defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", type=input.integer,
defval=11, minval=1, maxval=12)
startYear = input(title="Start Year", type=input.integer,
defval=2018, minval=1800, maxval=2100)
endDate = input(title="End Date", type=input.integer,
defval=1, minval=1, maxval=31)
endMonth = input(title="End Month", type=input.integer,
defval=11, minval=1, maxval=12)
endYear = input(title="End Year", type=input.integer,
defval=2031, minval=1800, maxval=2100)
// Look if the close time of the current bar
// falls inside the date range
inDateRange = (time >= timestamp(syminfo.timezone, startYear,
startMonth, startDate, 0, 0)) and
(time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
// Inputs
a = input(1, title = "Key Vaule. 'This changes the sensitivity'")
c = input(10, title = "ATR Period")
h = input(false, title = "Signals from Heikin Ashi Candles")
ma60 = sma(close,60)
ema144 = ema(close,144)
ema169 = ema(close,169)
ma20=sma(close,20)
plot(ema144,color=color.yellow, title="144")
plot(ema169,color=color.orange, title="169")
heitiane=(close-open)
heitiane:=abs(heitiane)
heitiane:=heitiane/close
if (inDateRange and heitiane >0.0191 and close<open) // and close>f3
strategy.entry("botsell20", strategy.short, comment = "黑天鹅追空"+tostring(heitiane))
if(crossover(ema144,ema169))
strategy.close("botsell20", comment = "平空")
if (inDateRange and heitiane >0.0191 and close>open) // and close>f3
strategy.entry("botbuy20", strategy.long, comment = "白天鹅追多"+tostring(heitiane))
if(crossunder(ema144,ema169))
strategy.close("botbuy20", comment = "平多")
Expand (64 lines)
Overview
BlackSwan Strategy enters long positions on large bullish candles and short positions on large bearish candles. Positions are closed when the 144-period exponential moving average crosses the 169-period EMA. The script draws both EMAs directly on the price chart and allows configurable backtest date filters. Pyramiding is enabled up to three entries, and the strategy relies entirely on EMA crosses for exits without defined stop-loss orders.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Start Date
int
1
startDate
Start Month
int
11
startMonth
Start Year
int
2018
startYear
End Date
int
1
endDate
End Month
int
11
endMonth
End Year
int
2031
endYear
Key Vaule. 'This changes the sensitivity'
int
1
a
ATR Period
int
10
c
Signals from Heikin Ashi Candles
bool
false
h
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-
This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian
This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr
This strategy trades Nikkei 225 futures during a configurable overnight session, defaulting to 19:00–03:00 ET. It builds long and short trend conditions from an 8/21 EMA pair and a 200-period SMA, with RSI, momentum, an ATR-scaled breakout range, and a volume