Zeal Terminal Open Zeal Terminal

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
Does not run in Zeal Terminal yetIt imports the library ZenAndTheArtOfTrading/ZenLibrary/5, whose source is not available here, so it does not run here. The settings, logic and review below are read from the source, which does not need a run.

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.

SettingDefaultType and rangeFeeds
From Month1int · min 1 · max 12start
From Day9int · min 1 · max 31start
From Year2019int · min 2018start
To Month1int · min 1 · max 12finish
To Day1int · min 1 · max 31finish
To Year9999int · min 2017finish
Take Profit/Stop Loss Settings
Take Profit %14intinpTakeProfit
Stop Loss %2intinpStopLoss
Order Sizing
One Position at a timetrueboolorder1
Hammer and Stars
Fib Level0.333floatbullFib bearFib
Color FilterfalseboolhammerCandle starCandle
ATR Filter0.1floatatrFilterCheck
Angle of EMA
Sourceclosesourceunused
Guides Position45floatemapos bgcolor
Guides Position-45intemaneg bgcolor
Price To Bar Ratio20.0floatprice2bar_ratio
Threshold1.0floatrise
Show Negative Slope Zonetrueboolunused
Average angle over how many bars20intsma
EMA
EMA length20intema
High/Low Filter
Swing High/Low LookbackHow many bars to look back for swing high/low10intswingHighFilter swingLowFilter
Use Swing High/Low Filter?Turns on/off the swing high/low filterfalseboolswingHighFilter swingLowFilter
Entry Candle ATR Size
>= ATR FilterMinimum size of entry candle compared to ATR0.0float · min 0.0atrMinFilter
<= ATR FilterMaximum size of entry candle compared to ATR3.0float · min 0.0atrMaxFilter

What it calculates

  • ATR14atr · 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.

high · low · closehigh · low · closeprice dataclosecloseprice dataemafilterEMA lengthsetting · 20smalAverage angle over how …setting · 20FromYearFrom Yearsetting · 2019FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 9ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1p2brPrice To Bar Ratiosetting · 20.0lowlowprice datahighhighprice datafibLevelFib Levelsetting · 0.333openopenprice datathresholdThresholdsetting · 1.0sl_inpStop Loss %setting · 2tp_inpTake Profit %setting · 14aatrFilterATR Filtersetting · 0.1lookbackSwing High/Low Lookbacksetting · 10guide_posGuides Positionsetting · 45guide_negGuides Positionsetting · -45atrMinFilterSize>= ATR Filtersetting · 0.0atrMaxFilterSize<= ATR Filtersetting · 3.0atrATR→ atremaEMA→ emasmaSMA→ smastartstartvaluefinishfinishvalueprice2bar_ratioprice2bar_ratiovaluecandleSizecandleSizevaluebullFib, bearFibbullFib · bearFib2 valueslowestBody, highestBodylowestBody · highestBody2 valuesslopeslopevalueriserisevalueprefallprefallvaluepreriseprerisevalueinpStopLossinpStopLossvalueinpTakeProfitinpTakeProfitvalueatrFilterCheckatrFilterCheckconditionhammerCandle, starCandlehammerCandle · starCand…2 conditionsswingHighFilterswingHighFilterconditionswingLowFilterswingLowFilterconditionemaposemaposconditionemanegemanegconditionatrMinFilteratrMinFilterconditionatrMaxFilteratrMaxFilterconditionatrFilteratrFilterconditionorder1order1conditionbuybuyconditionsellsellconditionentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long Exitexit Long Exitstrategy.exitexit:Short Exitexit Short Exitstrategy.exitplotshape:111Longplotshapeplotshape:112Shortplotshapebgcolor:113bgcolorbgcolorbgcolor:114bgcolorbgcolorplot:115EMAplot

Order rules

OrderFires whenBy defaultLine
Open Long longbuy and window()On116
Open Short shortsell and window()On117
Exit Long Exit stop and limitstrategy.position_size > 0On118
Exit Short Exit stop and limitstrategy.position_size < 0On119

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.

ScriptSharesTypeNetTradesMax drawdown
ATR + STC + MA by Romediusema lowest highest atr smav5 strategy−1.2%153.3%
LONG SAZB $ by stevenz17ema sma atr lowest highestv4 strategyNo trades on this market
MACD Strategy by maxencetajetatr highest lowest ema smav5 strategy+5.8%56.9%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%
Richard's Strategy by Deepak8369highest lowest atr emav4 strategy+34.6%7026.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 verified

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.

  • 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2No It imports the library ZenAndTheArtOfTrading/ZenLibrary/5, whose source is not available here, so it does not run hereNot measured
PineTSNot testedNot testedNot 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)