I'm having an odd issue modifying an open position in TradingView's strategy tester. Let me explain the context first:
The following line opens an order based on my entry condition, entryLong
.
strategy.entry("ID", strategy.long, comment="L_Entry", when = entryLong)
This works great, however, you can't make money until you close an order ;) thus:
strategy.exit( "L_STOP", "ID", loss = fixedSL * 10)
This line modifies the open order to add a stop loss at a price fixedSL
below the entry position. At this point, my only exit condition is price hitting my stop loss, which will always result in a losing strategy. To address this, I include:
if (exitLong) strategy.exit("L_TRAIL", "ID", trail_points = fixedTP * 10, trail_offset = trailSL * 10)
Which then adds a trailing stop loss after reaching a set profit. This way, I can safely lock in profit while still leaving room for growth. Here lies the problem. Each exit condition has an ID - L_STOP
and L_Trail
(L stands for Long, bc this is a buy). I reference these IDs on my charts to help in debugging and only the L_STOP
ever appears to close the order. This leads me to believe that the L_TRAIL
exit condition is either never met (unlikely) or is never set. I know that the bool, exitLong
, is set to True and the line should be executing.
I could avoid this issue entirely by setting the trailing stop and stop loss in a singlestrategy.exit
call, but it is extremely helpful to see L_STOP or L_TRAIL printed on the screen to tell what caused the exit of a trade. Only the ID of an order is printed when its condition is met, so with one call it would only be L_STOP for instance, which doesn't give much information on the trigger to exiting.
Any and all feedback is helpful! I can also include screencaps of the charts if necessary.