Strategy · Pine Script v4 · On the chart

BlackSwan Strategy

by hasnocool

This strategy detects large single-candle body expansions exceeding approximately 1.91% of price to enter momentum breakouts.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code53
Settings9inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Breakout, Moving averages, Trend

Markets

Crypto

Timeframes

M1-M5

Risk Notes

  • The strategy can add several entries in the same direction
  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Start Dateint1startDate
Start Monthint11startMonth
Start Yearint2018startYear
End Dateint1endDate
End Monthint11endMonth
End Yearint2031endYear
Key Vaule. 'This changes the sensitivity'int1a
ATR Periodint10c
Signals from Heikin Ashi Candlesboolfalseh
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.

Similar Pine Scripts

257 stars

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

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

均线突破交易系统

by tangly1024
76 stars

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

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
43 stars

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-

Strategy v5 TrendBreakout Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m - Strategy Candle Bar

ADA4H Optuna Strategy

by skywalker0803r
42 stars

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

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy
16 stars

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

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers