I have tried to set up a signal trading with TradingView and Binance integration via webhooks, using a Pinescript strategy.
In some cases this opens unexpected orders, exactly with the example below:
Here we see the pinescript strategy working on TradingView - it has opened 2 long positions and closed one. (pic above)
The "exit_Long_enter_11151" order is closing the previously opened "Long_enter_11151"
Lets say, the webhook for Binance integration was added at 20:25 The webhook sent a signal on the next bar to close the position.
But on Binance, there were no any actual positions opened, because the webhook was only created at 20:25
In result, a short position has been opened on binance
Here the same chart on Binance but with only one short position opened
How to synchronize my strategy with binance to prevent opening short positions if there are no long positions are open yet?
After some research, it's impossible to configure only using default Binance and Pinescript integration. It's necessary to configure alert signals from Pinescript, setup a webhook listener on your server and use a Binance api to open trades manually. https://www.tradingview.com/support/solutions/43000481368-strategy-alerts/