'Get the price when exit/close strategy
It can use strategy.opentrades.entry_price(0) to get the price when strategy entry. But how to get the price when strategy exit/close?
Solution 1:[1]
Well, similarly, there is
strategy.closedtrades.exit_price(strategy.closedtrades - 1)
For example:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
strategy("My strategy", overlay=true, margin_long=100, margin_short=100)
longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
exit_price = strategy.closedtrades.entry_price(strategy.closedtrades-1)
plot(exit_price, "", color.red, 2, plot.style_circles)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

