Strategy script - List of trades showing simultaneous Buy or Sell orders

20 Views Asked by At

I have a TradingView strategy where I am adding the buy and sell strategies as follows -

// Entry and exit logic
if (longCondition)
    strategy.entry("Buy", strategy.long, qty=accountSize / close, stop=stopLossLong, limit=takeProfitLong)
    strategy.exit("Exit", "Long", stop=stopLossLong, qty=accountSize / close, limit=takeProfitLong)
if (shortCondition)
    strategy.entry("Sell", strategy.short, qty=accountSize / close, stop=stopLossShort, limit=takeProfitShort)
    strategy.exit("Exit", "Short", stop=stopLossShort, qty=accountSize / close, limit=takeProfitShort)
    
// Plot buy and sell signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

However, in the strategy tester I am seeing that there is always another Sell signal when the stock is Sold. See the image of trade list below - List of Trades Why is there an Entry Long with Buy at the same price and time when there is an Exit Short with Buy? How can there be two simultaneous Buys at the same price and time?

What am I doing wrong here?

I tried tweaking with the Buy and Sell signals and got similar result.

1

There are 1 best solutions below

1
vitruvius On

Hedging is not supported on Tradingview. That means, you cannot have one open long and short position at the same time. The opposite direction trade entry will close the other one.

The second column is the type of the trade and the third one is the signal.

Your trade #1 is a short position (Entry Short) with 5 contracts. It is closed (Exit Short) by a long entry (Buy). In order to close it, you need to buy 5 contracts.

Your trade #2 is a long position (Entry Long) with 5 contracts. If you look at your chart, where this #2 entry is, you should see +10 (contract size). But 5 of them was used to close the old short position. So, in reality, you only hold 5 contracts at that point.