Blank cell cant make calculations !

TheSardOz

New Member
Joined
Nov 30, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hello Forum!
I have this data and I would like to calculate the profit loss,( entry value - exit value) or the other way around it depend if is a long or a short.
The problem I am facing is that I can't make the calculation because the data in not linear but shifted, what's the best solution ?


Thank you !


1606822232502.png
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi TheSardOz

Welcome to the Board..

What is the criteria for your results? I mean what should happen if the data is "long" and what should happen if the data is "short"? aditionally what should happen and either of the cells in entry value and exit value are blank?

Also please use xl2bb addon and upload part of your worksheet instead of providing only the screenshot.
 
Upvote 0
Hi TheSardOz

Welcome to the Board..

What is the criteria for your results? I mean what should happen if the data is "long" and what should happen if the data is "short"? aditionally what should happen and either of the cells in entry value and exit value are blank?

Also please use xl2bb addon and upload part of your worksheet instead of providing only the screenshot.
Hi Fadee2, Thanks for the welcome....

I am trying to make a dashboard, after re arranging the original data some values are no in the same row, and I can't do simple calculation like sum or subtractions to calculate the profit loss for each individual transaction.

this one below is the starting raw data (table 1)

OrdNoAccCodeSecCodeExchDestSubDestB/SVolumePriceValueFXRateDatecommmission
39840013287863FLTASXCIMB_SGX_HKEB1001716.001716130/11/2020 14:00:43$1.37
39840107287863FLTASXCIMB_SGX_HKEB1001714.001714130/11/2020 14:04:34$1.37
39840351287863FLTASXCIMB_SGX_HKES1001713.001713130/11/2020 14:16:12$1.37
39840429287863FLTASXCIMB_SGX_HKES1001714.001714130/11/2020 14:19:52$1.37
39840970287863FLTASXCIMB_SGX_HKEB1001713.001713130/11/2020 14:50:00$1.37
39841137287863FLTASXCIMB_SGX_HKEB1001712.501712.5130/11/2020 14:59:07$1.37
39841516287863FLTASXCIMB_SGX_HKES1001718.001718130/11/2020 15:24:09$1.37
39841619287863FLTASXCIMB_SGX_HKES1001717.001717130/11/2020 15:30:26$1.37
39835206287863TWEASXCIMB_SGX_HKES50893.00446.5130/11/2020 10:32:39$0.36
39835737287863TWEASXCIMB_SGX_HKES50900.00450130/11/2020 10:35:32$0.36
39836181287863TWEASXCIMB_SGX_HKEB25875218.75130/11/2020 10:43:10$0.18
39836213287863TWEASXCIMB_SGX_HKEB75882661.5130/11/2020 10:43:28$0.53
39840669287863TWEASXCIMB_SGX_HKEB100851851130/11/2020 14:33:15$0.68
39840804287863TWEASXCIMB_SGX_HKES100849.5849.5130/11/2020 14:40:24$0.68


this the data re arranged (table2)

using FLT CODE (FIRST 4 ROW FROM TOP ) as example: the trade was made in 4 transactions 2 buy and 2 sale to close the position,
to calculate the GROSS P&L I need to do (EXIT VALUE C - ENTRY VALUE C) because is a long position or for a short trade would be (ENTRY VALUE C - EXIT VALUE C)
but because the values are not in the same row I can't do the calculation.
I am learning excel so I get stuck easily unfortunately!

Thank you !

CommissionCodeDate CalcincludeVolume MovPosition BalanceCode BalanceTrade countTime InTime Outcotract date calcTicker Date RefLong/ShortUnit Price $ CalEntry PriceExit PriceEntry Value CExit Value CEntry VolumeExit volumeBalanceGross P&L
$1.37FLT30/11/2020Yes100100FLT/100114:00:0030/11/2020FLT-44165Long17.1617.16$1,716100-$1,716.00
$1.37FLT30/11/2020Yes100200FLT/200114:04:0030/11/2020FLT-44165Long17.1417.14$1,714100-$1,714.00
$1.37FLT30/11/2020Yes-100100FLT/100114:16:0030/11/2020FLT-44165Long17.1317.13$1,713100$1,713.00
$1.37FLT30/11/2020Yes-1000FLT/0114:19:0030/11/2020FLT-44165Long17.1417.14$1,714100$1,714.00
$1.37FLT30/11/2020Yes100100FLT/100114:50:0030/11/2020FLT-44165Long17.1317.13$1,713100-$1,713.00
$1.37FLT30/11/2020Yes100200FLT/200114:59:0030/11/2020FLT-44165Long17.1317.125$1,713100-$1,712.50
$1.37FLT30/11/2020Yes-100100FLT/100115:24:0030/11/2020FLT-44165Long17.1817.18$1,718100$1,718.00
$1.37FLT30/11/2020Yes-1000FLT/0115:30:0030/11/2020FLT-44165Long17.1717.17$1,717100$1,717.00
$0.36TWE30/11/2020Yes-50-50TWE/-50110:32:0030/11/2020TWE-44165Short8.938.93$44750$446.50
$0.36TWE30/11/2020Yes-50-100TWE/-100110:35:0030/11/2020TWE-44165Short9.009$45050$450.00
$0.18TWE30/11/2020Yes25-75TWE/-75110:43:0030/11/2020TWE-44165Short8.758.75$21925-$218.75
$0.53TWE30/11/2020Yes750TWE/0110:43:0030/11/2020TWE-44165Short8.828.82$66275-$661.50
$0.68TWE30/11/2020Yes100100TWE/100114:33:0030/11/2020TWE-44165Long8.518.51$851100-$851.00
$0.68TWE30/11/2020Yes-1000TWE/0114:40:0030/11/2020TWE-44165Long8.508.495$850100$849.50
 
Upvote 0
Hi TheSardOZ,
I am completely inexperience in trading, but to understand computational part of your query, I need to ask, do you want to compute balance based on the code, e.g. balance for each row would be computed based on FLT starting from 0 and once It becomes TWE computations would again start from 0, keeping in view Long and Short part of the equation as well?

Please pardon my trading inexperience.
 
Upvote 0
Hi TheSardOZ,
I am completely inexperience in trading, but to understand computational part of your query, I need to ask, do you want to compute balance based on the code, e.g. balance for each row would be computed based on FLT starting from 0 and once It becomes TWE computations would again start from 0, keeping in view Long and Short part of the equation as well?

Please pardon my trading inexperience.
Yes, each transaction need it's own profit loss result, when the position balance is 0 it means the all the shares I bought has been sell.
If instead of FLT was Apple's or Oranges the process would be the same:
I bought 100 Apples for X amount and after sold the Apples for Y amount, the difference is my profit or loss, and I need to calculate it for each transaction
The VOLUME MOV shows that my first buy was 100 units then I bought 100 more In the POSITION BALABCE you can see the units increasing when I buy and then decreasing as I sell down to the value of 0 witch means I have sold all the shares.
The Gross profit loss of this transaction is (1,713.00+1,714.00) - ( -1,716.00+ -1,714.00)= $3 ( this are the value from the BALANCE)
PS, there is a mistake in the (time in ) formula the time in showing 14:16:00 it should be in time out.

Thank you very much for showing interest and trying to help me out with this little problem!

1607021950262.png
 
Upvote 0
The Gross profit loss of this transaction is (1,713.00+1,714.00) - ( -1,716.00+ -1,714.00)= $3 ( this are the value from the BALANCE)
I think the P & L should be -3 as the equation goes

Book1
ZAAABACAD
23
2417131714-1716-1714-3
25
Sheet1
Cell Formulas
RangeFormula
AD24AD24=SUM(Z24:AC24)


if this is true then try, the following and see if does what you need...

Excel Formula:
=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))
 
Upvote 0
I think the P & L should be -3 as the equation goes

Book1
ZAAABACAD
23
2417131714-1716-1714-3
25
Sheet1
Cell Formulas
RangeFormula
AD24AD24=SUM(Z24:AC24)


if this is true then try, the following and see if does what you need...

Excel Formula:
=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))
Thank you very much for taking your time to help me out, I really appreciate. Unfortunately after the second calculation the profit loss is incorrect,
If I add a Colum there is a way to have the exit value inline with the entry value? maybe using the (time in) has reference?
CommissionCodeDate CalcincludeVolume MovPosition BalanceCode BalanceTrade countTime InTime OutTime closecotract date calcTicker Date RefLong/ShortUnit Price $ CalEntry PriceExit PriceEntry Value CExit Value CEntry VolumeExit volumeBalanceGross P&Lcorrec values
$1.92DOC4/12/2020Yes25002500DOC/2500111:26:224/12/2020DOC-44169Long0.960.96$2,4002500-$2,400.00-$2,400.00
$1.91DOC4/12/2020Yes-25000DOC/0111:29:3211:29:324/12/2020DOC-44169Long0.960.955$2,3882500$2,387.50-$12.50yes
$1.48NXL4/12/2020Yes250250NXL/250112:55:284/12/2020NXL-44169Long7.407.4$1,850250-$1,850.00-$1,850.00
$1.50NXL4/12/2020Yes-2500NXL/0112:56:1712:56:174/12/2020NXL-44169Long7.527.5186$1,880250$1,879.65$29.65yes
$0.63NXL4/12/2020Yes100100NXL/100113:12:154/12/2020NXL-44169Long7.897.89$789100-$789.00-$818.65
$0.64NXL4/12/2020Yes-1000NXL/0113:13:2613:13:264/12/2020NXL-44169Long7.957.95$795100$795.00-$23.65no
$0.66NXL4/12/2020Yes100100NXL/100114:07:424/12/2020NXL-44169Long8.218.21$821100-$821.00-$844.65
$0.66NXL4/12/2020Yes-1000NXL/0114:08:3114:08:314/12/2020NXL-44169Long8.258.25$825100$825.00-$19.65no
 
Upvote 0
Without adding the coloumn "Time Close" the formula works fine. Formula references were readjusted.
Excel Formula:
=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))

If you breakdown the formula, it checks 5 basic criteria to match and provide the result.
N3 & N4 = Code
Y3 = Long/Short
AC3 & AD3 = Entry Value / Exit Value
Then computes the result based on True/False, using values in AG and AH coloumns. Check if the values computed adjacent to "no" are the correct ones????????
Book1
MNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJ
2CommissionCodeDate CalcincludeVolume MovPosition BalanceCode BalanceTrade countTime InTime Outcotract date calcTicker Date RefLong/ShortUnit Price $ CalEntry PriceExit PriceEntry Value CExit Value CEntry VolumeExit volumeBalanceGross P&L
3$1.37FLT30/11/20Yes100100FLT/100114:00:0030/11/20FLT-44165Long17.1617.16$1,716100($1,716.00)-1716
4$1.37FLT30/11/20Yes100200FLT/200114:04:0030/11/20FLT-44165Long17.1417.14$1,714100($1,714.00)-3430
5$1.37FLT30/11/20Yes-100100FLT/100114:16:0030/11/20FLT-44165Long17.1317.13$1,713100$1,713.00-1717
6$1.37FLT30/11/20Yes-1000FLT/0114:19:0030/11/20FLT-44165Long17.1417.14$1,714100$1,714.00-3
7$1.37FLT30/11/20Yes100100FLT/100114:50:0030/11/20FLT-44165Long17.1317.13$1,713100($1,713.00)-1716
8$1.37FLT30/11/20Yes100200FLT/200114:59:0030/11/20FLT-44165Long17.1317.125$1,713100($1,712.50)-3428.5
9$1.37FLT30/11/20Yes-100100FLT/100115:24:0030/11/20FLT-44165Long17.1817.18$1,718100$1,718.00-1710.5
10$1.37FLT30/11/20Yes-1000FLT/0115:30:0030/11/20FLT-44165Long17.1717.17$1,717100$1,717.006.5
11$0.36TWE30/11/20Yes-50-50TWE/-50110:32:0030/11/20TWE-44165Short8.938.93$44750$446.50446.5
12$0.36TWE30/11/20Yes-50-100TWE/-100110:35:0030/11/20TWE-44165Short99$45050$450.00896.5
13$0.18TWE30/11/20Yes25-75TWE/-75110:43:0030/11/20TWE-44165Short8.758.75$21925($218.75)677.75
14$0.53TWE30/11/20Yes750TWE/0110:43:0030/11/20TWE-44165Short8.828.82$66275($661.50)16.25
15$0.68TWE30/11/20Yes100100TWE/100114:33:0030/11/20TWE-44165Long8.518.51$851100($851.00)-834.75
16$0.68TWE30/11/20Yes-1000TWE/0114:40:0030/11/20TWE-44165Long8.58.495$850100$849.5014.75
17$1.92DOC04/12/20Yes25002500DOC/2500111:26:2204/12/20DOC-44169Long0.960.96$2,4002500($2,400.00)-2400($2,400.00)
18$1.91DOC04/12/20Yes-25000DOC/0111:29:3204/12/20DOC-44169Long0.960.955$2,3882500$2,387.50-12.5yes($12.50)
19$1.48NXL04/12/20Yes250250NXL/250112:55:2804/12/20NXL-44169Long7.47.4$1,850250($1,850.00)-1850($1,850.00)
20$1.50NXL04/12/20Yes-2500NXL/0112:56:1704/12/20NXL-44169Long7.527.5186$1,880250$1,879.6529.65yes$29.65
21$0.63NXL04/12/20Yes100100NXL/100113:12:1504/12/20NXL-44169Long7.897.89$789100($789.00)-759.35($818.65)
22$0.64NXL04/12/20Yes-1000NXL/0113:13:2604/12/20NXL-44169Long7.957.95$795100$795.0035.65no($23.65)
23$0.66NXL04/12/20Yes100100NXL/100114:07:4204/12/20NXL-44169Long8.218.21$821100($821.00)-785.35($844.65)
24$0.66NXL04/12/20Yes-1000NXL/0114:08:3104/12/20NXL-44169Long8.258.25$825100$825.0039.65no($19.65)
Sheet1
Cell Formulas
RangeFormula
AH3:AH24AH3=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))


In case if you need to add another column, all references are required to be readjusted based on changes to your data.
 
Upvote 0
Without adding the coloumn "Time Close" the formula works fine. Formula references were readjusted.
Excel Formula:
=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))

If you breakdown the formula, it checks 5 basic criteria to match and provide the result.
N3 & N4 = Code
Y3 = Long/Short
AC3 & AD3 = Entry Value / Exit Value
Then computes the result based on True/False, using values in AG and AH coloumns. Check if the values computed adjacent to "no" are the correct ones????????
Book1
MNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJ
2CommissionCodeDate CalcincludeVolume MovPosition BalanceCode BalanceTrade countTime InTime Outcotract date calcTicker Date RefLong/ShortUnit Price $ CalEntry PriceExit PriceEntry Value CExit Value CEntry VolumeExit volumeBalanceGross P&L
3$1.37FLT30/11/20Yes100100FLT/100114:00:0030/11/20FLT-44165Long17.1617.16$1,716100($1,716.00)-1716
4$1.37FLT30/11/20Yes100200FLT/200114:04:0030/11/20FLT-44165Long17.1417.14$1,714100($1,714.00)-3430
5$1.37FLT30/11/20Yes-100100FLT/100114:16:0030/11/20FLT-44165Long17.1317.13$1,713100$1,713.00-1717
6$1.37FLT30/11/20Yes-1000FLT/0114:19:0030/11/20FLT-44165Long17.1417.14$1,714100$1,714.00-3
7$1.37FLT30/11/20Yes100100FLT/100114:50:0030/11/20FLT-44165Long17.1317.13$1,713100($1,713.00)-1716
8$1.37FLT30/11/20Yes100200FLT/200114:59:0030/11/20FLT-44165Long17.1317.125$1,713100($1,712.50)-3428.5
9$1.37FLT30/11/20Yes-100100FLT/100115:24:0030/11/20FLT-44165Long17.1817.18$1,718100$1,718.00-1710.5
10$1.37FLT30/11/20Yes-1000FLT/0115:30:0030/11/20FLT-44165Long17.1717.17$1,717100$1,717.006.5
11$0.36TWE30/11/20Yes-50-50TWE/-50110:32:0030/11/20TWE-44165Short8.938.93$44750$446.50446.5
12$0.36TWE30/11/20Yes-50-100TWE/-100110:35:0030/11/20TWE-44165Short99$45050$450.00896.5
13$0.18TWE30/11/20Yes25-75TWE/-75110:43:0030/11/20TWE-44165Short8.758.75$21925($218.75)677.75
14$0.53TWE30/11/20Yes750TWE/0110:43:0030/11/20TWE-44165Short8.828.82$66275($661.50)16.25
15$0.68TWE30/11/20Yes100100TWE/100114:33:0030/11/20TWE-44165Long8.518.51$851100($851.00)-834.75
16$0.68TWE30/11/20Yes-1000TWE/0114:40:0030/11/20TWE-44165Long8.58.495$850100$849.5014.75
17$1.92DOC04/12/20Yes25002500DOC/2500111:26:2204/12/20DOC-44169Long0.960.96$2,4002500($2,400.00)-2400($2,400.00)
18$1.91DOC04/12/20Yes-25000DOC/0111:29:3204/12/20DOC-44169Long0.960.955$2,3882500$2,387.50-12.5yes($12.50)
19$1.48NXL04/12/20Yes250250NXL/250112:55:2804/12/20NXL-44169Long7.47.4$1,850250($1,850.00)-1850($1,850.00)
20$1.50NXL04/12/20Yes-2500NXL/0112:56:1704/12/20NXL-44169Long7.527.5186$1,880250$1,879.6529.65yes$29.65
21$0.63NXL04/12/20Yes100100NXL/100113:12:1504/12/20NXL-44169Long7.897.89$789100($789.00)-759.35($818.65)
22$0.64NXL04/12/20Yes-1000NXL/0113:13:2604/12/20NXL-44169Long7.957.95$795100$795.0035.65no($23.65)
23$0.66NXL04/12/20Yes100100NXL/100114:07:4204/12/20NXL-44169Long8.218.21$821100($821.00)-785.35($844.65)
24$0.66NXL04/12/20Yes-1000NXL/0114:08:3104/12/20NXL-44169Long8.258.25$825100$825.0039.65no($19.65)
Sheet1
Cell Formulas
RangeFormula
AH3:AH24AH3=IF(AND(N3=N2,Y3="Long",AD3=0),AH2-ABS(AG3),IF(AND(N3<>N2,Y3="Long",AD3=0),AG3,IF(AND(N3=N2,Y3="Long",AD3<>0),(ABS(AH2)-AG3)*-1,IF(AND(N3<>N2,Y3="Long",AD3<>0),AG3,IF(AND(N3=N2,Y3="Short",AC3=0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3=0),"",IF(AND(N3=N2,Y3="short",AC3<>0),AH2+AG3,IF(AND(N3<>N2,Y3="Short",AC3<>0),AG3))))))))


In case if you need to add another column, all references are required to be readjusted based on changes to your data.
The results are inconsistent, some are correct some other not


Cell Formulas
RangeFormula
P6:P13P6=IF(LEN(Data_entry[@[commmission ]])=0,"",Data_entry[@[commmission ]])
Q6:Q13Q6=IF(LEN(Data_entry[@SecCode])=0,"",Data_entry[@SecCode])
R6:R13R6=IF(LEN(M6)>0,IFERROR(DATE(YEAR(M6),MONTH(M6),DAY(M6)),"xxx"),"")
S6:S13S6=IF(COUNTIF(S7:S10000,"Yes")=0,"Yes",IFERROR(IF(AND(AE6="",AF6=""),"No",IF(OR(LEN(R6)=0,R6="xxx",LEN(D6)=0,LEN(H6)=0,LEN(I6)=0,LEN(J6)=0),"No",IF(AA6>90000,"No","Yes"))),"No"))
T6:T13T6=IF(LEN(I6)=0,"",IF(H6="B",I6,I6*-1))
U6:U13U6=IF(LEN(D6)<1,0,SUMIF($D$5:D6,D6,$T$5:T6))
V6:V13V6=D6&"/"&U6
W6:W7W6=IF(LEN(D6)<1,1,COUNTIFS($AA5:AA$6,Z6,$D5:D$6,D6,$AC5:AC$6,AC6,$U5:U$6,0)+1)
X6:X13X6=IF(LEN(M6)=0,"",IF(AI6="","",IFERROR(TIME(HOUR(M6),MINUTE(M6),SECOND(M6)),"")))
Y6:Y13Y6=IF(LEN(M6)=0,"",IF(AJ6="","",IFERROR(TIME(HOUR(M6),MINUTE(M6),SECOND(M6)),"")))
Z6:Z13Z6=IF(LEN(M6)=0,"",IF(U6<>0,"",IFERROR(TIME(HOUR(M6),MINUTE(M6),SECOND(M6)),"")))
AA6:AA13AA6=IF(LEN(I6)=0,"",IF(U6=0,R6,IFERROR(INDEX($AA7:$AA$10000,MATCH(D6&"/0",$V7:$V$10000,0)),99999)))
AB6:AB13AB6=D6&"-"&AA6
AC6:AC13AC6=IF(LEN(I6)=0,"",IF(U6-T6=0,IF(H6="B","Long","Short"),LOOKUP(2,1/($AB$5:AB5=AB6),$AC$5:AC5)))
AD6:AD13AD6=IFERROR(IF($J$5="Price",J6/100,J6),J6)
AE6:AE13AE6=IF(LEN(I6)=0,"",IF(U6-T6=0,AD6,IF(AND(LOOKUP(2,1/($AB$5:AB5=AB6),$H$5:H5)=H6,LEN(LOOKUP(2,1/($AB$5:AB5=AB6),$AE$5:AE5))>0),AD6,"")))
AF6:AF13AF6=IF(LEN(I6)=0,"",IF(LEN(AE6)>0,"",AD6))
AG6:AG13AG6=IF(LEN(I6)=0,"",IF(AE6="","",AE6*I6))
AH6:AH13AH6=IF(LEN(I6)=0,"",IF(AF6="","",AF6*I6))
AI6:AI13AI6=IF(LEN(I6)=0,"",IF(AE6="","",I6))
AJ6:AJ13AJ6=IF(LEN(I6)=0,"",IF(AF6="","",I6))
AK6:AK13AK6=IF(AND(AE6="",AF6=""),"",IF(H6="S",AD6*I6,IF(H6="B",I6*AD6*-1,"")))
AL6:AL13AL6=IF(AND(Q6=Q5,AC6="Long",AH6=0),AL5-ABS(AK6),IF(AND(Q6<>Q5,AC6="Long",AH6=0),AK6,IF(AND(Q6=Q5,AC6="Long",AH6<>0),(ABS(AL5)-AK6)*-1,IF(AND(Q6<>Q5,AC6="Long",AH6<>0),AK6,IF(AND(Q6=Q5,AC6="Short",AG6=0),AL5+AK6,IF(AND(Q6<>Q5,AC6="Short",AG6=0),"",IF(AND(Q6=Q5,AC6="short",AG6<>0),AL5+AK6,IF(AND(Q6<>Q5,AC6="Short",AG6<>0),AK6))))))))
W8:W13W8=IF(LEN(D8)<1,1,COUNTIFS($AA$6:AA7,Z8,$D$6:D7,D8,$AC$6:AC7,AC8,$U$6:U7,0)+1)
 
Upvote 0
hi ThesardOz,
From your last results, it seems the conditional part of the formula needs some amendments. I'd suggest evaluating formula steps with matching conditions using the [F9] key and then changing the matching criteria, if needed.
Initially the formula was designed to compute results based on a single group, CODE, and then matches the criteria of Long/Short etc., e.g. if you had 4 rows of code DOC then the computations were made starting from 1st occurrence of DOC till the last one, keeping in view Long/Short. But now, maybe, I think you are computing the results for 2 rows, I m sorry but I have no experience in trading therefore, it might be getting way over my head.

I hope my explanation makes sense.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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