Stock market forecasting has attracted so many researchers and investors that many studies have been done in this field. These studies have led to the development of many predictive methods, the most widely used of which are machine learning-based methods. In machine learning-based methods, loss function has a key role in determining the model weights. In this study a new loss function is introduced, that has some special features, making the investing in the stock market more accurate and profitable than other popular techniques. To assess its accuracy, a two-stage experiment has been designed using data of Tehran Stock market. In the first part of the experiment, we select the most accurate algorithm among some of the well-known machine learning algorithms based on artificial neural network, ANN, support vector machine, SVM. In the second stage of the experiment, the various popular loss functions are compared with the proposed one. As a result, we introduce a new neural network using a new loss function, which is trained based on genetic algorithm. This network has been shown to be more accurate than other well-known and common networks such as long short-term memory (LSTM) for both train and test data.