I want to auto trade through Interactive Brokers, but there is a problem that I can't find a solution for. I don't want to set take profit and stop loss. Instead, I want take profit and stop loss based on unrealized P&L, for example, I buy aapl, I need when aapl unrealized P&L reaches $10 i sell that position , when unrealized P&L down $10 i stop loss that position .
You are in a world of hurt. This is based on the fact that you need to ask that question, and then answer your own question in the same post.
If you can’t set TP and SL in dollars or percents then you need to do the math by yourself … I know TradingView allows to set targets based on $Change or %Change, PnL wise. You can log into IB through TradingView
Why do we need to spell it for you: If you buy 10 shares of apple at 100. Then set you profit at 101 and stop loss at 99. If you buy 5 shares of apple at 200. Then set your profit at 202 and stop loss at 198. It is basic maths, just use a spread sheet or because you are coding an auto trading algo you need to put the maths inside it.
I assume that you are not a developer, otherwise you would have gone already to take a look at the API website. https://interactivebrokers.github.io/tws-api/introduction.html If you want to automate your trading strategy without writing any code, look for "no-code" solutions. There are many available. You will be presented a graphical UI with some sort of boxes and arrows where you can set your workflows and triggers based on dynamic values.