获取价格时 exit/close 策略
Get the price when exit/close strategy
进场时可以用strategy.opentrades.entry_price(0)获取价格。
但是策略exit/close时如何获取价格?
嗯,同样,还有
strategy.closedtrades.exit_price(strategy.closedtrades - 1)
例如:
// 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)
进场时可以用strategy.opentrades.entry_price(0)获取价格。 但是策略exit/close时如何获取价格?
嗯,同样,还有
strategy.closedtrades.exit_price(strategy.closedtrades - 1)
例如:
// 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)