5 day percent change of DI plus and minus difference


Category:
0
1

looking for a custom col to plot the percent change of the difference between di plus and di minus from 5 days ago to today.

so if the di plus was 20 and the di minus was 10 and 5 days later the di plus was 30 and the di minus was 15 the column would be (net diff/net diff start)/net diff x 100 .   (15-10)/10= 50 percent increase in this example.

 

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on August 9, 2020 1:50 pm
42 views
0
Private answer

I think this should do it. I have not tested it.

input numberOfDays = 5;
input length = 14;
input averageType = AverageType.WILDERS;
def hiDiff = high - high[1];
def loDiff = low[1] - low;
def plusDM = if hiDiff > loDiff and hiDiff > 0 then hiDiff else 0;
def minusDM = if loDiff > hiDiff and loDiff > 0 then loDiff else 0;
def atr = MovingAverage(averageType, TrueRange(high, close, low), length);
def diPlus = 100 * MovingAverage(averageType, plusDM, length) / atr;
def diMinus = 100 * MovingAverage(averageType, minusDM, length) / atr;
def range = diPlus - diMinus;
plot value = 100 * (range - range[numberOfDays]) / range[numberOfDays];

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on August 9, 2020 3:10 pm
0
Thank you. Im testing now and it appears to work. is there a reason why high{1] and low{1} are there referencing yesterday value instead of 5 days ago. i wouldve thought i could say give me the difference between the di plus 5 days ago and di minus 5 days ago and then get the percentage. I can totally work with this just was curious! thanks again.!
( at August 9, 2020 6:05 pm)
0
I only added the last two lines. Everything before that was copied from the built-in DMI study provided with Thinkorswim.
( at August 9, 2020 6:49 pm)