+ Reply to Thread
Results 1 to 14 of 14

sort out the trades in sequence

  1. #1
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    sort out the trades in sequence

    Hello,

    I have attached an Excel file. In this file, in Sheet 1, I have trades (When to Buy and when to Sell) as well as the price (in Column A). In sheet two I have columns I need to fill.

    In sheet two the first column is "Trade Number". Then there is "Buy Price", "Sell Price", "Profit/Loss", "Number of trades Won", and "Number of trades Lost".

    I want the Excel file to pull the first "Buy" signal from sheet 1 and enter it as the first trade in the first column of the second sheet. Then, I want Excel to take the price at the first buy signal, and put it at "Buy Price". Then I want Excel to pull the first sell signal and record its price in "Sell Price". Repeat the same method for trade 2, that is, record the next buy signal as trade number "2", record its value in "Buy Price", and so on.....eventually, I want to calculate the number of trades won, that is, if Profit/loss (which is equal to "Sell Price-Buy Price") equals positive, then it is a win. If positive value is negative, then it is a loss. I want to add all the number of trades won and all the number of trades lost in the next columns.

    If anyone can help me out with this I will appreciate it.
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: sort out the trades in sequence

    The columns in sheet 1 are not labelled. I have no idea what is what. There are no manually calculated expected results in sheet 2. I have no idea what you want to see. Please amend your sample sheet and repost.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    I have attached the file with the changes made. The first column is the price of the stock. The second column is 1 if there is a trade running or 0 if there is no trade running. Third column is the signal, whether to Buy the Sock or Sell.

    I want to pick the trades sequentially, that is, the first buy signal is recorded as "1" in "Trade Number" in the second sheet, with the price corresponding to the buy signal in buy price, whereas the subsequent sell signal is recorded as the sell price for the first trade.
    Then the next buy signal is recorded as "2" in the "Trade Number", with the price corresponding to the buy signal as "Buy Price" and, subsequently, the next price at the sell signal in the "sell price", and so on....

    In "holding period" in Sheet 2, I want to know the number of days the stock was held, that is, the number of rows between the first buy signal, and the first sell signal....the number of days between the second buy signal and the subsequent sell signal...and so on.

    I will appreciate if someone can help me out with this.
    Attached Files Attached Files
    Last edited by deezina07; 01-20-2021 at 08:05 AM.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: sort out the trades in sequence

    You have attached the same sheet!! There are no manually calculated results... Upload the correct one...

  5. #5
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    Apologies for this. I have attached the file again.

    Thanks
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    Can someone guide me here, please?

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: sort out the trades in sequence

    Based on your sample (which may not be truly representative, but is all I have to work with):

    Excel 2016 (Windows) 32 bit
    B
    C
    D
    E
    2
    =SMALL(IF(Sheet1!$D$8:$D$28="Buy",Sheet1!$A$8:$A$28),Sheet2!A2)
    =SMALL(IF(Sheet1!$D$8:$D$28="Sell",Sheet1!$A$8:$A$28),Sheet2!A2)
    =INDEX(Sheet1!$B$2:$B$28,MATCH(Sheet2!B2,Sheet1!$A$2:$A$28,0))
    =INDEX(Sheet1!$B$2:$B$28,MATCH(Sheet2!C2,Sheet1!$A$2:$A$28,0))
    Sheet: Sheet2

    The first two formulae may need to be entered with CTRL+SHIFT+ENTER. Drag copy all down.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: sort out the trades in sequence

    If you would prefer a formula that does NOT require array entry, this works too:

    =IFERROR(INDEX(Sheet1!$A:$A,AGGREGATE(15,6,ROW(Sheet1!$D$2:$D$30)/(Sheet1!$D$2:$D$30="Buy"),ROWS(B$2:B2))),"")

    it needs to be adjusted a little for the sell sate and for the buy/sell amounts - I have done this in the file. I have also tidied up the formulae in the yellow shaded areas. see sheet.
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 01-21-2021 at 05:32 AM.

  9. #9
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    Thank You!

    When I plug the formula in B2 while pressing ctrl+shift+enter, I get numbers in the column but not dates. I will highly appreciate if you can upload a file with the formulae, so I can see what I am doing incorrectly.

    I have attached the file to show where the problem is arising.

    Also, if I don't know the number of trades in the data set, I cannot write "Trade Number" in Sheet 2, Column A. Other formulae are dependent what is in Column A (Sheet 2).

    Can the formula be written in a manner that it captures the first trade and writes 1 in Column A. Then it captures the second trade and writes 2 in Column A.

    Again, Thank You. I highly appreciate this on your part.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    Got it.

    Thank You.

    I appreciate this.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: sort out the trades in sequence

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  12. #12
    Registered User
    Join Date
    01-19-2021
    Location
    Karachi, Pakistan
    MS-Off Ver
    Office 16
    Posts
    52

    Re: sort out the trades in sequence

    The only issue I am having is that when I enter the above mentioned code in a new file in Excel with the same data, it gives me numbers instead of dates in "Date Initiated" and "Date Terminated". The rest comes out fine. I have attached the file in which I pasted the code in order to note the error I am getting.
    Attached Files Attached Files

  13. #13
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: sort out the trades in sequence

    As I said in the PM. Format as date.

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: sort out the trades in sequence

    Change the cell formatting to Short Date - yours are set to General. The numbers are date serial numbers.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need Macro To Sequence And Auto Sort Data
    By Bubbles_A in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-18-2020, 05:01 AM
  2. [SOLVED] Merge and sort two columns in a dynamic defined sequence
    By DHT_Tech in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-11-2018, 02:10 PM
  3. [SOLVED] Sort sheet using arbitrary criteria (e.g. sequence)
    By scottiejmurray in forum Excel General
    Replies: 1
    Last Post: 03-19-2015, 06:56 PM
  4. Sort According to Custom Alphabetic Sequence
    By indrayumna in forum Excel General
    Replies: 4
    Last Post: 07-10-2008, 06:39 AM
  5. special sort sequence
    By fwalden in forum Excel General
    Replies: 4
    Last Post: 10-10-2006, 10:15 AM
  6. [SOLVED] How do I sort by EBCDIC sequence in EXCEL?
    By gary_h in forum Excel General
    Replies: 5
    Last Post: 03-29-2006, 08:35 PM
  7. How can I sort data in sequence by odd/even numbers
    By TxBlackJack in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-19-2006, 01:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1