Musk335im3
Member
Hi All!
Been trying to code a Watchlist label where:
Below is my effort in coding it. The Long signal works but cannot make the label work both on long and short. Thanks in advanced. (Mod, please delete in case there's already something like this posted here; just can't find it).
Been trying to code a Watchlist label where:
- Daily aggregation
- Label turns Green when current Price is >= plus 1 ATR from Yesterday's Closing
Below is my effort in coding it. The Long signal works but cannot make the label work both on long and short. Thanks in advanced. (Mod, please delete in case there's already something like this posted here; just can't find it).
Code:
### Initial Computations
## ATR
# ATR
input PeriodATR = aggregationPeriod.DAY;
input length_atr = 14;
input averageType_atr = AverageType.WILDERS;
def pre_ATR = MovingAverage(averageType_atr, TrueRange(high(period = PeriodATR), close(period = PeriodATR), low(period = PeriodATR)), length_atr);
def ATR = pre_ATR;
# ATR percentage
def pre_ATR_perc = (pre_ATR/close()) * 100;
def ATR_perc = pre_ATR_perc;
## All Closings: for computation ##
# Closings
input aggregationPeriod_Closing = AggregationPeriod.DAY;
def Closing = close(period = aggregationPeriod_Closing);
## Closings +/- ATR
# Upper
def Plus_ATR = Closing + ATR;
# Lower
def Minus_ATR = Closing - ATR;
## Conditions
def pre_Short = if (Closing <= Minus_ATR[1]) then 1 else double.NaN;
#plot Short = pre_Short;
def pre_Long = if (Closing >= Plus_ATR[1]) then 1 else double.NaN;
#plot Long = pre_Long;
def pre_Signal = (if pre_Long == 1 then 1 else if pre_Short == 1 then -1 else double.NaN);
plot Signal = pre_Signal;
AddLabel (yes, Signal, color.Black);# maybe not needed
Signal.AssignValueColor(if Signal == 1 then Color.GREEN else Color.Black);
AssignBackgroundColor(if Signal == 1 then Color.GREEN else Color.Black);
Signal.AssignValueColor(if Signal < 0 then Color.Red else Color.Black);
AssignBackgroundColor(if Signal < 0 then Color.Red else Color.Black);