ADR % Change Indicator


Category:
0
0

I’m having a hard time trying to get my indicator to show red > 5 % else green, here is my code I hope you can help!

 

 

def len = 1;

def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;

def ADR_highlow = (dayHigh / dayLow + dayHigh[1] / dayLow[1] + dayHigh[2] / dayLow[2] + dayHigh[3] / dayLow[3] + dayHigh[4] / dayLow[4] + dayHigh[5] / dayLow[5] + dayHigh[6] / dayLow[6] + dayHigh[7] / dayLow[7] + dayHigh[8] / dayLow[8] + dayHigh[9] / dayLow[9] + dayHigh[10] / dayLow[10] + dayHigh[11] / dayLow[11] + dayHigh[12] / dayLow[12] + dayHigh[13] / dayLow[13] + dayHigh[14] / dayLow[14] + dayHigh[15] / dayLow[15] + dayHigh[16] / dayLow[16] + dayHigh[17] / dayLow[17] + dayHigh[18] / dayLow[18] + dayHigh[19] / dayLow[19]) / 20;

def ADR_perc = (ADR_highlow – 1);
AddLabel(ADR_perc, “ADR ” + AsPercent(ADR_perc) + ” “, if ADR_perc > 5 then Color.RED else Color.GREEN);

Marked as spam
Posted by (Questions: 2, Answers: 3)
Asked on April 10, 2021 5:09 pm
355 views
0
Private answer

The code you have provided does NOT compute a percentage value. The code you have merely computes a 20 period simple moving average of the DailyHigh divided by the DailyLow.

Your code can be replace with the following and produce exactly the same results:

def len = 1;
def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;
def ADR_highlow = Average(dayHigh / dayLow, 20);
def ADR_perc = (ADR_highlow – 1);
AddLabel(ADR_perc, “ADR ” + AsPercent(ADR_perc) + ” “, if ADR_perc > 5 then Color.RED else Color.GREEN);

As for how to get the chart label to change color based on the value being above or below a specified amount. Try plotting this on a lower chart study where you can view the values this code produces. Then you can adjust the logic in your chart label to change color based on a more realistic value.

The following modifications to your code will plot this line in the lower subgraph.

declare lower;
def len = 1;
def dayHigh = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyHigh;
def dayLow = DailyHighLow(AggregationPeriod.DAY, len, 0, no).DailyLow;
plot ADR_highlow = Average(dayHigh / dayLow, 20);
def ADR_perc = (ADR_highlow – 1);
AddLabel(ADR_perc, “ADR ” + AsPercent(ADR_perc) + ” “, if ADR_perc > 5 then Color.RED else Color.GREEN);

This is the first step in troubleshooting. Break your code down into smaller pieces and plot those pieces on the chart so you can see exactly what each element from your code is doing.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 10, 2021 6:22 pm