Chris Moody的CM_Stochastic高亮条:我该如何编码“较高的较高”和“较低的较低”?

问题描述 投票:1回答:1

我正在尝试为Chris Moody的CM_Stochastic高亮条指示器添加特定的警报系统,以便在出现以下情况时得到通知1)crossUpAll高于前一个2)crossDownAll低于前一个

我已经写了这个,但是它不会触发警报:

pos_change = (crossUpAll[1] >= crossUpAll) 
neg_change = (crossDownAll[1] <= crossDownAll)

alertcondition (pos_change, "higher high") 
alertcondition (neg_change, "lower low")

您会建议替代方法吗?

pine-script indicator alerts stochastic
1个回答
1
投票
//@version=4 //Created by ChrisMoody on October 23, 2014 by user request - belgusinc //Changes Barcolor when Stochastic is Overbought Oversold. //Necessary for Highlight Bars //Only Necessary if you want you want Stochastic Croses study(title="CM_Stochastic_Highlight Bars", shorttitle="CM_Stoch_HighlightBars v4", overlay=true) len = input(14, minval=1, title="Length for Stochastic") smoothK = input(3, minval=1, title="SmoothK for Stochastic") smoothD = input(3, minval=1, title="SmoothD for Stochastic") upLine = input(80, minval=50, maxval=90, title="Upper Line Value?") lowLine = input(20, minval=10, maxval=50, title="Lower Line Value?") //Not Necessary, In Inputs Tab, capability to turn On/Off Highlight Bars, and Both Crosses //These are all checkboxes in inputs tab....Show Barcolor Highlights, Show Background Hghlight, Plot B and S for Buy Sell sbc = input(true, title="Show Price Bar highlight When Stoch is Above/Below High/Low Lines?") sbh = input(false, title="Show Background highlight When Stoch is Above/Below High/Low Lines?") sch = input(false, title="Show Back Ground Highlights When Stoch Cross - Strict Criteria - K Greater/LesThan High/Low Line - Crosses D ?") sl = input(true, title="Show 'B' and 'S' Letters When Stoch Crosses High/Low Line & D?") sac = input(false, title="Show Back Ground Highlights When Stoch Cross - Any Cross?") sacl = input(false, title="Show 'B' and 'S' Letters When Stoch Crosses - Any Cross?") //Necessary for Highlight Bars //Stoch formula k = sma(stoch(close, high, low, len), smoothK) d = sma(k, smoothD) //Necessary for Highlight Bars //aboveline = OverBought, belowline = Oversold Definitions aboveLine = k > upLine ? 1 : 0 belowLine = k < lowLine ? 1 : 0 //Only Necessary if you want you want Stochastic Croses //Definition for Cross when Above High-Low lines crossUp = (k[1] < d[1] and k[1] < lowLine[1]) and (k > d) ? 1 : 0 crossDn = (k[1] > d[1] and k[1] > upLine[1]) and (k < d) ? 1 : 0 //Only Necessary if you want you want Stochastic Croses //Definition for Cross that doesn't have to be above or below High and Low line. crossUpAll = (k[1] < d[1] and k > d) ? 1 : 0 crossDownAll = (k[1] > d[1] and k < d) ? 1 : 0 var lastCrossUpPrice = 0. var lastCrossDnPrice = 10e10 crossUpAlert = false crossDnAlert = false if crossUpAll and not crossUpAll[1] crossUpAlert := close > lastCrossUpPrice lastCrossUpPrice := close if crossDownAll and not crossDownAll[1] crossDnAlert := close < lastCrossDnPrice lastCrossDnPrice := close //Only Necessary if you want background Highlighting also - Take out the sbh/sbc and part //BackGround Highlights based on Above/Below Lines, Strict Cross Up/Down //BackGroound Color Plots bgcolor(sbh and aboveLine ? color.red : na, transp=70) bgcolor(sbh and belowLine ? color.lime : na, transp=70) bgcolor(sch and crossUp ? color.lime : na, transp=40) bgcolor(sch and crossDn ? color.red : na, transp=40) //Only Necessary if you want background Highlighting also //plots bgcolor Cross with no filter bgcolor(sac and crossUpAll ? color.lime : na, transp=40) bgcolor(sac and crossDownAll ? color.red : na, transp=40) //Necessary for Highlight Bars //Highlight Bar Definitions overBought() => sbc and aboveLine overSold() => sbc and belowLine //Necessary for Highlight Bars //Highlight Bar Plot Statement based on Above Definitions barcolor(overBought() ? color.orange : overSold() ? color.fuchsia : na) //Not Necessary if you just want Highlight Bars - Extra Feature //These are just the Letters B and Sell Based on Crosses plotchar(sl and crossUp ? crossUp : na, title="Buy Signal Strict Criteria", char='B', location=location.belowbar, color=color.lime, transp=0, offset=0) plotchar(sl and crossDn ? crossDn : na, title="Sell Signal Strict Criteria", char='S', location=location.abovebar, color=color.red, transp=0, offset=0) plotchar(sacl and crossUpAll ? crossUpAll : na, title="Buy Signal Any Cross Up", char='B', location=location.belowbar, color=color.lime, transp=0, offset=0) plotchar(sacl and crossDownAll ? crossDownAll : na, title="Sell Signal Any Cross Down", char='S', location=location.abovebar, color=color.red, transp=0, offset=0) alertcondition (crossUpAlert, "higher high") alertcondition (crossDnAlert, "lower low") // Debugging. plotchar(crossUpAll, "crossUpAll", "•", location.bottom, transp = 0) plotchar(crossDownAll, "crossDownAll", "•", location.top, transp = 0) plotchar(crossUpAlert, "crossUpAlert", "▲", location.bottom, transp = 60) plotchar(crossDnAlert, "crossDnAlert", "▼", location.top, transp = 60)

最后包含调试图。三角形显示警报将触发的位置,而圆点显示发生交叉的所有位置。

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.