【发布时间】:2023-02-08 16:54:33
【问题描述】:
我想设定一个每日利润目标,比如 500 美元。一旦该交易日的净利润达到或超过 500 美元,我希望策略测试员在下一个交易日之前停止交易。我可以使用 strategy.netprofit 函数,但这不会在多天的时间内起作用。有任何想法吗?
【问题讨论】:
标签: pine-script tradingview-api
我想设定一个每日利润目标,比如 500 美元。一旦该交易日的净利润达到或超过 500 美元,我希望策略测试员在下一个交易日之前停止交易。我可以使用 strategy.netprofit 函数,但这不会在多天的时间内起作用。有任何想法吗?
【问题讨论】:
标签: pine-script tradingview-api
尝试这个:
// 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)
【讨论】:
安德烈,
我可以问一下,对于每日跳动点或点目标(比如 50 跳动点)有什么修改,而不是每日 $ 限额?
谢谢,
【讨论】: