Line with breaks plot style not working in pine script - plot

I've this indicator coded in pine script which shows certain daily horizontal levels. But, when the plot style is set to "line with breaks", the vertical line joining the levels are still visible just like plot style "lines". But it works fine when "circles" or "cross" style is selected.
Please help me to fix this issue.
//#version=5
indicator(title="fff", overlay=true)
// Get user input
disableRepaint = input.bool(title ="Disable Repainting?", defval=true)
pdl = request.security(syminfo.tickerid, "D", low[disableRepaint and barstate.isconfirmed ? 0 : 1])
pdh = request.security(syminfo.tickerid,"D", high[disableRepaint and barstate.isconfirmed ? 0 : 1])
P1 = (pdh-(pdh-pdl) * 0.756)
P2 = (pdl+(pdh-pdl) * 0.790)
//gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_off) //Does not repaint
plot(pdl,style=plot.style_linebr,color=color.gray)
plot(pdh,style=plot.style_linebr,color=color.gray)
plot(P1,style=plot.style_linebr,color=color.white, linewidth=2)
plot(P2,style=plot.style_linebr,color=color.white,linewidth=2)

I don't have access to your code so it's difficult to help
But, it could look like this
plot(P1 == P1[1] ? P1 : na, style=plot.style_linebr,color=color.white, linewidth=2)
plot(P2 == P2[1] ? P2 : na, style=plot.style_linebr,color=color.white,linewidth=2)

Related

Strategy = Multiple confirmations for alert

I'm pretty much a beginner at coding but am trying to create an indicator with multiple confirmations and alerts but have come across a few issues.
My strategy is to use adx crossunders ,higher volume at the cross , engulfing candles and pivot points with all needing to happen at the same time.
I have started to code the first parameter which is the -DI cross under the plusDI and also the crossunder of plusDm and -DI to show on my chart. As further confirmation I am also trying to add engulfing candles at the point of a cross and two other confirmations which are increase in volume (last 2 bars) and price being at swing high or swing low maybe using fractal before any alerts are triggered. I am using this on lower timeframes eg 1min - 5min charts. If anyone could help with this or point me in the direction of how I combine them all into one alert it be would be massively appreciated.
Thank you!
//#version=5
indicator("My script")
//DMI + ADX
lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50)
len = input.int(14, minval=1, title="DI Length")
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / trur)
minus = fixnan(100 * ta.rma(minusDM, len) / trur)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
adxmax = input.int(50, title="ADX Max Buying Area", minval=1, maxval=100)
adxmin = input.int(0, title="ADX Min Buying Area", minval=0, maxval=99)
//identify engulfing candles
bullishEC = close > open[1] and close[1] < open[1]
bearishEC = close < open[1] and close [1] > close [1]
//plotshape( series=bearishEC, style = shape.cross , color=color.black, location=location.abovebar)
//plotshape( series=bullishEC, style = shape.circle , color=color.black, location=location.abovebar)
//DI cross alert
DIPcross = ta.crossover(plus, minus) ? plus : na
plotshape(DIPcross, style = shape.circle , color=color.teal, location=location.absolute)
DINcross = ta.crossover(minus, plus) ? minus : na
plotshape(DINcross, style = shape.circle , color=color.red, location=location.absolute)
plot(adx, color=color.orange, title="ADX", linewidth=2)
p1 = plot(plus, color=color.teal, title="+DI", linewidth=1)
p2 = plot(minus, color=color.yellow, title="-DI", linewidth=1)
adxmaxl = hline(adxmax, title="ADX MaxLine", color=color.silver, linestyle=hline.style_solid)
adxminl = hline(adxmin, title="ADX MinLine", color=color.silver, linestyle=hline.style_solid)

Plot precedence while plotting adx and price oscillator in [pine- script]

Hi I am a newbie to pine editor, I am trying to plot Price oscillator and ADX in the same window with the same precedence, but whenever I plot them ADX is coming on the top but it should be in reverse order. Plots are not coming correctly (when plotted individually it shows correctly). Please find the code which I have used and let me know where it needs to be corrected?
//#version=4
study(title="Price Oscillator", shorttitle="PPO", format=format.price, precision=2)
shortlen=input(12, minval=1)
longlen=input(26, minval=1)
src = input(close, title="Source")
short = ema(src, shortlen)
long = ema(src, longlen)
po = (short - long)/long*100
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
dirmov(len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
sig = adx(dilen, adxlen)
plot(po, color=#990000, title="PPO")
plot(sig, color=color.red, title="ADX")`
I have attached the snapshot of the window as well for your referenceplotting PPO and ADX
That's because they don't have the same scale. It would be much easier and reliable to simply use each one separately and overlay them on in the same pane, on different scales.

Plot a value also for the last (current) bar

I'm plotting a line that changes its value every month:
lastmonth_high = security(syminfo.tickerid, "M", high)
plot(lastmonth_high, color=lastmonth_high != lastmonth_high[1] ? na : color.blue, style=plot.style_line, linewidth=3)
This way it plots no value at the actual bar.
How can I extend the line one bar to the right ?
try this
lastmonth_high = security(syminfo.tickerid, "M", high, lookahead = barmerge.lookahead_on)
plot(lastmonth_high, color=lastmonth_high != lastmonth_high[1] ? na : color.blue, style=plot.style_line, linewidth=3)

Removing weekend/non-trading hours gaps in gnuplot

My question is identical to this question except that I'm using conditional coloring for candlesticks and the solution mentioned isn't working.
My data is like:
10/24/2018 23:45,168.25,168.65,168.2,168.4,0
10/24/2018 23:46,168.5,169,168.5,168.95,67577
10/24/2018 23:47,169.35,169.6,169.1,169.1,151630
10/24/2018 23:48,169.05,169.35,168.95,169.2,63418
.
.
10/26/2018 13:48,169.05,169.35,168.95,169.2,63418
10/26/2018 23:47,169.35,169.6,169.1,169.1,151630
10/26/2018 23:48,169.05,169.35,168.95,169.2,63418
Plotting a file like this in gnuplot using command:
plot ".../ISTFeed.csv" using (timecolumn(1, "%m/%d/%Y %H:%M:%S")) : 2 : 3 : 4 : 5 : ($5 < $2 ? rgb(255, 0, 0) : rgb(0, 255, 0)) linecolor rgb variable notitle with candlesticks
produces chart with gaps. I want gnuplot to omit the gaps and plot candlesticks continuously. Is there a way to achieve this?
Have a look at the below example with generated dummy data. Although the xtics in the plot look equidistant the values of the xtics are not equidistant at all. So if you want to readout a y-value between two xtics you don't have "any" idea what the actual x-value is. You just know it must be somewhere inbetween the neighbouring xtics. A bit strange... but if you are fine with this precision...
Code:
### remove gaps in timedata
# requires gnuplot >=5.2, because of use of datablocks
reset session
# generate some dummy data
t = strptime("%m/%d/%Y %H:%M", "10/24/2018 23:45")
close = 168.25
set print $Data
print "# date time, open, low, high, close"
do for [i=1:100] {
open = close + (rand(0)*2)-1
low_tmp = open - rand(0)
high_tmp = open + rand(0)
close = open + (rand(0)*2)-1
low = open<low_tmp ? open : close<low_tmp ? close : low_tmp
high = open>high_tmp ? open : close>high_tmp ? close : high_tmp
dt = 3600*rand(0)*48
t = t + dt
print sprintf("%s,%8 .2f,%8 .2f,%8 .2f,%8 .2f",strftime("%m/%d/%Y %H:%M",t),open,low,high,close)
}
set print
print $Data
N = 10
Offset = 5
everyNthRow(N) = (int($0)%N==Offset ? word(strcol(1),1) : NaN)
set datafile separator ","
set xtics rotate by 45 right
set style fill solid 1.0
plot $Data u 0:2:3:4:5:($5<$2 ? 0xff0000 : 0x00ff00):xtic(everyNthRow(N)) w candlesticks lc rgb var not
### end of code
Result:

Legends on R Leaflet Maps

While I realize that putting legends on maps using the Rstudio leaflet package is still a work in progress, I've been trying to add a legend post-hoc to the HTML that R generates.
library("leaflet")
set.seed(100)
pdf <- data.frame(Latitude = runif(100, -90,90), Longitude = runif(100, -180,180),
col=rep(c("red", "blue"), 50 ))
#just red
leaflet(pdf) %>% addTiles() %>%
addCircleMarkers(lat = ~ Latitude, lng = ~ Longitude, color= ~col)
I've been trying to adapt the code from http://leafletjs.com/examples/choropleth.html and figure out where to add it to the output from running the above code in R and turning it into HTML.
So something like putting the following in the body of the html:
<script>
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [red, blue],
labels = [];
// loop through our density intervals and generate a label with a colored square for each label
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + getColor(grades[i] + 1) + '"></i> ' +
grades[i] + (grades[i + 1] ? '–' + grades[i + 1] + '<br>' : '+');
}
return div;
};
legend.addTo(map);
<script>
This doesn't seem to work, however. Nothing pops up. Nor is it clear how I would use names other than 'red', and 'blue' for the grades, as it were. I've also added in CSS as shown in the choropleth example as well, but no dice.
Has anyone done this - manually added a legend to their R output (say, grabbing the source from Rpubs after publishing) to add a legend?
While this is not quite what I was looking for, it appears that an addLegend function is on its way, and is in one branch of the package. See some documentation and and an example here:
http://smartinsightsfromdata.github.io//2015/04/25/choropleths.html

Resources