JayRogers

Simple Horizontal Value and Offsets [Auto Shift]

Original (Simple Horizontal Value and Offsets/SHV) Requested by @TAFA94

Description:
  • Simple adjustable incremented horizontal offset lines extending up and down from a Median point.
  • Set full value for manual Median point control, or set an incremental rounding value for auto Median adjustment.
  • Source and look-back period inputs for fine tuning auto adjust.
  • Auto adjust on by default - can be toggled off for straight manual control.

**NOTE**
  • All values will likely need to be changed immediately on applying this script, in order to properly fit your charts specific price/value range and/or time resolution.

Cheers!
סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?
//@version=2

study(title="Simple Horizontal Value and Offsets [Auto Shift]", shorttitle="SHV_AS", overlay=true)

// Revision:    1
// Author:      JayRogers
//
// Description:
//  - Original (Simple Horizontal Value and Offsets/SHV) Requested by @TAFA94
//  - Simple horizontal values extending up and down from a median value.
//  - Set Median Value, and set offset values. Simples.
//
// r2 Changes/Description:
//  - Source Look-Back and rounding for automatically adjusting median point to closest specified value
//  - True/False toggle for lookback in case you want to keep it all manual.

// - INPUTS START
manualMed   = input(defval=1.09,    title="Manual Median Value [Full]")
offsetVal   = input(defval=0.0025,  title="Offset Value [+/- line increments]")
autoMed     = input(defval=true,    title="Auto adjust Median based on Look-Back Period?")
autoRnd     = input(defval=0.005,   title="Auto Median Rounding Value [Incremental]")
autoSrc     = input(defval=open,    title="Look-Back Rounding Source")
autoLen     = input(defval=60,      title="Look-Back Period") 
// - INPUTS END

// - FUNCTIONS START
// Get the rounded median point
medianRound() => round((sum(autoSrc, autoLen) / autoLen) / autoRnd) * autoRnd
// Offset multiplier function.
offsetMult(num) => num * offsetVal
// Are we auto adjusting the median?
getMedian() => autoMed ? medianRound() : manualMed
// - FUNCTIONS END

// - PLOTTING START
// Style variables for quicker edits
lc  = aqua      // color basis
sto = circles   // odd line style
ste = circles   // even line style
tro = 50        // odd line transparency
tre = 25        // even line transparency
// Median line
midline = plot(getMedian(), title="Median Line", color=lc, style=line, linewidth=2, transp=30)
// Upward offsets
plus1   = plot(getMedian() + offsetMult(1), title="Plus 1", color=lc, style=sto, transp=tro)
plus2   = plot(getMedian() + offsetMult(2), title="Plus 2", color=lc, style=ste, transp=tre)
plus3   = plot(getMedian() + offsetMult(3), title="Plus 3", color=lc, style=sto, transp=tro)
plus4   = plot(getMedian() + offsetMult(4), title="Plus 4", color=lc, style=ste, transp=tre)
plus5   = plot(getMedian() + offsetMult(5), title="Plus 5", color=lc, style=sto, transp=tro)
plus6   = plot(getMedian() + offsetMult(6), title="Plus 6", color=lc, style=ste, transp=tre)
plus7   = plot(getMedian() + offsetMult(7), title="Plus 7", color=lc, style=sto, transp=tro)
plus8   = plot(getMedian() + offsetMult(8), title="Plus 8", color=lc, style=ste, transp=tre)
plus9   = plot(getMedian() + offsetMult(9), title="Plus 9", color=lc, style=sto, transp=tro)
plus10  = plot(getMedian() + offsetMult(10), title="Plus 10", color=lc, style=ste, transp=tre)
// Downward offsets
minus1  = plot(getMedian() - offsetMult(1), title="minus 1", color=lc, style=sto, transp=tro)
minus2  = plot(getMedian() - offsetMult(2), title="minus 2", color=lc, style=ste, transp=tre)
minus3  = plot(getMedian() - offsetMult(3), title="minus 3", color=lc, style=sto, transp=tro)
minus4  = plot(getMedian() - offsetMult(4), title="minus 4", color=lc, style=ste, transp=tre)
minus5  = plot(getMedian() - offsetMult(5), title="minus 5", color=lc, style=sto, transp=tro)
minus6  = plot(getMedian() - offsetMult(6), title="minus 6", color=lc, style=ste, transp=tre)
minus7  = plot(getMedian() - offsetMult(7), title="minus 7", color=lc, style=sto, transp=tro)
minus8  = plot(getMedian() - offsetMult(8), title="minus 8", color=lc, style=ste, transp=tre)
minus9  = plot(getMedian() - offsetMult(9), title="minus 9", color=lc, style=sto, transp=tro)
minus10 = plot(getMedian() - offsetMult(10), title="minus 10", color=lc, style=ste, transp=tre)
// - PLOTTING END