亏损交易的状态变化
State change on a losing trade
在 pinescript 中有没有办法记录您在哪根蜡烛上止损或亏损?我的策略有 4 个状态:
- 正在搜索交易
- 在买入交易中
- 在卖出交易中
- 多头或空头退出当前交易
我想添加另一个状态,它告诉我我刚刚止损出局,并根据该状态对我的策略接下来要做什么做出不同的决定。
如果我对您的理解正确的话,您想要检测亏损交易。这是示例:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
if strategy.netprofit[1] > strategy.netprofit
label.new(bar_index, low, text = str.format("here is losing trade with size {0} {1}", strategy.netprofit - strategy.netprofit[1], syminfo.currency) )
在 pinescript 中有没有办法记录您在哪根蜡烛上止损或亏损?我的策略有 4 个状态:
- 正在搜索交易
- 在买入交易中
- 在卖出交易中
- 多头或空头退出当前交易
我想添加另一个状态,它告诉我我刚刚止损出局,并根据该状态对我的策略接下来要做什么做出不同的决定。
如果我对您的理解正确的话,您想要检测亏损交易。这是示例:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
if strategy.netprofit[1] > strategy.netprofit
label.new(bar_index, low, text = str.format("here is losing trade with size {0} {1}", strategy.netprofit - strategy.netprofit[1], syminfo.currency) )