简体   繁体   中英

Line trend color in Pine Script

I have the code plotting McGinley Dynamic. My goal is to diffrentiate the colors of the line depending on rising or falling line (green/red).

Code for plotting McGinley works. The problem is that it plots only in one color. After adding last two commented lines (and removing "plot(mg, color=orange, linewidth=4)") which are supposed to change colors the whole code breaks. What is wrong here?

study(title="McGinley Dynamic Average", shorttitle="McGinley", overlay=true, precision=6)
len = input(14, minval=1)
src = input(close, title="Source")

mg = na(mg[1]) ? src : mg[1] + (src - mg[1]) / (0.6 * len * pow(src/mg[1], 4))

plot(mg, color=orange, linewidth=4)
//mgc=(mg>mg[1]) ? green:(mg<mg[1]) ? red:(mg==mg[1]):blue:black
//plot(mg, color=std?mgc:black, linewidth=3, title="mg")

Expecting McGinley plotted in diffrent colors.

There is a mismatch in your conditions at this line (You placed : instead of ? after (mg == mg[1]) ):

mgc=(mg>mg[1]) ? green:(mg<mg[1]) ? red:(mg==mg[1]):blue:black

Simply change it to:

mgc = (mg > mg[1]) ? green : (mg < mg[1]) ? red : (mg == mg[1]) ? blue : black

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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