Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © alexgrover
- //@version=4
- study("Hull Estimate","HEMA",true)
- runEstimate = input(true, "Run HEMA instead of HMA")
- length = input(50)
- //----
- loopCount = input(400, "Loop iterations per bar")
- // —————————— ▼▼▼▼▼ Calculate run time of the script (insert this snippet after your "input()" calls).
- // Produces 3 values:
- // _totalTime = total elapsed time (ms)
- // _msPerBar = avg time per bar (ms)
- // _barsTimed = bars timed.
- // Get time at first bar.
- var _timeBegin = timenow
- // Get ms elapsed since first bar.
- var _timeElapsed = 0.
- if not barstate.islast
- _timeElapsed := timenow - _timeBegin
- // Calculate avg/bar only when time changes.
- var _msPerBar = 0.
- // Total bars timed before last change in "timenow".
- var _barsTimed = 0
- // ————— Bars elapsed since last change in "timenow".
- var _barsNotTimed = 0
- if change(_timeElapsed)
- _barsTimed := bar_index + 1
- _msPerBar := _timeElapsed / _barsTimed
- // ————— In between time changes, which only occur every second, estimate elapsed time using avg time per bar.
- if not barstate.islast
- // Bars elapsed since last change of time.
- _barsNotTimed := bar_index + 1 - _barsTimed
- // ————— Add (bars since "timenow" change * avg bar time) to time elapsed since last "timenow" change to get better estimate of total time elapsed.
- _totalTime = _timeElapsed + (_barsNotTimed * _msPerBar)
- // —————————— Display results in one of 3 modes (comment out those you don't need).
- _msPerBarColor = _msPerBar > 50 ? color.red : _msPerBar > 5 ? color.maroon : _msPerBar == 0 ? color.lime : color.green
- // ————— Mode 1: Print label at the end of chart.
- if barstate.islast
- var _label_text = tostring(_msPerBar, "Avg time per bar\n#.#### ms\n\n") + tostring(_totalTime / 1000, "Time elapsed\n#.#### seconds\n\n") + tostring(_barsTimed + _barsNotTimed, "Bars analyzed\n#")
- var label _timeLabel = label.new(bar_index, na, _label_text, xloc.bar_index, yloc.belowbar, style = label.style_none, textcolor = _msPerBarColor)
- label.set_xy(_timeLabel, bar_index, na)
- // ————— Mode 2: Plot elapsed time.
- plot(_totalTime, "Execution time (ms)", color.gray)
- // ————— Mode 3: Print Data Window values.
- plotchar(_msPerBar, "Avg time / bar (ms)", "", location.top, _msPerBarColor)
- plotchar(_totalTime, "Execution time (ms)", "", location.top)
- plotchar(_barsTimed, "Bars timed", "", location.top)
- // —————————— ▲▲▲▲▲
- // ——————————————————————————————————————————————————
- // ————— Your script code goes here.
- var a = 0.
- src = input(close)
- if runEstimate
- for i = 0 to loopCount
- a := a + (3*wma(src,length/2) - 2*ema(src,length/2))
- else
- for i = 0 to loopCount
- a := a + wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
- plot(a,"",#e91e63,2,transp=0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement