pine-script - 使用多个时间框架来绘制购买或出售
问题描述
仅在 1M 上发生交叉而 5M 上的指标低于零线时,才在 1M 和 5M 上使用一个指标来获得信号。
为 1M 和 5M 创建tickerID 和安全性,并为 1M 和指标 < 0 使用 crossover() 并将两者结合起来。
//@version=3
study(title="Sobh-New-HA-Study-Short", shorttitle="Sobh-New-HA-Study-Short", overlay=true)
///////////////// START Getting the HA candle /////////////////
openHA = security(heikinashi(tickerid), period, open)
closeHA = security(heikinashi(tickerid), period, close)
highHA = security(heikinashi(tickerid), period, high)
lowHA = security(heikinashi(tickerid), period, low)
////////////
haTicker = heikinashi(tickerid)
haOpenValue(r) => security(haTicker, r, open)
haCloseValue(r) => security(haTicker, r, close)
halowValue(r) => security(haTicker, r, low)
hahighValue(r) => security(haTicker, r, high)
Close1MHA=haCloseValue("1")
Open1MHA=haOpenValue("1")
High1MHA=hahighValue("1")
Low1MHA=halowValue("1")
Close5MHA=haCloseValue("5")
Open5MHA=haOpenValue("5")
High5MHA=hahighValue("5")
Low5MHA=halowValue("5")
///////////////////////////////////////////////////////////////////////
study(title="WaveTrend [LazyBear]", shorttitle="WT_LB")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
obLevel1 = input(60, "Over Bought Level 1")
obLevel2 = input(53, "Over Bought Level 2")
osLevel1 = input(-60, "Over Sold Level 1")
osLevel2 = input(-53, "Over Sold Level 2")
////////////////////////////////1MIN////////////////////////////////////////
ap1HA = (High1MHA + Low1MHA + Close1MHA)/3
esa1HA = ema(ap1HA, n1)
d1HA = ema(abs(ap1HA - esa1HA), n1)
ci1HA = (ap1HA - esa1HA) / (0.015 * d1HA)
tci1HA = ema(ci1HA, n2)
wt1HA = tci1HA //// Green Indicator
wt2HA = sma(wt1HA,4) //// Red Indicator
//////////////////////////5MIN///////////////////////////////////
apHA = (High5MHA + Low5MHA + Close5MHA)/3
esaHA = ema(apHA, n1)
dHA = ema(abs(apHA - esaHA), n1)
ciHA = (apHA - esaHA) / (0.015 * dHA)
tciHA = ema(ciHA, n2)
wt5HAOne = tciHA //// Green Indicator
wt5HATwo = sma(wt5HAOne,4) //// Red Indicator
ema2005MHA = ema(Close5MHA, 200)
plot(ema(close, 200),linewidth=4,transp=0,color=orange)
//////////////////////////// SMA 50 //////////////////////////////
lenSimple = input(50, minval=1)
srcSimple = input(close)
sma50 = sma(srcSimple, lenSimple)
/////////////////////////////////////////////////////////////////
plot(sma50, color=aqua, linewidth=4,title="SMA 50",transp=0)
/////////////////////
PriceCloseAboveSMA50= Close5MHA > sma50
PriceCloseBelow50SMA= sma50 > Close5MHA
BearMarket= ema2005MHA > sma50
BullMArket= sma50 > ema2005MHA
wt5HAOneBelowZero= wt5HATwo < 0
Buy = wt5HAOneBelowZero and crossover(wt1HA,wt2HA)
Sell = crossunder(wt5HAOne,wt5HATwo)
plotshape(Buy ,location=location.top, style=shape.diamond, color=lime, size=size.small)
plotshape(Sell ,location=location.top, style=shape.diamond, color=red, size=size.small)
只有当指标 wt1HA 超过 wt2HA 并且仅当 wt5HATwo < 0 时,我才应该绘制石灰钻石(买入)信号
但是当交叉发生时,我得到的是 1M 上的一个信号,关于 5M 是高于还是低于零
我附上了显示信号发生在 1M(数字 1)和(数字 2)上的图像,但正如您在 5M 上看到的那样,在指标高于 0 的确切时间(数字 3 见零线)。因此 1M 上的这个信号不应在 1M 上打印为绿色石灰菱形。
解决方案
推荐阅读
- reactjs - 是否可以安装仅包含 Material-UI 一个组件的包?
- flutter - 错误:在提供程序包中找不到类型“SingleChildCloneableWidget”
- javascript - 使用反应路由器时如何将道具传递给路由
- python - 为什么要通过计算字符的异或来比较两个字符串?
- python - 交换线空间图的轴
- python - Seaborn:Python 中计数图上的值存在问题
- python - 为 get 和 post 请求定义不同的模式 - AutoSchema Django Rest Framework
- c++ - 如何从循环中获取 4 个字符而不是 1 个字符的数据?
- php - 如何从 laravel 的菜单中获取餐厅的平均价格?
- java - Java FileWriter 类 - java.io.FileNotFoundException: * 没有这样的文件或目录 -Ubuntu