Last price reaches my TP and closes the position at negative profit (stock exchanges)

 

Hello guys!

All right?

I have a question to solve in the stock market (B3 - Brazilian).

I developed an EA, however, I realized that in some moments (I believe that it is highly volatile), the Last price moves away from Ask and Bid, and in these situations Last reaches my TP in profit, however, closes the position with a negative value ( Ask when closing a sell and Bid when closing a buy), these tests were performed on the mini index (WIN), I even increased the TPs to try to prevent Last from activating the TP while the Ask / Bid prices were in the negative position however, it did not resolve the issue.

Given these situations, what are the solutions that you use in your EAs to operate in stock exchanges that have this behavior?

 

I thought about, instead of placing TP / SL in open positions, store them and monitor Ask / Bid prices according to the desired position to be closed in the profit, however I believe that this approach will slightly increase my computational cost requiring that the CPU will process more for monitoring tick by tick values ​​and will also require a little more memory to store SL / TP levels. And as it is a strategy that uses Hedge and opens many positions, it seems to me that the computational cost will end up increasing a lot.

So, I would like to hear the ideas and solutions you use.

 

In advance, thank you very much for your attention and cooperation!

 

Kind regards,

Samuel.

 
You have already answered yourself. Use ask/bid instead of last price. The additional computational cost is a trade off, it is up to you to choose between computational cost or profit.
 

Hello guys!

Is this really the only alternative for this type of situation in these markets?

Thanks in advance for the reply Meatshell!
However, I keep looking for new ideas that will make this more computationally efficient.