'TradingView Pine editor getting the actual price of a label
I'm trying to get the actual price of a label when it was triggered. I tried a few ways but I'm not able to. Any help would be appreciated. I'm attaching the whole code here now. Maybe you can have a look at it and see where I went wrong. Thank you for all the help.
//@version=4
study("buy/sell", overlay=true)
//Gathers User Inputs
bsSignals = input(true, "Buy & Sell Signals On / Off")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
src = input(hlc3, title="Source")
t = tickerid(syminfo.prefix, syminfo.ticker)
realC = security(t, timeframe.period, close)
//WaveTrend for Signals
ap = src
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
wt1 = tci
wt2 = sma(wt1,4)
// Defines Variables for Avoiding Duplicate Signals
var sell = false
var buy = false
// Defines Trade Signals
buySignal = not sell and crossover(wt1, wt2)
sellSignal = not buy and crossunder(wt1, wt2)
if buySignal
sell := true
buy := false
if sellSignal
sell := false
buy := true
// Plots Signals to Chart
plotshape(bsSignals ? buySignal : na, title = "Buy Signal", location=location.belowbar, color=color.green, transp=0, style=shape.labelup, size=size.small, textcolor=color.white, text = "BUY")
plotshape(bsSignals ? sellSignal : na, title = "Sell Signal", location=location.abovebar, color=color.red, transp=0, style=shape.labeldown, size=size.small, textcolor=color.white, text = "SELL")
// 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=realC, 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=realC, color=color.new(#FF1493, 0),
style=label.style_labelup, size=size.auto)
label.delete(id=shortCondLabel[1])
// Plot all label prices on the chart
plot(series=buySignal ? label.get_y(id=longCondLabel) : na,
color=color.new(#1E90FF, 0), linewidth=4,
style=plot.style_circles, title="New Buy")
plot(series=sellSignal ? label.get_y(id=shortCondLabel) : na,
color=color.new(#FF1493, 0), linewidth=4,
style=plot.style_circles, title="New Sell")
Solution 1:[1]
I couldn't get my head around what to put in the +tostring() Line 59 and 71.
So I put in wt1 in one and close in the other. As you use the source hlc3 the signal I believe would not fire until the candle is closed making the hlc3 complete.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Frien_dd
//@version=4
study("buy/sell", overlay=true)
//Gathers User Inputs
bsSignals = input(true, "Buy & Sell Signals On / Off")
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
src = input(hlc3, title="Source")
t = tickerid(syminfo.prefix, syminfo.ticker)
realC = security(t, timeframe.period, close)
//WaveTrend for Signals
ap = src
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
wt1 = tci
wt2 = sma(wt1,4)
// Defines Variables for Avoiding Duplicate Signals
var sell = false
var buy = false
// Defines Trade Signals
buySignal = not sell and crossover(wt1, wt2)
sellSignal = not buy and crossunder(wt1, wt2)
if buySignal
sell := true
buy := false
if sellSignal
sell := false
buy := true
// Plots Signals to Chart
//plotshape(bsSignals ? buySignal : na, title = "Buy Signal", location=location.belowbar, color=color.green, transp=0, style=shape.labelup, size=size.small, textcolor=color.white, text = "BUY")
//plotshape(bsSignals ? sellSignal : na, title = "Sell Signal", location=location.abovebar, color=color.red, transp=0, style=shape.labeldown, size=size.small, textcolor=color.white, text = "SELL")
// 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 - "+tostring(wt1), textcolor=color.white)
// Short Label
var shortLabel = label.new(x=na, y=na, 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 - "+tostring(hlc3), 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=realC, 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=realC, color=color.new(#FF1493, 0),
style=label.style_labelup, size=size.auto)
label.delete(id=shortCondLabel[1])
// Plot all label prices on the chart
plot(series=buySignal ? label.get_y(id=longCondLabel) : na,
color=color.new(#1E90FF, 0), linewidth=4,
style=plot.style_circles, title="New Buy")
plot(series=sellSignal ? label.get_y(id=shortCondLabel) : na,
color=color.new(#FF1493, 0), linewidth=4,
style=plot.style_circles, title="New Sell")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
