All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ʻalayhi wa sallam, is His Slave and Messenger.
It is impermissible to sell the purchased item before taking possession of it first. Zayd ibn Thaabit said, "Do not sell it in the spot where you have bought it until you take it to your house for the Messenger of Allaah, sallallaahu ʻalayhi wa sallam, forbade to sell the goods where they are bought until the traders take them into their possession." [Abu Dawood]
It has been narrated on the authority of Ibn ʻAbbaas that the Prophet, sallallaahu ʻalayhi wa sallam, also forbade the resale of foodstuff by somebody who had bought it unless he had received it with exact full measure. [Al-Bukhari, Muslim, and others] Ibn ʻAbbaas also reported that the Messenger of Allaah, sallallaahu ʻalayhi wa sallam, said, "If anyone buys a grain, he should not sell it until he takes possession of it." Ibn ʻAbbaas remarked, "I think all things are considered the same in this regard." Another version reads, "I regard everything like food (so far as this principle is concerned)." [Muslim]
The scholars held different views as to whether the prohibition in this regard includes all purchased items in general or merely foodstuff in particular; the scholarly view that we adopt in Islamweb is that it includes all purchased items.
However, it should be noted that "taking into possession" in this context is determined according to the common practice. Therefore, if registering the shares in your account or transferring them to your online wallet, for instance, is considered an acceptable manner of taking possession of the shares by the buyer according to the definitions and practices of the stock exchanges, then this is acceptable in the sharee'ah and the buyer is entitled to sell them after taking them into possession; otherwise, it would be impermissible.
Dr. Yousuf ibn ʻAbdullaah Ash-Shubayli wrote:
“It is permissible for the owner of shares in a bank to sell them to anyone else, even before its exchange starts (in the stock market), because he has actually bought such shares and taken possession of them as per the sharee'ah given the fact that these shares are legally registered in his name. Accordingly, he is legally entitled to dispose of them as he wishes. Nevertheless, the buyer is not allowed to sell these purchased shares until the shares are transferred to his name; selling the shares before they are transferred to his name is not allowed in the sharee'ah. He cannot sell them to another party before the ownership is legally transferred to him, namely registering the shares in his name for two reasons. Firstly, the buyer in this case, even if he owns the shares, has not taken possession of them as they are still registered in the name of the seller. The Prophet, sallallaahu ʻalayhi wa sallam, deemed the sale of purchased items before taking them into possession forbidden. Secondly, if the shares are traded among multiple parties while still registered under the name of the first seller, then this leads to disputes, conflicts, and loss of rights.”
Hence, it is clear that selling shares in your case is not prohibited on account of selling what you do not own, because you mentioned that you buy the shares first and then sell them, and, therefore, these shares are legally owned by you. However, the problem lies in whether it counts as “taking into possession” as per the sharee'ah or not, as stated above.
Day trading that is carried out in accordance with the Islamic sharee'ah is not similar to gambling. Hence, it is permissible, in principle, unless it is intended merely to manipulate the stock prices or the like. Al-ʻUsaymi wrote, "In principle, it is permissible to partake in day or week trading. There are disadvantages in day and swift trading; however, banning it is practically impossible.”
Allaah knows best.