Pine Script v5 · Strategy
-NoSKi Hammer-Star -w angle of ema Backtester -
A Pine Script v5 strategy built on ATR (14), EMA (close, 20) and SMA (slope, 20). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.075% commission. 24 settings; defaults include From Month 1, From Day 9 and From Year 2019.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does -NoSKi Hammer-Star -w angle of ema Backtester - repaint?
- No
- No repainting patterns were found in the source.
- Does -NoSKi Hammer-Star -w angle of ema Backtester - run in Pine Script v6?
- Not tested
- The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L7:C0: no source was supplied for the library 'ZenAndTheArtOfTrading/ZenLibrary/5'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download.
- Does -NoSKi Hammer-Star -w angle of ema Backtester - use a stop loss?
- Yes
- strategy.exit sets a stop on line 118, 119.
- Does -NoSKi Hammer-Star -w angle of ema Backtester - run in Zeal Terminal?
- No
- Not yet: it imports the library ZenAndTheArtOfTrading/ZenLibrary/5, whose source is not available here, so it does not run here
Review
What a careful reader of this script would point out, found by checking the source.
-
Check
2 settings do nothing
“Source”, “Show Negative Slope Zone” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 116, 117, 118, 119. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| From Month | 1 | int · min 1 · max 12 | start |
| From Day | 9 | int · min 1 · max 31 | start |
| From Year | 2019 | int · min 2018 | start |
| To Month | 1 | int · min 1 · max 12 | finish |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Year | 9999 | int · min 2017 | finish |
| Take Profit/Stop Loss Settings | |||
| Take Profit % | 14 | int | inpTakeProfit |
| Stop Loss % | 2 | int | inpStopLoss |
| Order Sizing | |||
| One Position at a time | true | bool | order1 |
| Hammer and Stars | |||
| Fib Level | 0.333 | float | bullFib bearFib |
| Color Filter | false | bool | hammerCandle starCandle |
| ATR Filter | 0.1 | float | atrFilterCheck |
| Angle of EMA | |||
| Source | close | source | unused |
| Guides Position | 45 | float | emapos bgcolor |
| Guides Position | -45 | int | emaneg bgcolor |
| Price To Bar Ratio | 20.0 | float | price2bar_ratio |
| Threshold | 1.0 | float | rise |
| Show Negative Slope Zone | true | bool | unused |
| Average angle over how many bars | 20 | int | sma |
| EMA | |||
| EMA length | 20 | int | ema |
| High/Low Filter | |||
| Swing High/Low LookbackHow many bars to look back for swing high/low | 10 | int | swingHighFilter swingLowFilter |
| Use Swing High/Low Filter?Turns on/off the swing high/low filter | false | bool | swingHighFilter swingLowFilter |
| Entry Candle ATR Size | |||
| >= ATR FilterMinimum size of entry candle compared to ATR | 0.0 | float · min 0.0 | atrMinFilter |
| <= ATR FilterMaximum size of entry candle compared to ATR | 3.0 | float · min 0.0 | atrMaxFilter |
What it calculates
- ATR14
atr · line 56 - EMAclose, EMA length (20)
ema · line 74 - SMAslope, Average angle over how many bars (20)
sma · line 85
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | buy and window() | On | 116 |
| Open Short short | sell and window() | On | 117 |
| Exit Long Exit stop and limit | strategy.position_size > 0 | On | 118 |
| Exit Short Exit stop and limit | strategy.position_size < 0 | On | 119 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source.
The live replay needs a run, and this script does not run in Zeal Terminal yet; the answer comes from the checks on the source alone.
- ClearHigher-timeframe data1 request.security call(s), none with lookahead on.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| ATR + STC + MA by Romedius | ema lowest highest atr sma | v5 strategy | −1.2% | 15 | 3.3% |
| LONG SAZB $ by stevenz17 | ema sma atr lowest highest | v4 strategy | No trades on this market | ||
| MACD Strategy by maxencetajet | atr highest lowest ema sma | v5 strategy | +5.8% | 5 | 6.9% |
| DC Breakout Strategy - This is simplicity at its finest. by Robrecht99 | sma highest lowest atr | v5 strategy | +10.8% | 57 | 8.3% |
| Richard's Strategy by Deepak8369 | highest lowest atr ema | v4 strategy | +34.6% | 70 | 26.3% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 4 strategy calls use the when = argument (line 116, 117, 118, 119). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 6 settings use the untyped input() (line 33, 35, 37, 38, 39, 40). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L7:C0: no source was supplied for the library 'ZenAndTheArtOfTrading/ZenLibrary/5'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked.
- Line 33: input() → input.source()
- Line 35: input() → input.int()
- Line 37: input() → input.float()
- Line 38: input() → input.float()
- Line 39: input() → input.bool()
- Line 40: input() → input.int()
4 more edits
- Line 116: when = buy and window() → if block
- Line 117: when = sell and window() → if block
- Line 118: when = strategy.position_size > 0 → if block
- Line 119: when = strategy.position_size < 0 → if block
⋯//angle inputs-src = input(title='Source', defval=close, group="Angle of EMA")+src = input.source(title='Source', defval=close, group="Angle of EMA")guide_pos = input.float(title='Guides Position', defval=45, group="Angle of EMA")-guide_neg = input(title='Guides Position', defval=-45, group="Angle of EMA")+guide_neg = input.int(title='Guides Position', defval=-45, group="Angle of EMA")//price2bar_ratio = input(title='Price To Bar Ratio', defval=20.0, group="Angle of EMA") // Should be the same as that of the Chart-p2br = input(title='Price To Bar Ratio', defval=20.0, group="Angle of EMA") // Should be the same as that of the Chart+p2br = input.float(title='Price To Bar Ratio', defval=20.0, group="Angle of EMA") // Should be the same as that of the Chart-threshold = input(title='Threshold', defval=1.0, group="Angle of EMA")+threshold = input.float(title='Threshold', defval=1.0, group="Angle of EMA")-show_bg = input(title='Show Negative Slope Zone', defval=true, group="Angle of EMA")+show_bg = input.bool(title='Show Negative Slope Zone', defval=true, group="Angle of EMA")-smal = input(title='Average angle over how many bars', defval=20, group="Angle of EMA")+smal = input.int(title='Average angle over how many bars', defval=20, group="Angle of EMA")emafilter = input.int(title="EMA length", defval=20, group= "EMA")⋯plot(ema, title="EMA", color=color.yellow, linewidth=2)-strategy.entry("Long", direction= strategy.long, when= buy and window())+if buy and window()+ strategy.entry("Long", direction= strategy.long)-strategy.entry("Short", direction= strategy.short, when= sell and window())+if sell and window()+ strategy.entry("Short", direction= strategy.short)-strategy.exit("Long Exit", from_entry="Long", when=strategy.position_size > 0, limit = inpTakeProfit, stop = inpStopLoss)+if strategy.position_size > 0+ strategy.exit("Long Exit", from_entry="Long", limit = inpTakeProfit, stop = inpStopLoss)-strategy.exit("Short Exit", from_entry="Short", when=strategy.position_size < 0, limit = inpTakeProfit, stop = inpStopLoss)+if strategy.position_size < 0+ strategy.exit("Short Exit", from_entry="Short", limit = inpTakeProfit, stop = inpStopLoss)Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L7:C0: no source was supplied for the library 'ZenAndTheArtOfTrading/ZenLibrary/5'. Libraries cannot be fetched from TradingView; supply the source in the 'libraries' option. No libraries were supplied.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © noski1-//@version=5+//@version=6strategy(title='"NoSKi Hammer Star Backtester %', shorttitle='Noski HnS BT %', overlay=true, ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | No It imports the library ZenAndTheArtOfTrading/ZenLibrary/5, whose source is not available here, so it does not run here | Not measured | |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 116, 117) so the engine trades the way the script says.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © noski1//@version=5strategy(title='"NoSKi Hammer Star Backtester %', shorttitle='Noski HnS BT %', overlay=true, commission_type=strategy.commission.percent, commission_value=0.075, initial_capital = 10000, currency=currency.USD, default_qty_type= strategy.percent_of_equity, default_qty_value=100)// Import Zen libraryimport ZenAndTheArtOfTrading/ZenLibrary/5 as zen// --------------------------------------------------------------------------------//------- Inputs--------//// --------------------------------------------------------------------------------//Time PeriodFromMonth = input.int(defval=1, title='From Month', minval=1, maxval=12)FromDay = input.int(defval=9, title='From Day', minval=1, maxval=31)FromYear = input.int(defval=2019, title='From Year', minval=2018)ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)ToYear = input.int(defval=9999, title='To Year', minval=2017)start = timestamp(FromYear, FromMonth, FromDay, 00, 00)finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)window() => time >= start and time <= finish ? true : false // Take Profit SL inputstp_inp = input.int(14, title='Take Profit %', group = "Take Profit/Stop Loss Settings")/100 //input.int(defval = 1, title = "Take Profit %", minval = 1)/100sl_inp = input.int(2, title='Stop Loss %', group = "Take Profit/Stop Loss Settings")/100 //input.int(defval = 1, title = "Stop Loss %", minval = 1)/100 //Once order at a timeorder = input.bool(title="One Position at a time", defval=true, group="Order Sizing")//Hammer and star inputsfibLevel = input.float(title="Fib Level", defval=0.333, group="Hammer and Stars")colorFilter = input.bool(title="Color Filter", defval=false, group="Hammer and Stars")aatrFilter = input.float(title="ATR Filter", defval=0.1, group="Hammer and Stars")//angle inputssrc = input(title='Source', defval=close, group="Angle of EMA")guide_pos = input.float(title='Guides Position', defval=45, group="Angle of EMA")guide_neg = input(title='Guides Position', defval=-45, group="Angle of EMA")//price2bar_ratio = input(title='Price To Bar Ratio', defval=20.0, group="Angle of EMA") // Should be the same as that of the Chartp2br = input(title='Price To Bar Ratio', defval=20.0, group="Angle of EMA") // Should be the same as that of the Chartthreshold = input(title='Threshold', defval=1.0, group="Angle of EMA")show_bg = input(title='Show Negative Slope Zone', defval=true, group="Angle of EMA")smal = input(title='Average angle over how many bars', defval=20, group="Angle of EMA")emafilter = input.int(title="EMA length", defval=20, group= "EMA")//Swing High/Low filtervar g_hl = "High/Low Filter"lookback = input.int(title="Swing High/Low Lookback", defval=10, tooltip="How many bars to look back for swing high/low", group=g_hl)useHlFilter = input.bool(title="Use Swing High/Low Filter?", defval=false, tooltip="Turns on/off the swing high/low filter", group=g_hl)// Filter Settingsvar g_filter = "Entry Candle ATR Size"atrMinFilterSize = input.float(title=">= ATR Filter", defval=0.0, minval=0.0, group=g_filter, tooltip="Minimum size of entry candle compared to ATR")atrMaxFilterSize = input.float(title="<= ATR Filter", defval=3.0, minval=0.0, group=g_filter, tooltip="Maximum size of entry candle compared to ATR")//emaFilter = input.int(title="EMA Filter", defval=0, group=g_filter, tooltip="EMA length to filter trades - set to zero to disable")price2bar_ratio = request.security(syminfo.tickerid, "D", close) * 0.000025 * p2br// --------------------------------------------------------------------------------// Hammer and Candles// --------------------------------------------------------------------------------// Check our ATR filteratr = ta.atr(14)candleSize = high - lowatrFilterCheck = candleSize >= atr * aatrFilter// Calculate fibonacci level for current candlebullFib = (low - high) * fibLevel + highbearFib = (high - low) * fibLevel + low// Determine which price source closes or opens highest/lowestlowestBody = close < open ? close : openhighestBody = close > open ? close : open// Determine if we have a valid hammer or shooting star candlehammerCandle = lowestBody >= bullFib and (not colorFilter or close > open) and atrFilterCheckstarCandle = highestBody <= bearFib and (not colorFilter or close < open) and atrFilterCheck// Get swing high/low filterswingHighFilter = not useHlFilter or (high == ta.highest(high, lookback) or high[1] == ta.highest(high, lookback))swingLowFilter = not useHlFilter or (low == ta.lowest(low, lookback) or low[1] == ta.lowest(low, lookback))// --------------------------------------------------------------------------------// EMA Angle Functions// --------------------------------------------------------------------------------ema = ta.ema(close, emafilter)get_slope(ema, price2bar_ratio) => 180.0 / (2 * math.asin(1)) * math.atan(ta.change(ema) / price2bar_ratio)// Logicslope = get_slope(ema, price2bar_ratio)rise = falserise := slope - slope[1] > threshold ? true : slope - slope[1] < -threshold ? false : nz(rise[1])prefall = falseprefall := not rise or slope - slope[1] > 0 ? false : rise and slope - slope[1] < 0 ? true : nz(prefall[1])prerise = falseprerise := rise or slope - slope[1] < 0 ? false : not rise and slope - slope[1] > 0 ? true : nz(prerise[1])sma = ta.sma(slope, smal)// Angle Buy Sell Filteremapos = sma > guide_posemaneg = sma < guide_neg// --------------------------------------------------------------------------------// ATR Settings// --------------------------------------------------------------------------------// Check ATR filteratrMinFilter = high - low >= (atrMinFilterSize * atr) or atrMinFilterSize == 0.0atrMaxFilter = high - low <= (atrMaxFilterSize * atr) or atrMaxFilterSize == 0.0atrFilter = atrMinFilter and atrMaxFilter and not na(atr)var int inTrade = 0order1 = not order or inTrade ==0 // --------------------------------------------------------------------------------// Combined Buy and Sell signals// --------------------------------------------------------------------------------buy = hammerCandle and emapos and atrFilter and swingLowFilter and barstate.isconfirmed and order1// inTrade == 0sell = starCandle and emaneg and atrFilter and swingHighFilter and barstate.isconfirmed and order1//inTrade == 0inpStopLoss = strategy.position_avg_price * (1 - sl_inp)inpTakeProfit = strategy.position_avg_price * (1 + tp_inp)if strategy.position_size < 0 inpStopLoss := strategy.position_avg_price * (1 + sl_inp) inpTakeProfit := strategy.position_avg_price * (1 - tp_inp) // --------------------------------------------------------------------------------// View// --------------------------------------------------------------------------------plotshape(buy, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), text = "Long", title='Long', textcolor = color.green)plotshape(sell, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), text = "Short", title='Short', textcolor = color.red)bgcolor(sma > guide_pos ? color.new(color.green, 85) : na) // highlighting bg when ema angle > 45bgcolor(sma < guide_neg ? color.new(color.red, 85) : na)plot(ema, title="EMA", color=color.yellow, linewidth=2)strategy.entry("Long", direction= strategy.long, when= buy and window())strategy.entry("Short", direction= strategy.short, when= sell and window())strategy.exit("Long Exit", from_entry="Long", when=strategy.position_size > 0, limit = inpTakeProfit, stop = inpStopLoss)strategy.exit("Short Exit", from_entry="Short", when=strategy.position_size < 0, limit = inpTakeProfit, stop = inpStopLoss)