繁体   English   中英

TradingView Pine 基于颜色变化的交易信号

[英]TradingView Pine Trade Signal based on color change

在“定义交易信号”下,我试图弄清楚如何根据“颜色”中设置的线条颜色添加条件。 我在图表上使用了 ema2、ema5 和 ema11,但我使用(不可见的)ema27 更改了 ema11 线的颜色。 对于交易信号,我需要知道用什么来替换“???” 与语义类似: buySignal = not sell and ema2 > ema5 and ema11 > ema5 and ema11.color=#80FF40 and sellSignal = not buy and ema2 < ema5 and ema11 < ema5 and ema11.color=#FF0000

//@version=4
study(title="Crypto Leverage Trade Signals", shorttitle="Crypto Leverage Signals", overlay=true)

//Gathers User Inputs
bsSignals = input(true, "Buy & Sell Signals On / Off")

// Calculate and plot moving average
ema2 = ema(close, 2)
ema5 = ema(close, 5)
ema11 = ema(close, 11)
ema27 = ema(close, 27)

// Colors
sellLEVcolorup = ema2 > ema5 ? #80FF40 : ema2 < ema5 ? #FF0000 : na
buyLEVcolorup =  ema11 < ema5 ? #80FF40 : ema11 > ema5 ? #FF0000 : na
smoothcolorup = ema2 > ema27 ? #60ff40 : ema2 < ema27 ? #FF0000 : na


plot(series=ema2, color=sellLEVcolorup,
     linewidth=1, title="EMA2")

plot(series=ema5, color=buyLEVcolorup,
     linewidth=3, title="EMA5")
     
plot(series=ema11, color=smoothcolorup,
     linewidth=5, title="EMA11")
     
// Defines Variables for Avoiding Duplicate Signals
var sell = false
var buy = false

// Defines Trade Signals
buySignal = not sell and ema2 > ema5 and ema11 > ema5 and ???
sellSignal = not buy and ema2 < ema5 and ema11 < ema5 and ???

if buySignal
    sell := true
    buy := false

if sellSignal
    sell := false
    buy := true

// Long Label

var longLabel = label.new(x=na, y=na, yloc=yloc.abovebar,
     color=color.green, textcolor=color.new(color.white, 0),
     size=size.normal, style=label.style_labeldown)
     
if bsSignals ? buySignal : na

    // Long
    longLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,
         style=label.style_labeldown, color=color.new(color.green, 0),
         text="Buy", textcolor=color.white)     

// Short Label
var shortLabel = label.new(x=na, y=bar_index, yloc=yloc.belowbar,
     color=color.red, textcolor=color.new(color.white, 0),
     size=size.normal, style=label.style_labelup)

if bsSignals ? sellSignal : na

    // Short
    shortLabel := label.new(x=bar_index, y=na, yloc=yloc.abovebar,
         style=label.style_labeldown, color=color.new(color.red, 0),
         text="Sell", textcolor=color.white)

// Alert Conditions
alertcondition(buySignal, "Buy Signal", "Buy Signal")
alertcondition(sellSignal, "Sell Signal", "Sell Signal")

var label longCondLabel = na
var label shortCondLabel = na

if (buySignal) 
    longCondLabel := label.new(x=bar_index, y=na, color=color.new(#1E90FF, 0),
         style=label.style_labeldown, size=size.auto)
    label.delete(id=longCondLabel[1])

if (sellSignal)
    shortCondLabel := label.new(x=bar_index, y=na, color=color.new(#FF1493, 0),
         style=label.style_labelup, size=size.auto)
    label.delete(id=shortCondLabel[1])

我需要知道用什么来代替“???”

替换为无。 您的条件已经涵盖 ema11.color=#FF0000 和 ema11.color=#80FF40。

暂无
暂无

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

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