Ichimoku Chikou Precent from Price Label


Category:
0
0

Greetings Pete,

If you have time I’d appreciate your feedback on my code. I hope it’s correct. Maybe there is a better way to write it.
I created a label that looks at the Ichimoku Chikou, and the closing price (26 days ago), and displays a gray label with the percent difference of the two. I’d like to have the label turn green when Chikou is above the close, and red if the close is above the Chikou, but I get an error so I definitely can’t get that right. Maybe you can help. Thanks for all you do.

# Percentage Distance Chikou/Close (26 days ago)

declare upper;

def price = close[26];
def chikou = Ichimoku().”Chikou”[26];

def pctPriceAbove = (price/chikou) – 1;
def pctChikouAbove = (chikou/price) – 1;

AddLabel(yes, “Chikou/Close %: ” + if chikou > price then AsPercent(pctChikouAbove) else AsPercent(-pctPriceAbove),color.GRAY);

RESOLVED
Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on June 27, 2022 5:44 am
92 views
0
Thank you Pete!
( at June 27, 2022 12:57 pm)
0
Private answer

Your solution was very close. In fact you already had the logic worked out, you only needed to copy it from the text argument of the AddLabel() statement and apply it to the color argument.

Here it is after I made those changes:

# Percentage Distance Chikou/Close (26 days ago)
declare upper;
def price = close[26];
def chikou = Ichimoku()."Chikou"[26];
def pctPriceAbove = (price/chikou) - 1;
def pctChikouAbove = (chikou/price) - 1;
AddLabel(yes, "Chikou/Close %: " + if chikou > price then AsPercent(pctChikouAbove) else AsPercent(-pctPriceAbove), if chikou > price then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 27, 2022 12:52 pm