简体   繁体   English

交易视图 ta.crossover

[英]Trading View ta.crossover

I'm looking to use the function plotshape() to display a flag when there is a crossover in 3 instances such as:我希望使用函数 plotshape() 在 3 个实例中存在交叉时显示一个标志,例如:

  1. EMA8 crosses over the EMA113 and WMA200 EMA8 跨越 EMA113 和 WMA200
  2. EMA24 crosses over the EMA113 and WMA200 EMA24 跨越 EMA113 和 WMA200
  3. WMA50 crosses over the EMA113 and WMA200 WMA50 跨越 EMA113 和 WMA200

When I use the and function the flag displays only when the crossover happens on a single bar When I use the or function the flag displays twice当我使用 and 函数时,标志仅在单个条上发生交叉时显示当我使用 or 函数时,标志显示两次

I'm looking to have 1 flag plotted after then cross of both lines happens我希望在两条线交叉后绘制 1 个标志

Example: EMA8 crosses over EMA113 (no flag) crossover WMA200 flag where the condition of the previous cross of EMA113 is true示例:EMA8 越过 EMA113(无标志) 越过 WMA200 标志,其中 EMA113 的前一个交叉条件为真

Hopefully this makes sense and thank you!希望这是有道理的,谢谢!

 EMA8_= ta.ema(close,8)
    EMA24_= ta.ema(close,24)
    WMA50_= ta.wma(close,50)
    EMA113_= ta.ema(close,113)
    WMA200_= ta.wma(close,200)
    
    ema8=plot(ta.ema(close,8),color=color.white)
    ema24=plot(ta.ema(close,24),color=color.yellow)
    wma50=plot(ta.wma(close,50),color=color.red)
    ema113=plot(ta.ema(close,113),color=color.aqua)
    wma200=plot(ta.wma(close,200),color=color.blue)
    
    plotshape(series = (ta.crossover(EMA8_, EMA113_)) and (ta.crossover(EMA8_, WMA200_)) , style=shape.flag, location=location.top, color=#9FE2BF, size=size.normal)
    plotshape(series = (ta.crossover(EMA24_, EMA113_)) and (ta.crossover(EMA24_, WMA200_)) , style=shape.flag, location=location.top, color=#FFC000, size=size.normal)
    plotshape(series = (ta.crossover(WMA50_, EMA113_)) and (ta.crossover(WMA50_, WMA200_)) , style=shape.flag, location=location.top, color=#FF5F15, size=size.normal)

AND

or或者

There are multiple ways of doing this.有多种方法可以做到这一点。 In all cases, you should think about having a variable that becomes true only for one bar where your condition becomes true.在任何情况下,你应该考虑具有成为一个变量true只为您的病情为真的一个酒吧。

You should implement your logic based on that, or you can use functions that return true when a specific event happens.您应该基于此实现您的逻辑,或者您可以使用在特定事件发生时返回true函数。 Using ta.crossover() is indeed correct here.在这里使用ta.crossover()确实是正确的。

Let's look at your condition 1.让我们看看你的情况 1。

EMA8 crosses over the EMA113 and WMA200 EMA8 跨越 EMA113 和 WMA200

First, find if EMA8 crosses over EMA113 or WMA200.首先,找出 EMA8 是否越过 EMA113WMA200。 When that is true , check if EMA8 is greater than both of them.如果为true ,请检查 EMA8 是否大于两者。 You need to use crossover function here to only trigger your flag once a crossover happens.您需要在此处使用交叉功能,以便仅在发生交叉时触发您的标志。 Then by comparing the actual values, you also check if the other crossover happened sometime in the past.然后通过比较实际值,您还可以检查另一个交叉是否发生在过去的某个时间。 Because if EMA8 crossed over EMA113 or WMA200 in the past, its value would be greater than that.因为如果 EMA8 过去越过 EMA113 或 WMA200,它的价值会更大。

Here is the code for your condition 1. You can adapt it for your other conditions.这是您的条件 1 的代码。您可以根据其他条件对其进行调整。

//@version=5
indicator("My Script")
EMA8_= ta.ema(close,8)
EMA113_= ta.ema(close,113)
WMA200_= ta.wma(close,200)
bool isCond1 = (ta.crossover(EMA8_, EMA113_) or ta.crossover(EMA8_, WMA200_)) and (EMA8_ > EMA113_) and (EMA8_ > WMA200_)

plot(ta.ema(close,8),color=color.white)
plot(ta.ema(close,113),color=color.aqua)
plot(ta.wma(close,200),color=color.blue)
plotshape(series = isCond1 , style=shape.flag, location=location.top, color=#9FE2BF, size=size.normal)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM