简体   繁体   English

如何在 Trading View Strategy Tester 中计算每天的利润

[英]How to calculate each day's profit in Trading View Strategy Tester

I want to set a daily profit target, lets say of $500.我想设定一个每日利润目标,比如 500 美元。 Once the.net profit during that trading day is at or above $500, I want strategy tester to stop taking trades until the next trading day.I could use the strategy.netprofit function but that wouldn't work over the span of multiple days.一旦那个交易日的.net 利润达到或超过 500 美元,我希望策略测试员在下一个交易日之前停止交易。我可以使用 strategy.netprofit function 但这不会在多天的跨度内起作用。 Any ideas?有任何想法吗?

Try this:尝试这个:

// 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM