Mightymorphinchris
Active member
Overview
I would like to create a label on a study that will always be one of four colors:
1. Long: Cyan
2. Long Exit: Green
3. Short: Magenta
4. Short Exit: Red
Current Problems:
1. It's not holding the label to the last color that should be shown (ex. if the last signal was Long then stay cyan until Long Exit).
2. Another potential problem once I get over that first hurdle is that Short Exit signal may come after a Long which should be ignored. Like the first problem, if the current label is Long then the only thing that should change the label is a LongExit or Short signal. Likewise if the current label is Short then the only thing that should change the label is ShortExit or Long.
My broken code:
If someone could help me out it would be greatly appreciated!
I would like to create a label on a study that will always be one of four colors:
1. Long: Cyan
2. Long Exit: Green
3. Short: Magenta
4. Short Exit: Red
Current Problems:
1. It's not holding the label to the last color that should be shown (ex. if the last signal was Long then stay cyan until Long Exit).
2. Another potential problem once I get over that first hurdle is that Short Exit signal may come after a Long which should be ignored. Like the first problem, if the current label is Long then the only thing that should change the label is a LongExit or Short signal. Likewise if the current label is Short then the only thing that should change the label is ShortExit or Long.
My broken code:
Ruby:
def LongBuy = if Uptrend == 1 and Uptrend[1] == 0 then 1 else 0;
def LongExit = if ExitUpTrend == 1 and ExitUpTrend[1] == 0 then 1 else 0;
def ShortSell = if DownTrend == 1 and DownTrend[1] == 0 then 1 else 0;
def ShortExit = if ExitDownTrend == 1 and ExitDownTrend[1] == 0 then 1 else 0;
AddLabel(yes,
text = if LongBuy == 1
then "Long"
else if LongExit == 1
then "Exit Long"
else if ShortSell == 1
then "Short"
else "Short Exit",
color = if LongBuy == 1
then Color.Cyan
else if LongExit == 1
then Color.Green
else if ShortSell == 1
then Color.Magenta
else Color.Red
);
If someone could help me out it would be greatly appreciated!