alfaaz2011
New Member
Hi Ninja,
I seek your assistance in writing codes base on below logic. Hope something help can get on this forum. heard that this is one of best forum
I am writing a macro, Where I have to attribute new trade as OPEN or CLOSE based on existing positon. Existing position should be adjusted line by line of each trade as some trade will add in existing position and some will deduct based on Long (+ve) and Short (-Ve) Trade. there are 5 case as below should be
Instructions For all trades, I have to check existing positon based on that trade should be attributed "open or Close". I have included all case which can occured and I have to includes in my macro.
Case 1 Let's say in case of ABC, there is a new trade of 2 units which is less than and Equal to existing position are +2 , my existing postion is in same direction +ve new and +ve existing , this is an additional to my Porfolio, So I have to attribute new trade as "open" in next cell.
Case 2 Let's say in case of CDF, there is a trade of 1 units BUT existing position is -ve = -1 (SHORT Quantity) , when both are in different direction and existing postion can absorb the all the units of new trade. I have to attribute new trade as "Close" in next cell.
Case 3 "Now this one is challenging in case of GHF , because I am having multiple long trades units 3,1,2 and my existing position is = -4 (short) . Now this rule should go through each row referring to same existing positon but have to adjust existing position after each trade like mentioned below
1. First trade of 3 units must refer to existing position first, Since existing position are = -4 (Short) opposite sign which means it can absorb all the new position, It should attribute to ""CLOSE""
2. Second row of same ticker, is having trade of 1 new trade, and my existing position should be adjusted to -1 = 3-4 (New trade of first line - existing position) . In short for 2nd line it is 1 new ,-1 existing , Which should attribute is as ""CLOSE""
3. So now 3rd Row of same ticker, is having trade of 2 new trade, and my existing position is =0 (after 2 trade= 1 +-1), Which means this trade should be attributed to ""OPEN""
"
Case 4 "This one is also similar to case 3 only sign is other way around , XYZ , because I am having multiple trades units -3,-1,-2 (Short trade) and my existing position is = +2, +2 (Long) . Now this rule should go through each row referring to same existing positon but have to adjust existing position after each trade like below
1. First trade of -3 (Short) units must refer to existing position fist, Since existing position are =4 = (2+2) (Long), It should attribute to ""CLOSE"" as all new position is absorbed by existing positon as they are in opposite direction.
2. Second row of same ticker, is having trade of -1 (Short) new trade, and my existing position is left only 1 after adjusting first trade (-3+4 :New trade of first line - existing position) . Which means my existing position still can observe the new position , therefore it should be attributed is as ""CLOSE""
3. So now 3rd Row of same ticker, is having trade of -2 (short) new trade, and my existing position left is zero after trade =(0 = 1 +-1), Which means existing position can't abort by existing position it should be attributed by ""OPEN"".
"
Case5 This is very state forward, existing position is NIL of , Zero and New trades are could be +ve (long) or -ve (Short) it should always be "OPEN" as there is nothing in existing position to absorb. Like BHN and LKJ ticker
New Trade
Ticker Quantity
Case1 ABC 2 Open
Case2 CDF 1 Close
Case3 GHF 3 Close
Case3 GHF 1 Close
Case3 GHF 2 Open
Case4 XYZ -3 Close
Case4 XYZ -1 Close
Case4 XYZ -2 Open
Case5 BKN 5 Open
Case5 LKJ -9 Open
Existing position
Ticker Quantity
ABC 2
CDF -1
GHF -4
XYZ 4
In Attached doc , I have provided New trade and existing position. I have open/Close results in O columns of New trade.
Thanks in Advance
▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !
I seek your assistance in writing codes base on below logic. Hope something help can get on this forum. heard that this is one of best forum
I am writing a macro, Where I have to attribute new trade as OPEN or CLOSE based on existing positon. Existing position should be adjusted line by line of each trade as some trade will add in existing position and some will deduct based on Long (+ve) and Short (-Ve) Trade. there are 5 case as below should be
Instructions For all trades, I have to check existing positon based on that trade should be attributed "open or Close". I have included all case which can occured and I have to includes in my macro.
Case 1 Let's say in case of ABC, there is a new trade of 2 units which is less than and Equal to existing position are +2 , my existing postion is in same direction +ve new and +ve existing , this is an additional to my Porfolio, So I have to attribute new trade as "open" in next cell.
Case 2 Let's say in case of CDF, there is a trade of 1 units BUT existing position is -ve = -1 (SHORT Quantity) , when both are in different direction and existing postion can absorb the all the units of new trade. I have to attribute new trade as "Close" in next cell.
Case 3 "Now this one is challenging in case of GHF , because I am having multiple long trades units 3,1,2 and my existing position is = -4 (short) . Now this rule should go through each row referring to same existing positon but have to adjust existing position after each trade like mentioned below
1. First trade of 3 units must refer to existing position first, Since existing position are = -4 (Short) opposite sign which means it can absorb all the new position, It should attribute to ""CLOSE""
2. Second row of same ticker, is having trade of 1 new trade, and my existing position should be adjusted to -1 = 3-4 (New trade of first line - existing position) . In short for 2nd line it is 1 new ,-1 existing , Which should attribute is as ""CLOSE""
3. So now 3rd Row of same ticker, is having trade of 2 new trade, and my existing position is =0 (after 2 trade= 1 +-1), Which means this trade should be attributed to ""OPEN""
"
Case 4 "This one is also similar to case 3 only sign is other way around , XYZ , because I am having multiple trades units -3,-1,-2 (Short trade) and my existing position is = +2, +2 (Long) . Now this rule should go through each row referring to same existing positon but have to adjust existing position after each trade like below
1. First trade of -3 (Short) units must refer to existing position fist, Since existing position are =4 = (2+2) (Long), It should attribute to ""CLOSE"" as all new position is absorbed by existing positon as they are in opposite direction.
2. Second row of same ticker, is having trade of -1 (Short) new trade, and my existing position is left only 1 after adjusting first trade (-3+4 :New trade of first line - existing position) . Which means my existing position still can observe the new position , therefore it should be attributed is as ""CLOSE""
3. So now 3rd Row of same ticker, is having trade of -2 (short) new trade, and my existing position left is zero after trade =(0 = 1 +-1), Which means existing position can't abort by existing position it should be attributed by ""OPEN"".
"
Case5 This is very state forward, existing position is NIL of , Zero and New trades are could be +ve (long) or -ve (Short) it should always be "OPEN" as there is nothing in existing position to absorb. Like BHN and LKJ ticker
New Trade
Ticker Quantity
Case1 ABC 2 Open
Case2 CDF 1 Close
Case3 GHF 3 Close
Case3 GHF 1 Close
Case3 GHF 2 Open
Case4 XYZ -3 Close
Case4 XYZ -1 Close
Case4 XYZ -2 Open
Case5 BKN 5 Open
Case5 LKJ -9 Open
Existing position
Ticker Quantity
ABC 2
CDF -1
GHF -4
XYZ 4
In Attached doc , I have provided New trade and existing position. I have open/Close results in O columns of New trade.
Thanks in Advance
▬▬▬▬▬▬▬▬▬ Mod edit : thread moved to appropriate forum !