How to addLabel with Spread percentage


Category:
0
0

Hello Pete and other,

I have a spread % code here that using fine, but I would like to know if you can help me to place the output from the code inside a label. I don’t know coding that’s why I asking you for help.

my code:

Plot Spread =((ask-bid)/bid)*100;

spread.assignValueColor(if spread >=10 then color.Downtick else color.green);

 

I saw this post that you help some else with this label, code here:

input limit = 0.09;
def priceB = close(priceType = PriceType.BID);
def priceA = close(priceType = PriceType.ASK);
AddLabel(yes, Concat(“Bid: “, priceB), Color.WHITE);
AddLabel(yes, Concat(“Ask: “, priceA), Color.WHITE);
AddLabel(yes, Concat(“Spread: “, priceA – priceB), if priceA – priceB > limit then Color.RED else Color.WHITE);

I trying to place a label like this with black background that show me my spread % formula result inside

 

thanks in advance

 

Maykel

Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on July 27, 2019 11:45 am
126 views
0
Private answer

I moved this question out of the "Frequently Asked Questions" topic and into the "Chart Studies" topic.

To add a label to your existing code:

AddLabel(yes, Spread, Color.BLACK);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 27, 2019 12:00 pm
0
when I do what you are telling me the ask and bid on my code gives me an error (it remains in red) and doesn't display anything at all. What could be wrong? my code: Plot Spread =((ask-bid)/bid)*100; spread.assignValueColor(if spread >=10 then color.Downtick else color.green); AddLabel(yes, Spread, Color.BLACK);
( at July 27, 2019 12:22 pm)
0
Well if your code did not work in the first place it will certainly not work after adding the label. In the very first sentence of your question you stated the code was working fine. The Bid and Ask are only available in a custom watchlist. You cannot use this for a chart.
( at July 27, 2019 1:16 pm)