I Lost my label scripts
1) AddLabel(yes, "MA20: " + Average(close, 20), if close > Average(close, 20) then Color.DARK_GREEN else Color.DARK_RED);
Question: How do I Round the label to 2 decimal places?
2) I'd like to recreate a label that displays the percent the close is above or below MA20. If the percent change is positive, I'd like to color the label DARK_GREEN. If the percent change is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
3) I'd like to recreate a label that displays the percent change in the close from the last trading day of 2023 to the current close. The Label would look like this: Label "YoY%: 4.94%". If the percent change is positive, I'd like to color the label DARK_GREEN. If the percent change is negative, I'd like the color the label DARK_RED. I'd like to Round the label to 2 decimal places.
4) I'd like to recreate a label that displays the VIX close on an Intraday Chart. If the close from the previous bar is positive, I'd like to color the label DARK_GREEN. If the close from the previous bar is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
5) I'd like to recreate a label that displays the VIX close on a Daily Chart. If the close from the previous bar is positive, I'd like to color the label DARK_GREEN. If the close from the previous bar is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
Again, help would be greatly appreciated.
UPDATE:
I have read many label scripts...plus more...this weekend, and came up with and/or wrote the following:
Label_MA200:
AddLabel(yes, "MA200: " + Average(close, 200) , if close > Average(close, 200) then Color.DARK_GREEN else Color.DARK_RED);
Still unable to round 2 decimal places successfully.
Label_MA200_Pct_PAB (Percent Price is Above/Below Moving Average)
def value = (Average(close, 200) - close) / Average(close, 200) * -100;
def showlabel = value;
AddLabel(showLabel,"% A/B MA: " + Round(value,2),
if value >0 then Color.DARK_GREEN else
if value <0 then Color.DARK_RED else Color.WHITE);
The Label Values are correct. The color callouts are unconventional but work. I tried to rewrite the script (a number of times) conventionally but wasn't successful.
Label_PctYoY (Percent Price Change YoY)
#SPX 2024 Close: 4769.83
def value = (close - 4769.83) / (4769.83) * 100;
def showlabel = value;
AddLabel(showLabel,"SPX YoY % G/L: " + Round(value,2),
if value >0 then Color.DARK_GREEN else
if value <0 then Color.DARK_RED else Color.WHITE);
The Label Values are correct. The color callouts are unconventional but work. I tried to rewrite the script (a number of times) conventionally but wasn't successful. It would be more beneficial if the TOS manual would provide simpler examples in MHO.
Would greatly appreciate your inputs/help!
Mike
1) AddLabel(yes, "MA20: " + Average(close, 20), if close > Average(close, 20) then Color.DARK_GREEN else Color.DARK_RED);
Question: How do I Round the label to 2 decimal places?
2) I'd like to recreate a label that displays the percent the close is above or below MA20. If the percent change is positive, I'd like to color the label DARK_GREEN. If the percent change is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
3) I'd like to recreate a label that displays the percent change in the close from the last trading day of 2023 to the current close. The Label would look like this: Label "YoY%: 4.94%". If the percent change is positive, I'd like to color the label DARK_GREEN. If the percent change is negative, I'd like the color the label DARK_RED. I'd like to Round the label to 2 decimal places.
4) I'd like to recreate a label that displays the VIX close on an Intraday Chart. If the close from the previous bar is positive, I'd like to color the label DARK_GREEN. If the close from the previous bar is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
5) I'd like to recreate a label that displays the VIX close on a Daily Chart. If the close from the previous bar is positive, I'd like to color the label DARK_GREEN. If the close from the previous bar is negative, I'd like to color the label DARK_RED. I'd like to Round the label to 2 decimal places.
Again, help would be greatly appreciated.
UPDATE:
I have read many label scripts...plus more...this weekend, and came up with and/or wrote the following:
Label_MA200:
AddLabel(yes, "MA200: " + Average(close, 200) , if close > Average(close, 200) then Color.DARK_GREEN else Color.DARK_RED);
Still unable to round 2 decimal places successfully.
Label_MA200_Pct_PAB (Percent Price is Above/Below Moving Average)
def value = (Average(close, 200) - close) / Average(close, 200) * -100;
def showlabel = value;
AddLabel(showLabel,"% A/B MA: " + Round(value,2),
if value >0 then Color.DARK_GREEN else
if value <0 then Color.DARK_RED else Color.WHITE);
The Label Values are correct. The color callouts are unconventional but work. I tried to rewrite the script (a number of times) conventionally but wasn't successful.
Label_PctYoY (Percent Price Change YoY)
#SPX 2024 Close: 4769.83
def value = (close - 4769.83) / (4769.83) * 100;
def showlabel = value;
AddLabel(showLabel,"SPX YoY % G/L: " + Round(value,2),
if value >0 then Color.DARK_GREEN else
if value <0 then Color.DARK_RED else Color.WHITE);
The Label Values are correct. The color callouts are unconventional but work. I tried to rewrite the script (a number of times) conventionally but wasn't successful. It would be more beneficial if the TOS manual would provide simpler examples in MHO.
Would greatly appreciate your inputs/help!
Mike
Last edited by a moderator: