Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study(title = "Sweetspot Gold R4-RN - by JustUncleL", shorttitle = "SWSPOT R4-RN", overlay = true, precision=5)
- // Original Author: @JustUncleL
- // Revision: R4
- // Date: 22-Dec-2016
- //
- //
- // Description:
- // - This revision upgrades "Sweetspot Gold R3"
- // - This works well for all currency pairs I've tested, most commodities, and most stocks.
- // - The indicator plots the so called "round price levels" or "00" levels, which end on 00, 50, 25 etc.
- // For example, 1.4000, 1.4400, 1.4450.
- // - It automatically calculates the levels for each chart time frame and sublevels. Or can manually
- // select main level size (in pips)
- // - Use this indicator as a guidance to a better mapping of Support/Resistance levels on the chart.
- // Next time you draw Support/Resistance lines, if they coincide with round price levels, especially "00",
- // you have got a excellent S/R level to work with!
- //
- // === REVISIONS ===
- //
- // Revision R4-RN:
- // - RN version created to implement one Main level plotting, typically used in Higher Time charts.
- // - Lowered limits on Manual levels to 1pip, this helps with exotics and non-currency charts.
- // Revision R4:
- // - Modified code to improve Automatic mode calculations, so now works better with exotic pairs,
- // Commodities, Indices and Stocks.
- // - Modified some Automatic level and sublevel selections.
- // Revision R3:
- // - Added number of sub levels, both auto and manual options.
- // - Automaically calculate grid size based on chart resolution and asset.
- // - This revision replaces "Sweetspot Gold2", "Sweetspot Gold4" and "Sweetspot Gold10"
- //
- // Revision R2:
- // - Fixed bug with displaying commodities
- //
- //
- // === INPUTS ===
- uAuto = input(true,title="Use Automatic Levels")
- swLevel_ = input(defval = 100,title = "Sweetspot Levels - Pips", minval=1,step=1) * 10
- avgLen_ = input(100, minval=1, title = "Average Level, Period Length (Used to centre Drawing)")
- // === /INPUTS ===
- // === FUNCTIONS ===
- // Function to find number of digits in an integer number, thanks to RS.
- f_int_n_digits(_input_value)=>
- _value = abs(_input_value)
- _n_digits = 0
- if _value > 0
- _n_digits := 1
- if _value >= 10
- _n_digits := 2
- if _value >= 100
- _n_digits := 3
- if _value >= 1000
- _n_digits := 4
- if _value >= 10000
- _n_digits := 5
- if _value >= 100000
- _n_digits := 6
- if _value >= 1000000
- _n_digits := 7
- if _value >= 10000000
- _n_digits := 8
- if _value >= 100000000
- _n_digits := 9
- if _value >= 1000000000
- _n_digits := 10
- _return = _n_digits
- // === /FUNCTIONS ===
- // === CONSTANTS and SERIES ===
- // Select Levels and Sub-Levels based on Time frame.
- swLevel = not uAuto? swLevel_ : ismonthly ? 10000 : isweekly ? 10000 : isdaily ? 5000 : isintraday ? interval>=240 ? 5000 : interval>=1 ? 1000 : 1000 :1000
- avgLen = not uAuto? avgLen_ : ismonthly ? 100 : isweekly ? 100 : isdaily ? 200 : isintraday ? interval>=240 ? 200 : interval>=5 ? 200 : interval>=1 ? 100 : 100 :100
- //
- // Calculate an Average for the centre line.
- ZZ = sum(hl2,avgLen)/avgLen
- // How digits in the current price avg.
- dg = f_int_n_digits(round(ZZ[1]))
- // get this symbols point tick value, normally 0.01 for JPY and BATS symbols and 0.00001 for the rest.
- point = syminfo.mintick
- // Dynamically adjust the multiplier to the number of digits left of Decimal and point value.
- mul = syminfo.prefix == "BATS" ? dg<=1? 1.0 :
- point<0.05 and dg>=2? pow(10,dg-3) :
- point<0.5 and dg>=3? pow(10,dg-4) :
- point<5.0 and dg>=4? pow(10,dg-5) :
- point<50.0 and dg>=5? pow(10,dg-6):
- point<500.0 and dg>=6? pow(10,dg-7): 1.0 :
- dg<=1? 1.0 :
- point<0.00005 and dg>=2? pow(10,dg-1) :
- point<0.0005 and dg>=3? pow(10,dg-2) :
- point<0.005 and dg>=4? pow(10,dg-3) :
- point<0.05 and dg>=5? pow(10,dg-4):
- point<0.5 and dg>=6? pow(10,dg-5): 1.0
- // -- debugs
- //plotshape(point,location=location.bottom,color=red)
- //plotshape(dg,location=location.bottom,color=red)
- //plotshape(mul,location=location.bottom,color=red)
- // Calculate the "00" centre Level and Scale increment
- ZZ_000 = floor((ZZ/(point*swLevel*mul)))*point*swLevel*mul
- INC = point*swLevel*mul
- // Calculate Main levels
- ZH_100 = ZZ_000 + INC
- ZH_200 = ZH_100 + INC
- ZH_300 = ZH_200 + INC
- ZH_400 = ZH_300 + INC
- ZH_500 = ZH_400 + INC
- ZH_600 = ZH_500 + INC
- ZH_700 = ZH_600 + INC
- ZH_800 = ZH_700 + INC
- ZH_900 = ZH_800 + INC
- ZH1000 = ZH_900 + INC
- ZH1100 = ZH1000 + INC
- ZH1200 = ZH1100 + INC
- ZH1300 = ZH1200 + INC
- ZH1400 = ZH1300 + INC
- ZH1500 = ZH1400 + INC
- ZH1600 = ZH1500 + INC
- ZH1700 = ZH1600 + INC
- ZH1800 = ZH1700 + INC
- ZH1900 = ZH1800 + INC
- ZH2000 = ZH1900 + INC
- ZH2100 = ZH2000 + INC
- ZH2200 = ZH2100 + INC
- ZH2300 = ZH2200 + INC
- ZH2400 = ZH2300 + INC
- ZH2500 = ZH2400 + INC
- ZH2600 = ZH2500 + INC
- ZH2700 = ZH2600 + INC
- ZH2800 = ZH2700 + INC
- ZH2900 = ZH2800 + INC
- ZH3000 = ZH2900 + INC
- ZL_100 = ZZ_000 - INC
- ZL_200 = ZL_100 - INC
- ZL_300 = ZL_200 - INC
- ZL_400 = ZL_300 - INC
- ZL_500 = ZL_400 - INC
- ZL_600 = ZL_500 - INC
- ZL_700 = ZL_600 - INC
- ZL_800 = ZL_700 - INC
- ZL_900 = ZL_800 - INC
- ZL1000 = ZL_900 - INC
- ZL1100 = ZL1000 - INC
- ZL1200 = ZL1100 - INC
- ZL1300 = ZL1200 - INC
- ZL1400 = ZL1300 - INC
- ZL1500 = ZL1400 - INC
- ZL1600 = ZL1500 - INC
- ZL1700 = ZL1600 - INC
- ZL1800 = ZL1700 - INC
- ZL1900 = ZL1800 - INC
- ZL2000 = ZL1900 - INC
- ZL2100 = ZL2000 - INC
- ZL2200 = ZL2100 - INC
- ZL2300 = ZL2200 - INC
- ZL2400 = ZL2300 - INC
- ZL2500 = ZL2400 - INC
- ZL2600 = ZL2500 - INC
- ZL2700 = ZL2600 - INC
- ZL2800 = ZL2700 - INC
- ZL2900 = ZL2800 - INC
- ZL3000 = ZL2900 - INC
- //
- //
- // === /CONSTANTS and SERIES ===
- // === PLOTTING ===
- // Plot the main levels
- plot( ZH3000, title="ZH3000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2900, title="ZH2900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2800, title="ZH2800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2700, title="ZH2700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2600, title="ZH2600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2500, title="ZH2500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2400, title="ZH2400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2300, title="ZH2300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2200, title="ZH2200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2100, title="ZH2100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH2000, title="ZH2000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1900, title="ZH1900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1800, title="ZH1800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1700, title="ZH1700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1600, title="ZH1600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1500, title="ZH1500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1400, title="ZH1400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1300, title="ZH1300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1200, title="ZH1200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1100, title="ZH1100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH1000, title="ZH1000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_900, title="ZH_900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_800, title="ZH_800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_700, title="ZH_700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_600, title="ZH_600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_500, title="ZH_500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_400, title="ZH_400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_300, title="ZH_300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_200, title="ZH_200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZH_100, title="ZH_100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZZ_000, title="ZZ_000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_100, title="ZL_100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_200, title="ZL_200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_300, title="ZL_300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_400, title="ZL_400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_500, title="ZL_500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_600, title="ZL_600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_700, title="ZL_700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_800, title="ZL_800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL_900, title="ZL_900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1000>0?ZL1000:na, title="ZL1000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1100>0?ZL1100:na, title="ZL1100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1200>0?ZL1200:na, title="ZL1200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1300>0?ZL1300:na, title="ZL1300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1400>0?ZL1400:na, title="ZL1400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1500>0?ZL1500:na, title="ZL1500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1600>0?ZL1600:na, title="ZL1600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1700>0?ZL1700:na, title="ZL1700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1800>0?ZL1800:na, title="ZL1800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL1900>0?ZL1900:na, title="ZL1900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2000>0?ZL2000:na, title="ZL2000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2100>0?ZL2100:na, title="ZL2100", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2200>0?ZL2200:na, title="ZL2200", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2300>0?ZL2300:na, title="ZL2300", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2400>0?ZL2400:na, title="ZL2400", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2500>0?ZL2500:na, title="ZL2500", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2600>0?ZL2600:na, title="ZL2600", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2700>0?ZL2700:na, title="ZL2700", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2800>0?ZL2800:na, title="ZL2800", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL2900>0?ZL2900:na, title="ZL2900", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- plot( ZL3000>0?ZL3000:na, title="ZL3000", color=blue, style=linebr, linewidth=1, transp=40, trackprice = true,offset=-9999)
- // === /PLOTTING ===
- //
- //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement