so i'm trying to get the ATR plot to print from a macd long signal.
Code: Select all
//@version=4
study(title="MACD", shorttitle="MACD test drawing", overlay=true)
// Getting inputs
atrper = input(14, "ATR Period")
multiplier = input(1.5, title="ATR Stop Mulitplier")
spread = input(0) / 100, title="Spread"
//MACD//
src_m = close
fast_length = 12
slow_length = 26
signal_length = 9
fast_ma = ema(src_m, fast_length)
slow_ma = ema(src_m, slow_length)
macd = fast_ma - slow_ma
signal = ema(macd, signal_length)
//----------ATR----------//
atr = rma(atr(1), atrper)
atrplot = plot(atr *1.5, color=#f70808)//, display=display.none)
//Bar Color//
bclongm = (macd > signal)
bcshortm = (macd < signal)
barcolor(bclongm ? color.white : bcshortm ? color.blue : na)
//Signal//
longm = crossover (macd, signal)
shortm = crossunder (macd, signal)
//Direction//
buy = longm
//------Stoploss------//
longsl = close - atr * multiplier
//Plots//
line1 = valuewhen (buy, close, 0)
//line2 = valuewhen (longsl, close,0) // Trying to write the valuewhen for the longsl (atr stop loss form signal close of MACD) it doesnt work
line2 = buy ? longsl : na //why do i have to write this line like this and not like line 40?
plot (line1, color=line1!=line1[1] ? na : color.white, style=plot.style_linebr, transp=0)
//plot (line2, color=line2!=line2[1] ? na : color.white, style=plot.style_linebr, transp=0) // if i could get the atr stop to plot like this then it'll be ideal as i will have the value of said atr stop
plot (fixnan (line2), color=line2!=line2[1] ? na : color.black, style=plot.style_cross, join=false) // also can only get the atr stop and line 42 to print if i do like this, why??
i have to write it the way ive done it above, notes in the script itself on the lines
any help will be gratefully appreciated as this is starting to get annoying
as you can see I can get the MACD signal close to print a lovely nice white line, but, the atr has to be plotted with circles for some reason and cant get a valuewhen of that plot.
I dont want to go down the line.new route as has limitations of historic plots