如何在交易视图中计算每天的利润 查看策略测试器



我想设定一个每天的利润目标,比如说500美元。一旦该交易日的净利润达到或超过500美元,我希望策略测试员在下一个交易日之前停止交易。我可以使用strategy。netprofit函数,但这在多天内不起作用。什么好主意吗?

试试这个:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=5
strategy("My strategy", margin_long=100, margin_short=100)
dailyNetProfitLimit = input(500)
canTrade(dailyNetProfitLimit)=>
var bool canTrade = false
tD = time("D")
var float dailyProfitStart = na
if tD!=tD[1] or na(dailyProfitStart) // new day or start
dailyProfitStart := strategy.netprofit
canTrade := true
if strategy.netprofit - dailyProfitStart >= dailyNetProfitLimit
canTrade := false
canTrade
canTrade = canTrade(dailyNetProfitLimit)
// debug plot
plot(strategy.netprofit, color = canTrade?color.green:color.red)

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition and canTrade)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition and canTrade)
strategy.entry("My Short Entry Id", strategy.short)

最新更新