COUNTIF FORMULA

Krisco

New Member
Joined
Sep 26, 2021
Messages
9
Office Version
  1. 365
Platform
  1. MacOS
Hi All, I am creating a backtesting spreadsheet and I am trying to work out a formula. I have a column [Column Q] that I can input (D, 4hr, 1hr) timeframes into. I am trying to work out for the "D" eg. Daily timeframe, what percentage of them were Wining trades. I also have a column [Column W] which is "Win/Loss Per Trade ($)". I have been trying quite a few different formulas without any luck. This is an example formula that isn't working but might give you an idea as to what I am trying to do. I only want it to count [Column Q] with "D" in it if that trade had a Win eg.[Column W] >0 & put into % form. Formula =(COUNTIF(Q$9:Q$1008,"D")/COUNTA(Q$9:Q$1008))+COUNTIF(W$9:W$1008,">0") . Would appreciate any help. Thanks

Main - 2 target back - forward - live trading & testing spreadsheet.ods
QRSTUVW
3Timeframe
4D4hr1hr
5WinLossWinLossWinLossTotal $ gain
660%$13,062.50
7
8Timeframe (D, 4hr, 1hr)Win/Loss Per Trade ($)
9D$13,062.50
10D$0.00
114hr$0.00
124hr$0.00
13D$0.00
14$0.00
15$0.00
16$0.00
17$0.00
18$0.00
19$0.00
20$0.00
21$0.00
22$0.00
23$0.00
24$0.00
25$0.00
26$0.00
27$0.00
28$0.00
29$0.00
30$0.00
31$0.00
32$0.00
33$0.00
34$0.00
MEWNIE_Strategy_(4hr_TF)
Cell Formulas
RangeFormula
Q6Q6=(COUNTIF(Q$9:Q$1008,"D")/COUNTA(Q$9:Q$1008))*AND(COUNTIF(W$9:W$1008,">0"))
W6W6=SUM(W9:W1008)
W9:W34W9=J9+M9
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Welcome to MrExcel Message Board.
I don't Know you want Exactly Formula at O6 or O7. Try both:
Book1
NOPQRSTUVW
2
3Timeframe
4D4hr1hr
5WinLossWinLossWinLossTotal $ gain
620%60%13062.50
733%
8Timeframe (D, 4hr, 1hr)Win/Loss Per Trade ($)
9D13062.50
10D0.00
114hr0.00
124hr0.00
13D0.00
140.00
150.00
160.00
170.00
180.00
190.00
200.00
210.00
220.00
230.00
240.00
250.00
260.00
270.00
280.00
290.00
300.00
310.00
320.00
330.00
340.00
Sheet1
Cell Formulas
RangeFormula
Q6Q6=(COUNTIF(Q$9:Q$1008,"D")/COUNTA(Q$9:Q$1008))*AND(COUNTIF(W$9:W$1008,">0"))
W6W6=SUM(W9:W1008)
O6O6=COUNTIF($W$9:$W$1008, ">" & 0)/COUNTA($Q$9:$Q$1008)
O7O7=COUNTIF($W$9:$W$1008, ">" & 0)/COUNTIF($Q$9:$Q$1008, "D")
W9:W34W9=J9+M9
 
Upvote 0
Perhaps these?

21 09 26.xlsm
QRSTUVW
3Timeframe
4D4hr1hr
5WinLossWinLossWinLossTotal $ gain
667%33%50%50%#N/A#N/A1300
7
8Timeframe (D, 4hr, 1hr)Win/Loss Per Trade ($)
9D100
10D0
114hr
124hr200
13D1000
14
15
16
Win-Loss %
Cell Formulas
RangeFormula
Q6,S6,U6Q6=IFERROR(COUNTIFS($Q9:$Q1008,Q4,$W9:$W1008,">0")/COUNTIF($Q9:$Q1008,Q4),NA())
R6,T6,V6R6=1-Q6
W6W6=SUM(W9:W1008)
 
Upvote 0
Solution
Welcome to MrExcel Message Board.
I don't Know you want Exactly Formula at O6 or O7. Try both:
Book1
NOPQRSTUVW
2
3Timeframe
4D4hr1hr
5WinLossWinLossWinLossTotal $ gain
620%60%13062.50
733%
8Timeframe (D, 4hr, 1hr)Win/Loss Per Trade ($)
9D13062.50
10D0.00
114hr0.00
124hr0.00
13D0.00
140.00
150.00
160.00
170.00
180.00
190.00
200.00
210.00
220.00
230.00
240.00
250.00
260.00
270.00
280.00
290.00
300.00
310.00
320.00
330.00
340.00
Sheet1
Cell Formulas
RangeFormula
Q6Q6=(COUNTIF(Q$9:Q$1008,"D")/COUNTA(Q$9:Q$1008))*AND(COUNTIF(W$9:W$1008,">0"))
W6W6=SUM(W9:W1008)
O6O6=COUNTIF($W$9:$W$1008, ">" & 0)/COUNTA($Q$9:$Q$1008)
O7O7=COUNTIF($W$9:$W$1008, ">" & 0)/COUNTIF($Q$9:$Q$1008, "D")
W9:W34W9=J9+M9
Hi maabadi, Thanks for your help. I think the formula in cell O7 is the closest as it is selecting the "D" in column Q. I'll have a play around with your formula as when I copy & paste it into my excel spreadsheet, it seems to be only giving me a % of "D" in column Q and not taking into account if they were a win from column W, even though the formula looks like it does take this into account. I'll have a play. Thanks
 
Last edited by a moderator:
Upvote 0
Try this:
Book1
PQRSTUVW
1
2
3Timeframe
4D4hr1hr
5WinLossWinLossWinLossTotal $ gain
633%67%0%100%  13062.50
7
8Timeframe (D, 4hr, 1hr)Win/Loss Per Trade ($)
9D13062.50
10D0.00
114hr0.00
124hr0.00
13D0.00
140.00
150.00
160.00
170.00
180.00
190.00
200.00
210.00
220.00
230.00
240.00
250.00
260.00
270.00
280.00
290.00
300.00
310.00
320.00
330.00
340.00
Sheet1
Cell Formulas
RangeFormula
Q6:V6Q6=IFERROR(IF(Q5="win",COUNTIFS($W$9:$W$1008, ">" & 0,$Q$9:$Q$1008,IF(Q5="Win",Q4,P4)),COUNTIFS($W$9:$W$1008, 0,$Q$9:$Q$1008,IF(Q5="Win",Q4,P4))) /COUNTIF($Q$9:$Q$1008, IF(Q5="Win",Q4,P4)),"")
W6W6=SUM(W9:W1008)
W9:W34W9=J9+M9
 
Upvote 0
Did you try the post #3 formula suggestions?
Hi Peter_SSs, Just trying to figure out what that formula is telling me. Thanks for replying as well. Just been having a look at it and when I cut & paste it into the same cells as you have them in, the formula doesn't seem to select "D" or "4hr". Also when I go & enter some extra "D"'s in the list in the Q column, it does change the % but by what I'm thinking it shouldn't as I don't have a "Win/Loss Per Trade" in Colum W for those rows, so I think it shouldn't be selecting them as they haven't had a "win" in column W as yet. See how you go. I might have to add an extra column or two to make the formula easier. I was just trying not to add too many, but I might have to. Let me know if you need anything. ?
 
Upvote 0
I'm not understanding what you are saying. For a start, please answer the following:

Are the results in post #3 correct for that small sample data shown?

If not, which results are incorrect and what should those results be?
 
Upvote 0
I'm not understanding what you are saying. For a start, please answer the following:

Are the results in post #3 correct for that small sample data shown?

If not, which results are incorrect and what should those results be?
Hi Peter_SSs, I have had a bit of a play with what you have given me & yes your formula did work. Thanks heaps.?
 
Upvote 0
Hi Peter_SSs, I have had a bit of a play with what you have given me & yes your formula did work. Thanks heaps.?
You're welcome. Glad you got it working. Thanks for the confirmation. (y)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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