Adding Text to Label?


Category:
0
0

Hi, Pete: using a previous Q/A here, I figured out how to add a label to the PPO study you see below.  For the life of me, however, I can’t figure out how to add text before the value number (_signal).  I’ve tried placing “PPO:” everywhere I can, using commas where I thought appropriate, but no love.  The number shows up on my chart just fine.  But I’d like some text there, too.  Can you help?

input fastPeriod = 12;
input slowPeriod = 26;
input signalPeriod = 9;
input price = close;

def fastEma = ExpAverage(price, fastPeriod);
def slowEma = ExpAverage(price, slowPeriod);
def periodOK = fastPeriod < slowPeriod;
AddLabel(!periodOK, “ERROR: fastPeriod MUST be less than slowPeriod”);
def _ppo = if periodOK then ((fastEma – slowEma) / slowEma) * 100 else 0;
def _signal = ExpAverage(_ppo, signalPeriod);

AddLabel(yes, _signal, if _signal>0 then Color.Green else Color.Red);

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

From what I’ve read, placing

“PPO:”,

after

AddLabel(yes,

should do the trick but all I get when i do that are errors.

Marked as spam
Posted by (Questions: 6, Answers: 3)
Asked on September 27, 2020 7:22 am
204 views
0
Private answer

Two methods are available. Both work in most cases while one of them works in all cases but is a bit more complex. The easy method is to use the plus sign "+" to concatenate various string elements.

AddLabel(yes, "PPO: " + _signal, if _signal>0 then Color.Green else Color.Red);

The more robust way to do this is using the built-in function named "Concat()":

AddLabel(yes, Concat("PPO: ", _signal), if _signal>0 then Color.Green else Color.Red);

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on September 27, 2020 7:30 am