Highs and lows

andrewmurray86

New Member
Joined
Jun 18, 2020
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hi team,

I'm wondering if there is a formula that might work like this VBA code? Formula to calculate percentage difference between peak and trough across a sequence of values?
I'd love to use it but have no idea how to get there, I cannot code and wouldn't know where to begin copying this code to make it work for my workbook.

Essentially I am hoping to find the difference between each new High and the following low point. I have a formula which has found where these points are (for the best part, it has identified once "false" valley, but only because I don't know how to tell it to ignore this) <--- Which if you have the knowledge to make it the formula ignore any doubles so the column reads only peak, valley, peak, valley etc rather than potentially valley, valley, peak, valley, peak, peak that would be great.

But, all that asideI'm struggling to get anything that might work calculating the difference between the highs and lows and I'm also struggling with identifying the cells which correspond to the peak and valley cells.

If that were possible then perhaps the formula could identify a peak then identify a valley, then calculate the difference between them, but give only the greatest value. And then the second greatest value.

In my spread sheet I have a value which is 8.12% below start value. Then the next value will be the difference between cells S66 and S95, which is easily calculable however once the spreadsheet has over 1000 entries finding these values will be the hard part.

Copy of Andrew_Murray_Trade_Results_2020-1.xlsx
PQRST
1Trade ProfitStreakEquityColumn1
2-$4.03-$4.03$3,995.97 
3-$4.04-$8.07$3,991.93 
4-$3.65-$11.72$3,988.28 
5-$3.64-$15.36$3,984.64 
6-$4.25-$19.61$3,980.38 
7-$4.26-$23.87$3,976.13 
8-$39.92-$63.79$3,936.21 
9-$39.91-$103.70$3,896.30 
10$0.00$0.00$3,896.14 
11$0.00$0.00$3,895.98 
12-$28.77-$28.77$3,867.16 
13-$28.82-$57.59$3,838.39 
14-$40.39-$97.98$3,798.00 
15-$40.39-$138.37$3,757.61 
16-$40.64-$179.01$3,716.97 
17-$40.64-$219.65$3,676.33 
18$0.00$0.00$3,675.41 
19$0.00$0.00$3,675.09Valley
20$6.57$6.57$3,681.66 
21$6.61$13.18$3,688.27 
22$75.74$88.92$3,764.01 
23$24.02$112.94$3,788.03 
24$24.45$137.39$3,812.48 
25$0.30$137.69$3,812.78 
26$0.00$0.00$3,812.30Valley
27$94.11$94.11$3,837.65 
28$25.35$119.46$3,931.76 
29$17.72$137.18$3,949.48 
30$61.11$198.29$4,010.59 
31$0.00$0.00$4,007.91 
32$0.28$0.28$4,008.19 
33$22.78$23.06$4,030.97 
34$0.28$23.34$4,031.25 
35$22.52$45.86$4,053.77Peak
36$0.00$0.00$4,053.31 
37$0.00$0.00$4,053.07 
38$0.00$0.00$4,052.70 
39$0.00$0.00$4,052.45 
40-$34.86-$34.86$4,017.59 
41-$34.87-$69.73$3,982.72 
42$0.00$0.00$3,982.09 
43$16.92$16.92$3,999.01 
44$16.92$33.84$4,015.93 
45$16.84$50.68$4,032.77 
46$16.83$67.51$4,049.60 
47$0.00$0.00$4,048.68 
48$0.00$0.00$4,048.31 
49$0.00$0.00$3,948.31 
50$0.00$0.00$3,928.31 
51$0.00$0.00$3,928.14 
52$0.82$0.82$3,928.96 
53$22.20$23.02$3,951.16 
54$0.88$23.90$3,976.09 
55$24.93$48.83$3,976.97 
56-$16.80$0.00$3,960.06 
57-$16.91-$16.91$3,943.26 
58$11.14$0.00$3,966.08 
59$22.82$22.82$3,977.22 
60$0.60$23.42$3,977.82 
61$22.80$46.22$4,000.62 
62$23.41$69.63$4,024.03 
63$16.30$85.93$4,040.33 
64$0.00$0.00$4,039.76 
65$21.22$21.22$4,060.98 
66$0.37$21.59$4,061.35Peak
67$0.00$0.00$4,059.70 
68$0.00$0.00$4,059.12 
69$0.00$0.00$4,058.87 
70$0.00$0.00$4,058.61 
71-$42.44-$42.44$4,016.17 
72-$42.41-$84.85$3,973.76 
73$0.00$0.00$3,973.47 
74-$33.44-$33.44$3,940.03 
75-$33.44-$66.88$3,906.59 
76$0.00$0.00$3,932.69 
77$0.00$0.00$3,932.20 
78$25.70$25.70$3,864.20 
79$0.00$0.00$3,861.67 
80$0.00$0.00$3,887.37 
81$0.00$0.00$3,885.99 
82$0.00$0.00$3,884.94 
83$0.00$0.00$3,883.92 
84$0.00$0.00$3,882.93 
85$0.00$0.00$3,881.94 
86$0.00$0.00$3,882.93 
87$0.00$0.00$3,879.87 
88$0.00$0.00$3,879.08 
89$0.00$0.00$3,878.04 
90$0.00$0.00$3,877.05 
91$0.00$0.00$3,876.22 
92$0.00$0.00$3,857.20 
93$0.00$0.00$3,838.17 
94$0.00$0.00$3,835.12 
95$0.00$0.00$3,834.23Valley
96$0.00$0.00$3,834.23Valley
97$0.00$0.00$3,834.23Valley
98$0.00$0.00$3,834.23Valley
Splash
Cell Formulas
RangeFormula
P2:P98P2=IF(#REF!="balance",0,#REF!)
Q2Q2=#REF!
R2R2=W1+N2
S2:S98S2=IF(AND(R1>=R2,R3>=R2,R4>=R3),IF(R2<MIN($R$2:$R$252)/0.95,"Valley",""),IF(AND(R1<R2,R3<R2),IF(R2>MAX($R$2:$R$252)*0.998,"Peak",""),""))
Q3:Q98Q3=IF((AND(P3<0,Q2<=0)),P3+Q2,IF((AND(P3>0,Q2>=0)),P3+Q2,0))
R3:R98R3=R2+N3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
S2:S200Cellcontains a blank value textNO
S2:S200Cellcontains a blank value textNO
P2:Q75,Q3:Q200Cell Value<0textNO
P2:Q75,Q3:Q200Cell Value>0textNO
O2:S2,A96:R200,O3:R95Cellcontains a blank value textNO
O2:S2,A96:R200,O3:R95Cellcontains a blank value textNO
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
This is where the data will end up ultimately. Edit: I was hoping there would be a graph here too but there is not so I have removed it. It will be easy enough to change the target cells. The post does not add any extra information.

I'm wondering if the formula in Column S can have an extra IF/OR/AND or something added to it to basically ignore the Peak/Valley if the following result is the same? Even though these results are often many cells apart.

I have updated the formula here:
Copy of Andrew_Murray_Trade_Results_2020-1.xlsx
PQRS
1Trade ProfitStreakEquityColumn1
2-$4.03-$4.03$3,995.97 
3-$4.04-$8.07$3,991.93 
4-$3.65-$11.72$3,988.28 
5-$3.64-$15.36$3,984.64 
6-$4.25-$19.61$3,980.38 
7-$4.26-$23.87$3,976.13 
8-$39.92-$63.79$3,936.21 
9-$39.91-$103.70$3,896.30 
10$0.00$0.00$3,896.14 
11$0.00$0.00$3,895.98 
12-$28.77-$28.77$3,867.16 
13-$28.82-$57.59$3,838.39 
14-$40.39-$97.98$3,798.00 
15-$40.39-$138.37$3,757.61 
16-$40.64-$179.01$3,716.97 
17-$40.64-$219.65$3,676.33 
18$0.00$0.00$3,675.41 
19$0.00$0.00$3,675.09Valley
20$6.57$6.57$3,681.66 
21$6.61$13.18$3,688.27 
22$75.74$88.92$3,764.01 
23$24.02$112.94$3,788.03 
24$24.45$137.39$3,812.48 
25$0.30$137.69$3,812.78 
26$0.00$0.00$3,812.30Valley
27$94.11$94.11$3,837.65 
28$25.35$119.46$3,931.76 
29$17.72$137.18$3,949.48 
30$61.11$198.29$4,010.59 
31$0.00$0.00$4,007.91 
32$0.28$0.28$4,008.19 
33$22.78$23.06$4,030.97 
34$0.28$23.34$4,031.25 
35$22.52$45.86$4,053.77Peak
36$0.00$0.00$4,053.31 
37$0.00$0.00$4,053.07 
38$0.00$0.00$4,052.70 
39$0.00$0.00$4,052.45 
40-$34.86-$34.86$4,017.59 
41-$34.87-$69.73$3,982.72 
42$0.00$0.00$3,982.09 
43$16.92$16.92$3,999.01 
44$16.92$33.84$4,015.93 
45$16.84$50.68$4,032.77 
46$16.83$67.51$4,049.60 
47$0.00$0.00$4,048.68 
48$0.00$0.00$4,048.31 
49$0.00$0.00$3,948.31 
50$0.00$0.00$3,928.31 
51$0.00$0.00$3,928.14Valley
52$0.82$0.82$3,928.96 
53$22.20$23.02$3,951.16 
54$0.88$23.90$3,976.09 
55$24.93$48.83$3,976.97 
56-$16.80$0.00$3,960.06 
57-$16.91-$16.91$3,943.26Valley
58$11.14$0.00$3,966.08 
59$22.82$22.82$3,977.22 
60$0.60$23.42$3,977.82 
61$22.80$46.22$4,000.62 
62$23.41$69.63$4,024.03 
63$16.30$85.93$4,040.33 
64$0.00$0.00$4,039.76 
65$21.22$21.22$4,060.98 
66$0.37$21.59$4,061.35Peak
67$0.00$0.00$4,059.70 
68$0.00$0.00$4,059.12 
69$0.00$0.00$4,058.87 
70$0.00$0.00$4,058.61 
71-$42.44-$42.44$4,016.17 
72-$42.41-$84.85$3,973.76 
73$0.00$0.00$3,973.47 
74-$33.44-$33.44$3,940.03 
75-$33.44-$66.88$3,906.59 
76$0.00$0.00$3,932.69 
77$0.00$0.00$3,932.20 
78$25.70$25.70$3,864.20 
79$0.00$0.00$3,861.67 
80$0.00$0.00$3,887.37 
81$0.00$0.00$3,885.99 
82$0.00$0.00$3,884.94 
83$0.00$0.00$3,883.92 
84$0.00$0.00$3,882.93 
85$0.00$0.00$3,881.94 
86$0.00$0.00$3,882.93 
87$0.00$0.00$3,879.87 
88$0.00$0.00$3,879.08 
89$0.00$0.00$3,878.04 
90$0.00$0.00$3,877.05 
91$0.00$0.00$3,876.22 
92$0.00$0.00$3,857.20 
93$0.00$0.00$3,838.17 
94$0.00$0.00$3,835.12 
95$0.00$0.00$3,834.23Valley
96$0.00$0.00$3,834.23Valley
97$0.00$0.00$3,834.23Valley
Splash
Cell Formulas
RangeFormula
P2:P97P2=IF(#REF!="balance",0,#REF!)
Q2Q2=#REF!
R2R2=W1+N2
S2:S97S2=IF(AND(R1>=R2,R3>=R2,R4>=R3),IF(R2<MAX($R$2:$R$252)*0.98,"Valley",""),IF(AND(R1<R2,R3<R2),IF(R2>MAX($R$2:$R$252)*0.998,"Peak",""),""))
Q3:Q97Q3=IF((AND(P3<0,Q2<=0)),P3+Q2,IF((AND(P3>0,Q2>=0)),P3+Q2,0))
R3:R97R3=R2+N3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
S3:S200Cellcontains a blank value textNO
S3:S200Cellcontains a blank value textNO
S3:S200Cellcontains a blank value textNO
S3:S200Cellcontains a blank value textNO
S3:S200Cellcontains a blank value textNO
S3:S200Cellcontains a blank value textNO
S2:S200Cellcontains a blank value textNO
S2:S200Cellcontains a blank value textNO
P2:Q75,Q3:Q200Cell Value<0textNO
P2:Q75,Q3:Q200Cell Value>0textNO
O2:S2,A96:R200,O3:R95Cellcontains a blank value textNO
O2:S2,A96:R200,O3:R95Cellcontains a blank value textNO
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top