JayRogers

MTF Any MA Cross - Multi Marker

Honorable Mention:
  • @glaz for jumping on the "on price" suggestion and throwing the code at me - which spurred me to add shapes in too, because why not eh?
Description:
  • Multitude of MA choices.
  • MA's can both be set to different resolutions.
  • Crossover/Crossunder, drawn at an averaged position.
r2 Changes:
  • On-MA cross marker now only drawn at averaged position
  • On price markers added
  • Shape markers added
  • All marker types can be toggled on and off.

We need a proper script versioning system up in here! ...just saying ;)
ลบออกจากสคริปส์โปรด เพิ่มเข้าไปในสคริปส์โปรด
//@version=2

study(title="MTF Any MA Cross - Multi Marker", shorttitle="Any MA Cross", overlay=true)

// Revision:    2
// Author:      JayRogers
//
// Honorable Mention:
//  - @glaz for jumping on the "on price" suggestion and throwing the code at me - which spurred me to add shapes in too, because why not eh?
//
// Description:
//  - Multitude of MA choices.
//  - MA's can both be set to different resolutions.
//  - Crossover/Crossunder, drawn at an averaged position.
// r2 Changes:
//  - on-MA cross marker now only drawn at averaged position
//  - On price markers added
//  - shapes added
//  - All marker types can be toggled on and off.

// - INPUTS START
// first ma
maUseRes1   = input(defval = false, title = "[ MA 1 SECTION ] - Use Different Resolution?")
maReso1     = input(defval = "60", title = "MA 1 - Set Resolution", type = resolution)
maType1     = input(defval = "SMA", title = "MA 1 - Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )", type = string)
maSource1   = input(defval = open, title = "MA 1 - Source", type = source)
maLength1   = input(defval = 20, title = "MA 1 - Period", minval = 1)
lsmaOffset1 = input(defval = 1, title = "MA 1 - Least Squares (LSMA) Only - Offset Value", minval = 0)
almaOffset1 = input(defval = 0.85, title = "MA 1 - Arnaud Legoux (ALMA) Only - Offset Value", minval = 0, step = 0.01)
almaSigma1  = input(defval = 6, title = "MA 1 - Arnaud Legoux (ALMA) Only - Sigma Value", minval = 0)
// second ma
maUseRes2   = input(defval = false, title = "[ MA 2 SECTION ] - Use Different Resolution?")
maReso2     = input(defval = "60", title = "MA 2 - Set Resolution", type = resolution)
maType2     = input(defval = "EMA", title = "MA 2 - Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )", type = string)
maSource2   = input(defval = open, title = "MA 2 - Source", type = source)
maLength2   = input(defval = 20, title = "MA 2 - Period", minval = 1)
lsmaOffset2 = input(defval = 1, title = "MA 2 - Least Squares (LSMA) Only - Offset Value", minval = 0)
almaOffset2 = input(defval = 0.85, title = "MA 2 - Arnaud Legoux (ALMA) Only - Offset Value", minval = 0, step = 0.01)
almaSigma2  = input(defval = 6, title = "MA 2 - Arnaud Legoux (ALMA) Only - Sigma Value", minval = 0)
// position
crossOnLines    = input(defval = true, title = "[ MARKER LOCATIONS ] - Show On MA's? (on the lines)")
crossOnPrice    = input(defval = true, title = "Show On Price? (on the candle)")
crossShapes     = input(defval = true, title = "Show Shapes? (above/below candle)")
// - INPUTS END

// - FUNCTIONS
// Returns chosen MA input calculation, default to SMA if blank or typo.
variant(type, src, len, lsmaOffset, almaOffset, almaSigma) =>
    v1 = sma(src, len)                                                  // Simple
    v2 = ema(src, len)                                                  // Exponential
    v3 = 2 * v2 - ema(v2, len)                                          // Double Exponential
    v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)               // Triple Exponential
    v5 = wma(src, len)                                                  // Weighted
    v6 = vwma(src, len)                                                 // Volume Weighted
    v7 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len    // Smoothed
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))   // Hull
    v9 = linreg(src, len, lsmaOffset)                                   // Least Squares
    v10 = alma(src, len, almaOffset, almaSigma)                         // Arnaud Legoux
    type=="EMA"?v2 : type=="DEMA"?v3 : type=="TEMA"?v4 : type=="WMA"?v5 : type=="VWMA"?v6 : type=="SMMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : type=="ALMA"?v10 : v1
// return selected resolution series
reso(exp, res, use) => use ? security(tickerid, res, exp) : exp
// - FUNCTIONS END

// - SERIES VARIABLES
// ma's
ma1 = reso(variant(maType1, maSource1, maLength1, lsmaOffset1, almaOffset1, almaSigma1), maReso1, maUseRes1)
ma2 = reso(variant(maType2, maSource2, maLength2, lsmaOffset2, almaOffset2, almaSigma2), maReso2, maUseRes2)
// crossing stuffs
crossUp         = crossover(ma1, ma2)
crossDown       = crossunder(ma1, ma2)
crossAvg        = avg(ma1, ma2)
crossPrice      = security(tickerid, "1", close)
crossUpPrice    = valuewhen(crossUp, crossPrice, 0)
crossDownPrice  = valuewhen(crossDown, crossPrice, 0)
// - SERIES VARIABLES END

// - PLOTTING
plot(ma1, title = "MA 1", color = #33CC33, linewidth = 2, style = line, transp = 20)
plot(ma2, title = "MA 2", color = #FF5555, linewidth = 2, style = line, transp = 20)
plotshape(crossShapes and crossUp, title="Cross Over Shape", style=shape.circle, location=location.abovebar, color=#33FF33, transp=0, size=size.tiny)
plotshape(crossShapes and crossDown, title="Cross Under Shape", style=shape.circle, location=location.belowbar, color=#FF3333, transp=0, size=size.tiny)
plot(crossOnPrice and crossUp ? crossUpPrice : na, title = "On Price Cross Over", color = #33FF33, linewidth = 4, style = circles, transp = 0)
plot(crossOnPrice and crossDown ? crossDownPrice : na, title = "On Price Cross Under", color = #FF3333, linewidth = 4, style = circles, transp = 0)
plot(crossOnLines and crossUp ? crossAvg : na, title = "On MA Cross Over", color = #33FF33, linewidth = 4, style = circles, transp = 0)
plot(crossOnLines and crossDown ? crossAvg : na, title = "On MA Cross Under", color = #FF3333, linewidth = 4, style = circles, transp = 0)
// - PLOTTING END
very nice
ตอบกลับ
Hello, I like your indicator, how can I add the resolution for 4H. regards
+1 ตอบกลับ
So you can apply the 2 hr, 3 hr, but no 4hr... interesting choice i guess
+1 ตอบกลับ
seanwooj Fishface666
@Fishface666, this seems to be a limitation of pinescript. not the fault of this particular script.
+1 ตอบกลับ
หน้าแรก ตัวช่วยคัดกรองหุ้น ตัวคัดกรองฟอเร็กซ์ ตัวคัดกรองคริปโต ปฏิทินเศรษฐกิจ มันทำงานได้อย่างไร ข้อมูลสำคัญของชาร์ต ราคา กฎของบ้าน ผู้ดูแลการใช้งาน เว็บไซต์ & โบรกเกอร์ โซลูชั่น วิดเจ็ต โซลูชั่นชาร์ต ขอความช่วยเหลือ คำร้องขอเพิ่มเติมลักษณะและบริการ บล็อก & ข่าว คำถามที่พบบ่อย วิกิ Twitter
ข้อมูลส่วนตัว ตั้งค่าประวัติ บัญชีและการเรียกเก็บเงิน เหรียญ TradingView ตั๋วการขอความสนับสนุนของฉัน ขอความช่วยเหลือ ไอเดียที่ถูกตีพิมพ์ ผู้ติดตาม กำลังติดตาม ข้อความส่วนตัว แชท ออกจากระบบ