I have a strategy that if it opens a trade (whether Long/Buy or Short/Sel), it should continue with the trend but if signals an opposite trade, it should close the first trade, but its not closing anything.
Also on TradingView, it does not show the Close trade (LX or SX) on the chart!
Here is a sample:
bool longCondition = long_entry
bool shortCondition = short_entry
// Create entries based on the cross conditions for both trades biases.
if longCondition and inDateRange
strategy.entry("LONG", strategy.long, comment=i_alert_txt_entry_long)
strategy.close("SX", comment=i_alert_txt_exit_short) // Close the short position if open
if shortCondition and inDateRange
strategy.entry("SHORT", strategy.short, comment=i_alert_txt_entry_short)
strategy.close("LX",comment=i_alert_txt_exit_long) // Close the long position if open
I have tried many variations of the code, It opens a trade normally but it does not close and I have to manually close a trade (with a loss of course)
I have tried multiple conditions it does not work.
Changed from Comment and alerts and does not work.
I am using WunderTrading as a medium between Trading View and Binance (Crypto Trading)
It would not be necessary to close one order to open another.
But if you insist, I think the simplest solution is to close the operation, and in the next candle open a new one.
The explanation is that by default it uses first in, first out (FIFO)
There is a close_entries_rule "ANY" option, but it has many conditions
https://www.tradingcode.net/tradingview/exit-order-sequence/